-
Notifications
You must be signed in to change notification settings - Fork 28
refactor(mobile): centralize safe-area spacing in useScreenInsets #2314
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
Open
Gilbert09
wants to merge
1
commit into
main
Choose a base branch
from
mobile-screen-insets-hook
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -12,7 +12,6 @@ import { | |||||||||||||||||||||
| } from "react-native"; | ||||||||||||||||||||||
| import { useReanimatedKeyboardAnimation } from "react-native-keyboard-controller"; | ||||||||||||||||||||||
| import Animated, { useAnimatedStyle } from "react-native-reanimated"; | ||||||||||||||||||||||
| import { useSafeAreaInsets } from "react-native-safe-area-context"; | ||||||||||||||||||||||
| import { FloatingBackButton } from "@/components/FloatingBackButton"; | ||||||||||||||||||||||
| import { getTask, runTaskInCloud } from "@/features/tasks/api"; | ||||||||||||||||||||||
| import { FloatingTaskHeader } from "@/features/tasks/components/FloatingTaskHeader"; | ||||||||||||||||||||||
|
|
@@ -36,6 +35,7 @@ import { useTaskSessionStore } from "@/features/tasks/stores/taskSessionStore"; | |||||||||||||||||||||
| import { useTaskStore } from "@/features/tasks/stores/taskStore"; | ||||||||||||||||||||||
| import type { Task } from "@/features/tasks/types"; | ||||||||||||||||||||||
| import { getSessionActivityPhase } from "@/features/tasks/utils/sessionActivity"; | ||||||||||||||||||||||
| import { useScreenInsets } from "@/hooks/useScreenInsets"; | ||||||||||||||||||||||
| import { logger } from "@/lib/logger"; | ||||||||||||||||||||||
| import { useThemeColors } from "@/lib/theme"; | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
|
|
@@ -59,7 +59,7 @@ export default function TaskDetailScreen() { | |||||||||||||||||||||
| }>(); | ||||||||||||||||||||||
| const router = useRouter(); | ||||||||||||||||||||||
| const queryClient = useQueryClient(); | ||||||||||||||||||||||
| const insets = useSafeAreaInsets(); | ||||||||||||||||||||||
| const { insets, composerBottom } = useScreenInsets(); | ||||||||||||||||||||||
| const themeColors = useThemeColors(); | ||||||||||||||||||||||
| const [task, setTask] = useState<Task | null>(null); | ||||||||||||||||||||||
| const [loading, setLoading] = useState(true); | ||||||||||||||||||||||
|
|
@@ -123,9 +123,9 @@ export default function TaskDetailScreen() { | |||||||||||||||||||||
| // height, so the composer sits at the keyboard top — no extra gap needed | ||||||||||||||||||||||
| // when open. Closed state keeps a comfortable bottom inset. | ||||||||||||||||||||||
| return { | ||||||||||||||||||||||
| marginBottom: height.value < 0 ? 0 : Math.max(insets.bottom, 50), | ||||||||||||||||||||||
| marginBottom: height.value < 0 ? 0 : composerBottom(), | ||||||||||||||||||||||
| }; | ||||||||||||||||||||||
| }, [insets.bottom]); | ||||||||||||||||||||||
| }, [composerBottom]); | ||||||||||||||||||||||
|
Comment on lines
125
to
+128
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.
Suggested change
Prompt To Fix With AIThis is a comment left during a code review.
Path: apps/mobile/src/app/task/[id].tsx
Line: 125-128
Comment:
Once the value is pre-computed outside the worklet, use the scalar directly and update the dependency array accordingly.
```suggestion
return {
marginBottom: height.value < 0 ? 0 : composerBottomValue,
};
}, [composerBottomValue]);
```
How can I resolve this? If you propose a fix, please make it concise. |
||||||||||||||||||||||
|
|
||||||||||||||||||||||
| useEffect(() => { | ||||||||||||||||||||||
| if (!taskId) return; | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,66 @@ | ||
| import type { ReactNode } from "react"; | ||
| import { Modal, Pressable, View } from "react-native"; | ||
| import { | ||
| type BottomGapVariant, | ||
| useScreenInsets, | ||
| } from "@/hooks/useScreenInsets"; | ||
|
|
||
| const SHEET_SHADOW = { | ||
| shadowColor: "#000", | ||
| shadowOpacity: 0.15, | ||
| shadowRadius: 20, | ||
| shadowOffset: { width: 0, height: -4 }, | ||
| elevation: 12, | ||
| } as const; | ||
|
|
||
| interface SheetContainerProps { | ||
| open: boolean; | ||
| onClose: () => void; | ||
| children: ReactNode; | ||
| /** Bottom padding gap above the safe-area inset. Defaults to "compact". */ | ||
| bottomGap?: BottomGapVariant; | ||
| /** Extra classes for the sheet panel. */ | ||
| className?: string; | ||
| } | ||
|
|
||
| /** | ||
| * Bottom-sheet shell: a dimmed backdrop, a panel pinned to the bottom edge with | ||
| * the standard rounded top, border, shadow, drag handle, and safe-area-aware | ||
| * bottom padding. Tapping the backdrop closes; taps inside the panel don't. | ||
| * | ||
| * Use this instead of re-implementing the `mt-auto rounded-t-2xl …` markup so | ||
| * every sheet shares one shape and one inset policy. | ||
| */ | ||
| export function SheetContainer({ | ||
| open, | ||
| onClose, | ||
| children, | ||
| bottomGap = "compact", | ||
| className = "", | ||
| }: SheetContainerProps) { | ||
| const { bottom } = useScreenInsets(); | ||
|
|
||
| return ( | ||
| <Modal | ||
| visible={open} | ||
| transparent | ||
| animationType="slide" | ||
| onRequestClose={onClose} | ||
| statusBarTranslucent | ||
| > | ||
| <Pressable className="flex-1 bg-black/40" onPress={onClose}> | ||
| <Pressable | ||
| onPress={() => {}} | ||
| className={`mt-auto rounded-t-2xl border-gray-6 border-t bg-background ${className}`} | ||
| style={{ paddingBottom: bottom(bottomGap), ...SHEET_SHADOW }} | ||
| > | ||
| {/* Drag handle */} | ||
| <View className="items-center pt-2 pb-1"> | ||
| <View className="h-1 w-10 rounded-full bg-gray-6" /> | ||
| </View> | ||
| {children} | ||
| </Pressable> | ||
| </Pressable> | ||
| </Modal> | ||
| ); | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
composerBottomis a plain JS function fromuseMemo, not a Reanimated worklet.useAnimatedStylecallbacks that read aSharedValue(height.value) are serialized and executed on the UI thread, where calling non-worklet JS functions throws a runtime error. The sibling filetask/index.tsxavoids this correctly by pre-computingrestingBottom = bottom("compact")outside the animated style and capturing the primitive number in the worklet closure. The same pattern should be applied here.Prompt To Fix With AI