-
Notifications
You must be signed in to change notification settings - Fork 1.4k
feat: basic setup react-native-true-sheet #6970
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: develop
Are you sure you want to change the base?
Changes from all commits
65be6cf
08056fb
b4a596f
76cc834
6b25f98
767bbe9
73cb35d
1d89804
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,26 @@ | ||
| import { useMemo } from 'react'; | ||
|
|
||
| import type { TActionSheetOptions } from './Provider'; | ||
| import { getDetents } from './utils'; | ||
|
|
||
| interface UseActionSheetDetentsParams { | ||
| data: TActionSheetOptions; | ||
| windowHeight: number; | ||
| contentHeight: number; | ||
| itemHeight: number; | ||
| bottom: number; | ||
| } | ||
|
|
||
| export function useActionSheetDetents({ data, windowHeight, contentHeight, itemHeight, bottom }: UseActionSheetDetentsParams) { | ||
| return useMemo( | ||
| () => | ||
| getDetents({ | ||
| data, | ||
| windowHeight, | ||
| contentHeight, | ||
| itemHeight, | ||
| bottom | ||
| }), | ||
| [data, windowHeight, contentHeight, itemHeight, bottom] | ||
| ); | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,61 @@ | ||
| import type { SheetDetent } from '@lodev09/react-native-true-sheet'; | ||
|
|
||
| import type { TActionSheetOptions } from './Provider'; | ||
|
|
||
| export const ACTION_SHEET_MIN_HEIGHT_FRACTION = 0.35; | ||
| export const ACTION_SHEET_MAX_HEIGHT_FRACTION = 0.75; | ||
| export const HANDLE_HEIGHT = 28; | ||
| export const CANCEL_HEIGHT = 64; | ||
|
|
||
| interface IGetDetentsParams { | ||
| data: TActionSheetOptions; | ||
| windowHeight: number; | ||
| contentHeight: number; | ||
| itemHeight: number; | ||
| bottom: number; | ||
| } | ||
|
|
||
| export const normalizeSnapsToDetents = (snaps: (string | number)[]): number[] => | ||
| snaps | ||
| .slice(0, 3) | ||
| .map(snap => { | ||
| if (typeof snap === 'number') { | ||
| if (snap <= 0 || snap > 1) return Math.min(1, Math.max(0.1, snap)); | ||
| return snap; | ||
| } | ||
| const match = String(snap).match(/^(\d+(?:\.\d+)?)\s*%$/); | ||
| if (match) return Math.min(1, Math.max(0.1, Number(match[1]) / 100)); | ||
| return 0.5; | ||
| }) | ||
| .sort((a, b) => a - b); | ||
|
Comment on lines
+18
to
+30
Contributor
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. 🧩 Analysis chain🏁 Script executed: rg -n --type=ts --type=tsx 'snaps\s*[:=]' -C 3 | head -100Repository: RocketChat/Rocket.Chat.ReactNative Length of output: 105 🏁 Script executed: # Look at the actual file to understand the function better
cat -n app/containers/ActionSheet/utils.tsRepository: RocketChat/Rocket.Chat.ReactNative Length of output: 2509 🏁 Script executed: # Check Provider.tsx for context about snaps type and usage
rg -n 'snaps' app/containers/ActionSheet/Provider.tsx -C 2Repository: RocketChat/Rocket.Chat.ReactNative Length of output: 401 🏁 Script executed: rg -n 'snaps\s*[=:]\s*\[' --type ts -C 2Repository: RocketChat/Rocket.Chat.ReactNative Length of output: 1045 🏁 Script executed: # Also search for ActionSheet component usage
rg -n 'ActionSheet' --type ts -C 1 | grep -A 2 -B 2 'snaps' | head -60Repository: RocketChat/Rocket.Chat.ReactNative Length of output: 353 🏁 Script executed: # Look for any comments or migration notes about snaps/pixel values
rg -n 'pixel|detent|snap' app/containers/ActionSheet/ --type tsRepository: RocketChat/Rocket.Chat.ReactNative Length of output: 1110 🏁 Script executed: cat -n app/lib/hooks/useVideoConf/index.tsx | sed -n '55,75p'Repository: RocketChat/Rocket.Chat.ReactNative Length of output: 651 🏁 Script executed: # Check git history or comments around this line
git log --oneline -n 20 -- app/lib/hooks/useVideoConf/index.tsx 2>/dev/null || echo "Git history not available"Repository: RocketChat/Rocket.Chat.ReactNative Length of output: 125 🏁 Script executed: # Check if there are any other references to understanding what 480 means in this context
rg -n '480|windowHeight' app/lib/hooks/useVideoConf/index.tsx -C 5Repository: RocketChat/Rocket.Chat.ReactNative Length of output: 375 🏁 Script executed: # Check if there's a test or if 480 is actually being used
rg -n 'StartACallActionSheet' --type ts -C 3 | head -40Repository: RocketChat/Rocket.Chat.ReactNative Length of output: 1712 🏁 Script executed: # Check the old bottom-sheet or previous implementation for context
rg -n 'bottom.?sheet|BottomSheet' --type ts -i | head -20Repository: RocketChat/Rocket.Chat.ReactNative Length of output: 2068 🏁 Script executed: # Check if SheetDetent type is defined locally or imported
fd 'SheetDetent' --type ts -x cat -n {} 2>/dev/null | head -20Repository: RocketChat/Rocket.Chat.ReactNative Length of output: 60 🏁 Script executed: # Check if there's documentation about what the expected snap values should be
rg -n 'TrueSheet|react-native-true-sheet' --type ts -C 2 | head -40Repository: RocketChat/Rocket.Chat.ReactNative Length of output: 2025 🏁 Script executed: cat -n app/containers/ActionSheet/utils.ts | sed -n '18,65p'Repository: RocketChat/Rocket.Chat.ReactNative Length of output: 1943 🏁 Script executed: # Check ActionSheet.tsx to see how detents is used
cat -n app/containers/ActionSheet/ActionSheet.tsx | sed -n '30,50p'Repository: RocketChat/Rocket.Chat.ReactNative Length of output: 693 🏁 Script executed: # Get the exact function signatures and return types
rg -n 'useActionSheetDetents' app/containers/ActionSheet/ -A 10 -B 2Repository: RocketChat/Rocket.Chat.ReactNative Length of output: 3252 🏁 Script executed: # Verify the type of detents variable
grep -n 'detents.*=' app/containers/ActionSheet/ActionSheet.tsx | head -5Repository: RocketChat/Rocket.Chat.ReactNative Length of output: 149
The code supports two snap formats—legacy pixel values (e.g., Example: To fix this, either:
Also note: 🤖 Prompt for AI Agents |
||
|
|
||
| export const getDetents = ({ data, windowHeight, contentHeight, itemHeight, bottom }: IGetDetentsParams): SheetDetent[] => { | ||
| const hasOptions = (data?.options?.length || 0) > 0; | ||
| const maxSnap = hasOptions | ||
| ? Math.min( | ||
| (itemHeight + 0.5) * (data?.options?.length || 0) + | ||
| HANDLE_HEIGHT + | ||
| (data?.headerHeight || 0) + | ||
| bottom + | ||
| (data?.hasCancel ? CANCEL_HEIGHT : 0), | ||
| windowHeight * ACTION_SHEET_MAX_HEIGHT_FRACTION | ||
| ) | ||
| : 0; | ||
|
|
||
| if (data?.snaps?.length) { | ||
| return normalizeSnapsToDetents(data.snaps); | ||
| } | ||
| if (hasOptions) { | ||
| if (maxSnap > windowHeight * 0.6) { | ||
| return [0.5, ACTION_SHEET_MAX_HEIGHT_FRACTION]; | ||
| } | ||
| const fraction = Math.max(0.25, Math.min(maxSnap / windowHeight, ACTION_SHEET_MAX_HEIGHT_FRACTION)); | ||
| return [fraction]; | ||
| } | ||
| if (contentHeight > 0) { | ||
| const fraction = Math.min(contentHeight / windowHeight, ACTION_SHEET_MAX_HEIGHT_FRACTION); | ||
| const contentDetent = Math.max(0.25, fraction); | ||
| return contentDetent > ACTION_SHEET_MIN_HEIGHT_FRACTION ? [ACTION_SHEET_MIN_HEIGHT_FRACTION, contentDetent] : [contentDetent]; | ||
| } | ||
| return [ACTION_SHEET_MIN_HEIGHT_FRACTION, 'auto']; | ||
| }; | ||
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.
🛠️ Refactor suggestion | 🟠 Major
Pass
childrenvia JSX elements instead of thechildrenprop.As flagged by static analysis (Biome
noChildrenProp), passing children via a prop is not the canonical React pattern. Use JSX nesting instead.♻️ Proposed fix
<BottomSheetContent options={data?.options} hide={hide} - children={data?.children} hasCancel={data?.hasCancel} - onLayout={handleContentLayout} - /> + onLayout={handleContentLayout}> + {data?.children} + </BottomSheetContent>📝 Committable suggestion
🧰 Tools
🪛 Biome (2.3.13)
[error] 115-115: Avoid passing children using a prop
The canonical way to pass children in React is to use JSX elements
(lint/correctness/noChildrenProp)
🤖 Prompt for AI Agents