expo / router

[ARCHIVE]: Expo Router has moved to expo/expo -- The File-based router for universal React Native apps
https://docs.expo.dev/routing/introduction/
1.37k stars 114 forks source link

Can't dynamically set gestureEnabled in a presentation: "modal" screen #778

Closed mozzius closed 1 year ago

mozzius commented 1 year ago

Which package manager are you using? (Yarn is recommended)

pnpm (known issues due to Metro)

Summary

I want to disable the swipe down gesture in a presentation: "modal" when I have unsaved changes in the screen. While I can set gestureEnabled in the layout, when I set it dynamically in a screen the setting does not work.

In fact, while I want to set it on the fly, I found it doesn't even work if you set it to false the whole time on the page using <Stack.Screen> in the screen's component.

I also tried to use navigation.setOptions in a useEffect but that didn't work either

Minimal reproducible example

// _layout.js
export default function Layout() {
  return (
    <Stack>
      <Stack.Screen title="example" options={{ presentation: "modal" }} />
    </Stack>
  )
}
// example.js
export default function Screen() {
  return (
    <>
      <Stack.Screen options={{ gestureEnabled: false }} />
      <Text>You can swipe me down</Text>
   </>
}
EvanBacon commented 1 year ago

Seems like a react-native-screens issue.

mozzius commented 1 year ago

Ok I'll open an issue there, thanks

mozzius commented 1 year ago

@EvanBacon it was entirely a me problem, sorry. I had nested another <Stack> inside the modal so obviously the gestureEnabled prop was only applied to the inner <Stack.Screen>. Apologies for not testing thoroughly enough, closing