Dynamic sizing and navigator #1590
Replies: 5 comments 1 reply
-
I think I am running into this as well. Switching between different screens of a stack navigator, causes the dynamicSizing to expand the height correctly but does not shrink back down if I navigate to a smaller "screen". Has anyone found an escape hatch to cause the bottom sheet to recalculate? |
Beta Was this translation helpful? Give feedback.
-
I believe I might be encountering a similar challenge with implementing a bottom sheet that dynamically adjusts its size when navigating. Have you come across a solution or a reliable approach for this? |
Beta Was this translation helpful? Give feedback.
-
I dropped the react-native stack navigator and hand rolled my own, which resolved all of my issues. Each one of my "ScreenComponents" has its top most component being either a BottomSheetView or a BottomSheetScrollView, when switching between them everything resizes as expected. I built this with zustand but I am sure you can easily convert it to a Context based or any other state management based solution. Here is the gist of it: export const BottomSheetNavigator = (props: Props) => {
const screen = useNavigatorStore(s => s.screen);
const initialRouteName = useMemo(() => {
// return one of the screens conditionally if needed
}, [someDependency]);
const isLoading = initialRouteName === undefined;
if (isLoading) {
return <Loading />;
}
const ScreenToRender = screens[screen ?? initialRouteName];
return <ScreenToRender {...props} />;
};
const screens = {
Screen1: memo(Screen1Component),
Screen2: memo(Screen2Component),
etc...
};
export type Screen = keyof typeof screens;
type NavigatorStore = {
screen: Screen | null;
navigate: (screen: Screen) => void;
reset: () => void;
};
export const useNavigatorStore = create<NavigatorStore>(set => ({
screen: null,
navigate: screen => set({ screen }),
reset: () => set({ screen: null }),
})); |
Beta Was this translation helpful? Give feedback.
-
Any updates? |
Beta Was this translation helpful? Give feedback.
-
i'd be really keen for this to be handled seamlessly, i've got most of the way there with dynamic snap points that are updated by child onLayout calls, but it feels incredibly janky and not very intuitive |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Dynamic sizing does not seem to work well with having a stack navigator inside a bottom sheet. Is there some way I can trigger a recalculation on e.g. a
navigate
event? I triedaddEventListener
in combination withsnapToIndex
orexpand
but it only snaps to a known snappoint.Beta Was this translation helpful? Give feedback.
All reactions