-
Notifications
You must be signed in to change notification settings - Fork 179
feat: improve layout on smaller screens #1285
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: dev
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,122 @@ | ||
| // SPDX-FileCopyrightText: 2025 Social Connect Labs, Inc. | ||
| // SPDX-License-Identifier: BUSL-1.1 | ||
| // NOTE: Converts to Apache-2.0 on 2029-06-11 per LICENSE. | ||
|
|
||
| import { useCallback } from 'react'; | ||
| import { useWindowDimensions } from 'react-native'; | ||
|
|
||
| export const DEFAULT_COMPACT_WIDTH = 360; | ||
| export const DEFAULT_COMPACT_HEIGHT = 720; | ||
|
Check failure on line 9 in app/src/hooks/useCompactLayout.ts
|
||
|
|
||
| interface UseCompactLayoutOptions { | ||
| compactWidth?: number; | ||
| compactHeight?: number; | ||
| } | ||
|
|
||
| type ResponsiveDimension = 'width' | 'height' | 'any'; | ||
|
|
||
| interface ResponsivePaddingOptions { | ||
| min?: number; | ||
| max?: number; | ||
| percent?: number; | ||
| } | ||
|
|
||
| type ResponsiveValueConfig<T> = { | ||
| compact: T; | ||
| regular: T; | ||
| dimension?: ResponsiveDimension; | ||
| }; | ||
|
|
||
| const useCompactLayout = ( | ||
| options: UseCompactLayoutOptions = {}, | ||
| ): { | ||
| width: number; | ||
| height: number; | ||
| isCompactWidth: boolean; | ||
| isCompactHeight: boolean; | ||
| isCompact: boolean; | ||
| selectResponsiveValue: <T>( | ||
| compactValue: T, | ||
| regularValue: T, | ||
| dimension?: ResponsiveDimension, | ||
| ) => T; | ||
| selectResponsiveValues: <TConfig extends Record<string, ResponsiveValueConfig<unknown>>>( | ||
|
Check warning on line 43 in app/src/hooks/useCompactLayout.ts
|
||
| config: TConfig, | ||
| ) => { | ||
| [K in keyof TConfig]: TConfig[K] extends ResponsiveValueConfig<infer TValue> | ||
| ? TValue | ||
| : never; | ||
| }; | ||
| getResponsiveHorizontalPadding: (options?: ResponsivePaddingOptions) => number; | ||
|
Check warning on line 50 in app/src/hooks/useCompactLayout.ts
|
||
| } => { | ||
| const { width, height } = useWindowDimensions(); | ||
| const compactWidth = options.compactWidth ?? DEFAULT_COMPACT_WIDTH; | ||
| const compactHeight = options.compactHeight ?? DEFAULT_COMPACT_HEIGHT; | ||
|
|
||
| const isCompactWidth = width < compactWidth; | ||
| const isCompactHeight = height < compactHeight; | ||
| const selectResponsiveValue = useCallback( | ||
| <T>( | ||
| compactValue: T, | ||
| regularValue: T, | ||
| dimension: ResponsiveDimension = 'any', | ||
| ): T => { | ||
| if (dimension === 'width') { | ||
| return isCompactWidth ? compactValue : regularValue; | ||
| } | ||
|
|
||
| if (dimension === 'height') { | ||
| return isCompactHeight ? compactValue : regularValue; | ||
| } | ||
|
|
||
| return isCompactWidth || isCompactHeight ? compactValue : regularValue; | ||
| }, | ||
| [isCompactHeight, isCompactWidth], | ||
| ); | ||
|
|
||
| const selectResponsiveValues = useCallback( | ||
| <TConfig extends Record<string, ResponsiveValueConfig<unknown>>>( | ||
| config: TConfig, | ||
| ) => { | ||
| const entries = Object.entries(config) as Array<[ | ||
|
Check warning on line 81 in app/src/hooks/useCompactLayout.ts
|
||
| keyof TConfig, | ||
|
Check warning on line 82 in app/src/hooks/useCompactLayout.ts
|
||
| ResponsiveValueConfig<unknown>, | ||
| ]>; | ||
|
Check warning on line 84 in app/src/hooks/useCompactLayout.ts
|
||
| const result = {} as { | ||
| [K in keyof TConfig]: TConfig[K] extends ResponsiveValueConfig<infer TValue> | ||
|
Check warning on line 86 in app/src/hooks/useCompactLayout.ts
|
||
| ? TValue | ||
| : never; | ||
| }; | ||
|
|
||
| entries.forEach(([key, { compact, regular, dimension }]) => { | ||
| result[key] = selectResponsiveValue(compact, regular, dimension); | ||
| }); | ||
|
|
||
| return result; | ||
| }, | ||
| [selectResponsiveValue], | ||
| ); | ||
|
|
||
| const getResponsiveHorizontalPadding = useCallback( | ||
| (paddingOptions: ResponsivePaddingOptions = {}): number => { | ||
| const { min = 16, max, percent = 0.06 } = paddingOptions; | ||
| const computed = width * percent; | ||
| const withMin = Math.max(min, computed); | ||
| return typeof max === 'number' ? Math.min(max, withMin) : withMin; | ||
| }, | ||
| [width], | ||
| ); | ||
|
|
||
| return { | ||
| width, | ||
| height, | ||
| isCompactWidth, | ||
| isCompactHeight, | ||
| isCompact: isCompactWidth || isCompactHeight, | ||
| selectResponsiveValue, | ||
| selectResponsiveValues, | ||
| getResponsiveHorizontalPadding, | ||
| }; | ||
| }; | ||
|
|
||
| export default useCompactLayout; | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,7 +2,7 @@ | |
| // SPDX-License-Identifier: BUSL-1.1 | ||
| // NOTE: Converts to Apache-2.0 on 2029-06-11 per LICENSE. | ||
|
|
||
| import React from 'react'; | ||
| import React, { useMemo } from 'react'; | ||
|
Check failure on line 5 in app/src/layouts/ExpandableBottomLayout.tsx
|
||
| import { | ||
| Dimensions, | ||
| PixelRatio, | ||
|
|
@@ -17,6 +17,7 @@ | |
|
|
||
| import { black, white } from '@/utils/colors'; | ||
| import { extraYPadding } from '@/utils/constants'; | ||
| import useCompactLayout from '@/hooks/useCompactLayout'; | ||
|
|
||
| // Get the current font scale factor | ||
| const fontScale = PixelRatio.getFontScale(); | ||
|
|
@@ -57,7 +58,17 @@ | |
| ...props | ||
| }) => { | ||
| const { top } = useSafeAreaInsets(); | ||
| const { roundTop, ...restProps } = props; | ||
| const { roundTop, style: incomingStyle, ...restProps } = props; | ||
| const { selectResponsiveValue } = useCompactLayout({ | ||
| compactHeight: 760, | ||
| }); | ||
| const spacingStyle = useMemo( | ||
| () => ({ | ||
| paddingHorizontal: selectResponsiveValue(16, 20, 'width'), | ||
| paddingVertical: selectResponsiveValue(16, 20, 'height'), | ||
| }), | ||
| [selectResponsiveValue], | ||
| ); | ||
| return ( | ||
| <View | ||
| {...restProps} | ||
|
|
@@ -66,7 +77,9 @@ | |
| styles.topSection, | ||
| roundTop && styles.roundTop, | ||
| roundTop ? { marginTop: top } : { paddingTop: top }, | ||
| spacingStyle, | ||
|
Comment on lines
77
to
+80
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
The new responsive padding in Useful? React with 👍 / 👎. |
||
| { backgroundColor }, | ||
| incomingStyle, | ||
| ]} | ||
| > | ||
| {children} | ||
|
|
@@ -108,6 +121,16 @@ | |
| const minBottom = safeAreaBottom + extraYPadding; | ||
| const totalBottom = | ||
| typeof incomingBottom === 'number' ? minBottom + incomingBottom : minBottom; | ||
| const { selectResponsiveValue } = useCompactLayout({ | ||
| compactHeight: 760, | ||
| }); | ||
| const spacingStyle = useMemo( | ||
| () => ({ | ||
| paddingHorizontal: selectResponsiveValue(16, 20, 'width'), | ||
| paddingTop: selectResponsiveValue(18, 30, 'height'), | ||
| }), | ||
| [selectResponsiveValue], | ||
| ); | ||
|
|
||
| let panelHeight: number | 'auto' = 'auto'; | ||
| // set bottom section height to 38% of screen height | ||
|
|
@@ -129,7 +152,7 @@ | |
| <View | ||
| {...props} | ||
| height={panelHeight} | ||
| style={[styles.bottomSection, style]} | ||
| style={[styles.bottomSection, spacingStyle, style]} | ||
| paddingBottom={totalBottom} | ||
| > | ||
| {children} | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fix mnemonic numbering regression
Line 44 renders
{index}, but the list now passesindex={i}(Lines 115-121), so the first pill shows0instead of1. That’s a user-visible correctness bug. Displayindex + 1(or passi + 1) before rendering.Also applies to: 115-121
🤖 Prompt for AI Agents