@react-navigation/native-stack 6.7.0 → 6.9.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (31) hide show
  1. package/lib/commonjs/utils/useDismissedRouteError.js +29 -0
  2. package/lib/commonjs/utils/useDismissedRouteError.js.map +1 -0
  3. package/lib/commonjs/utils/useInvalidPreventRemoveError.js +33 -0
  4. package/lib/commonjs/utils/useInvalidPreventRemoveError.js.map +1 -0
  5. package/lib/commonjs/views/HeaderConfig.js +3 -5
  6. package/lib/commonjs/views/HeaderConfig.js.map +1 -1
  7. package/lib/commonjs/views/NativeStackView.js +9 -5
  8. package/lib/commonjs/views/NativeStackView.js.map +1 -1
  9. package/lib/commonjs/views/NativeStackView.native.js +63 -24
  10. package/lib/commonjs/views/NativeStackView.native.js.map +1 -1
  11. package/lib/module/utils/useDismissedRouteError.js +17 -0
  12. package/lib/module/utils/useDismissedRouteError.js.map +1 -0
  13. package/lib/module/utils/useInvalidPreventRemoveError.js +20 -0
  14. package/lib/module/utils/useInvalidPreventRemoveError.js.map +1 -0
  15. package/lib/module/views/HeaderConfig.js +3 -4
  16. package/lib/module/views/HeaderConfig.js.map +1 -1
  17. package/lib/module/views/NativeStackView.js +10 -6
  18. package/lib/module/views/NativeStackView.js.map +1 -1
  19. package/lib/module/views/NativeStackView.native.js +63 -26
  20. package/lib/module/views/NativeStackView.native.js.map +1 -1
  21. package/lib/typescript/src/types.d.ts +8 -0
  22. package/lib/typescript/src/utils/useDismissedRouteError.d.ts +5 -0
  23. package/lib/typescript/src/utils/useInvalidPreventRemoveError.d.ts +2 -0
  24. package/lib/typescript/src/views/HeaderConfig.d.ts +2 -1
  25. package/package.json +11 -9
  26. package/src/types.tsx +8 -0
  27. package/src/utils/useDismissedRouteError.tsx +30 -0
  28. package/src/utils/useInvalidPreventRemoveError.tsx +31 -0
  29. package/src/views/HeaderConfig.tsx +4 -5
  30. package/src/views/NativeStackView.native.tsx +77 -38
  31. package/src/views/NativeStackView.tsx +20 -12
@@ -1 +1 @@
1
- {"version":3,"sources":["NativeStackView.native.tsx"],"names":["getDefaultHeaderHeight","getHeaderTitle","HeaderHeightContext","HeaderShownContext","SafeAreaProviderCompat","NavigationContext","NavigationRouteContext","StackActions","useTheme","React","Platform","StyleSheet","View","useSafeAreaFrame","useSafeAreaInsets","Screen","ScreenStack","warnOnce","DebugContainer","HeaderConfig","isAndroid","OS","MaybeNestedStack","options","route","presentation","headerHeight","children","colors","header","headerShown","contentStyle","isHeaderInModal","undefined","headerShownPreviousRef","useRef","useEffect","current","name","content","styles","container","backgroundColor","background","absoluteFill","SceneView","descriptor","previousDescriptor","nextDescriptor","index","onWillDisappear","onAppear","onDisappear","onDismissed","navigation","render","animationDuration","animationTypeForReplace","gestureEnabled","autoHideHomeIndicator","navigationBarColor","navigationBarHidden","orientation","statusBarAnimation","statusBarHidden","statusBarStyle","statusBarTranslucent","statusBarColor","animation","customAnimationOnGesture","fullScreenGestureEnabled","gestureDirection","nextGestureDirection","gestureDirectionOverride","isHeaderInPush","insets","frame","isModal","isIPhone","isPad","isTVOS","isLandscape","width","height","topInset","top","isParentHeaderShown","useContext","parentHeaderHeight","defaultHeaderHeight","customHeaderHeight","setCustomHeaderHeight","useState","key","e","nativeEvent","layout","back","title","NativeStackViewInner","state","descriptors","nextDismissedKey","setNextDismissedKey","dismissedRouteName","routes","find","message","console","error","map","previousKey","nextKey","emit","type","data","closing","target","event","dispatch","pop","dismissCount","source","NativeStackView","props","create","flex"],"mappings":";;AAAA,SACEA,sBADF,EAEEC,cAFF,EAGEC,mBAHF,EAIEC,kBAJF,EAKEC,sBALF,QAMO,4BANP;AAOA,SACEC,iBADF,EAEEC,sBAFF,EAKEC,YALF,EAOEC,QAPF,QAQO,0BARP;AASA,OAAO,KAAKC,KAAZ,MAAuB,OAAvB;AACA,SAASC,QAAT,EAAmBC,UAAnB,EAA+BC,IAA/B,QAA2C,cAA3C;AACA,SACEC,gBADF,EAEEC,iBA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AAAA,OAAO,EAAE;AAAX,WAFQ;AAGdC,UAAAA,MAAM,EAAE7F,KAAK,CAACqE;AAHA,SAAhB;AAKD,OA1BH;AA2BE,MAAA,WAAW,EAAGyB,KAAD,IAAW;AACtBhE,QAAAA,UAAU,CAACiE,QAAX,CAAoB,EAClB,GAAGhH,YAAY,CAACiH,GAAb,CAAiBF,KAAK,CAACvB,WAAN,CAAkB0B,YAAnC,CADe;AAElBC,UAAAA,MAAM,EAAElG,KAAK,CAACqE,GAFI;AAGlBwB,UAAAA,MAAM,EAAEjB,KAAK,CAACP;AAHI,SAApB;AAMAU,QAAAA,mBAAmB,CAAC/E,KAAK,CAACqE,GAAP,CAAnB;AACD;AAnCH,MADF;AAuCD,GAhDA,CADH,CADF;AAqDD;;AAED,eAAe,SAAS8B,eAAT,CAAyBC,KAAzB,EAAuC;AACpD,sBACE,oBAAC,sBAAD,qBACE,oBAAC,oBAAD,EAA0BA,KAA1B,CADF,CADF;AAKD;AAED,MAAMpF,MAAM,GAAG7B,UAAU,CAACkH,MAAX,CAAkB;AAC/BpF,EAAAA,SAAS,EAAE;AACTqF,IAAAA,IAAI,EAAE;AADG;AADoB,CAAlB,CAAf","sourcesContent":["import {\n getDefaultHeaderHeight,\n getHeaderTitle,\n HeaderHeightContext,\n HeaderShownContext,\n SafeAreaProviderCompat,\n} from '@react-navigation/elements';\nimport {\n NavigationContext,\n NavigationRouteContext,\n ParamListBase,\n Route,\n StackActions,\n StackNavigationState,\n useTheme,\n} from '@react-navigation/native';\nimport * as React from 'react';\nimport { Platform, StyleSheet, View } from 'react-native';\nimport {\n useSafeAreaFrame,\n useSafeAreaInsets,\n} from 'react-native-safe-area-context';\nimport type { ScreenProps } from 'react-native-screens';\nimport {\n Screen,\n ScreenStack,\n StackPresentationTypes,\n} from 'react-native-screens';\nimport warnOnce from 'warn-once';\n\nimport type {\n NativeStackDescriptor,\n NativeStackDescriptorMap,\n NativeStackNavigationHelpers,\n NativeStackNavigationOptions,\n} from '../types';\nimport DebugContainer from './DebugContainer';\nimport HeaderConfig from './HeaderConfig';\n\nconst isAndroid = Platform.OS === 'android';\n\nconst MaybeNestedStack = ({\n options,\n route,\n presentation,\n headerHeight,\n children,\n}: {\n options: NativeStackNavigationOptions;\n route: Route<string>;\n presentation: Exclude<StackPresentationTypes, 'push'> | 'card';\n headerHeight: number;\n children: React.ReactNode;\n}) => {\n const { colors } = useTheme();\n const { header, headerShown = true, contentStyle } = options;\n\n const isHeaderInModal = isAndroid\n ? false\n : presentation !== 'card' && headerShown === true && header === undefined;\n\n const headerShownPreviousRef = React.useRef(headerShown);\n\n React.useEffect(() => {\n warnOnce(\n !isAndroid &&\n presentation !== 'card' &&\n headerShownPreviousRef.current !== headerShown,\n `Dynamically changing 'headerShown' in modals will result in remounting the screen and losing all local state. See options for the screen '${route.name}'.`\n );\n\n headerShownPreviousRef.current = headerShown;\n }, [headerShown, presentation, route.name]);\n\n const content = (\n <DebugContainer\n style={[\n styles.container,\n presentation !== 'transparentModal' &&\n presentation !== 'containedTransparentModal' && {\n backgroundColor: colors.background,\n },\n contentStyle,\n ]}\n stackPresentation={presentation === 'card' ? 'push' : presentation}\n >\n {children}\n </DebugContainer>\n );\n\n if (isHeaderInModal) {\n return (\n <ScreenStack style={styles.container}>\n <Screen enabled style={StyleSheet.absoluteFill}>\n <HeaderConfig\n {...options}\n route={route}\n headerHeight={headerHeight}\n canGoBack\n />\n {content}\n </Screen>\n </ScreenStack>\n );\n }\n\n return content;\n};\n\ntype SceneViewProps = {\n index: number;\n descriptor: NativeStackDescriptor;\n previousDescriptor?: NativeStackDescriptor;\n nextDescriptor?: NativeStackDescriptor;\n onWillDisappear: () => void;\n onAppear: () => void;\n onDisappear: () => void;\n onDismissed: ScreenProps['onDismissed'];\n};\n\nconst SceneView = ({\n descriptor,\n previousDescriptor,\n nextDescriptor,\n index,\n onWillDisappear,\n onAppear,\n onDisappear,\n onDismissed,\n}: SceneViewProps) => {\n const { route, navigation, options, render } = descriptor;\n const {\n animationDuration,\n animationTypeForReplace = 'push',\n gestureEnabled,\n header,\n headerShown,\n autoHideHomeIndicator,\n navigationBarColor,\n navigationBarHidden,\n orientation,\n statusBarAnimation,\n statusBarHidden,\n statusBarStyle,\n statusBarTranslucent,\n statusBarColor,\n } = options;\n\n let {\n animation,\n customAnimationOnGesture,\n fullScreenGestureEnabled,\n presentation = 'card',\n gestureDirection = presentation === 'card' ? 'horizontal' : 'vertical',\n } = options;\n\n if (gestureDirection === 'vertical' && Platform.OS === 'ios') {\n // for `vertical` direction to work, we need to set `fullScreenGestureEnabled` to `true`\n // so the screen can be dismissed from any point on screen.\n // `customAnimationOnGesture` needs to be set to `true` so the `animation` set by user can be used,\n // otherwise `simple_push` will be used.\n // Also, the default animation for this direction seems to be `slide_from_bottom`.\n if (fullScreenGestureEnabled === undefined) {\n fullScreenGestureEnabled = true;\n }\n if (customAnimationOnGesture === undefined) {\n customAnimationOnGesture = true;\n }\n if (animation === undefined) {\n animation = 'slide_from_bottom';\n }\n }\n\n // workaround for rn-screens where gestureDirection has to be set on both\n // current and previous screen - software-mansion/react-native-screens/pull/1509\n const nextGestureDirection = nextDescriptor?.options.gestureDirection;\n const gestureDirectionOverride =\n nextGestureDirection != null ? nextGestureDirection : gestureDirection;\n\n if (index === 0) {\n // first screen should always be treated as `card`, it resolves problems with no header animation\n // for navigator with first screen as `modal` and the next as `card`\n presentation = 'card';\n }\n\n const isHeaderInPush = isAndroid\n ? headerShown\n : presentation === 'card' && headerShown !== false;\n\n const insets = useSafeAreaInsets();\n const frame = useSafeAreaFrame();\n\n // `modal` and `formSheet` presentations do not take whole screen, so should not take the inset.\n const isModal = presentation === 'modal' || presentation === 'formSheet';\n\n // Modals are fullscreen in landscape only on iPhone\n const isIPhone =\n Platform.OS === 'ios' && !(Platform.isPad || Platform.isTVOS);\n const isLandscape = frame.width > frame.height;\n\n const topInset = isModal || (isIPhone && isLandscape) ? 0 : insets.top;\n\n const isParentHeaderShown = React.useContext(HeaderShownContext);\n const parentHeaderHeight = React.useContext(HeaderHeightContext);\n\n const defaultHeaderHeight = getDefaultHeaderHeight(frame, isModal, topInset);\n\n const [customHeaderHeight, setCustomHeaderHeight] =\n React.useState(defaultHeaderHeight);\n\n const headerHeight = header ? customHeaderHeight : defaultHeaderHeight;\n\n return (\n <Screen\n key={route.key}\n enabled\n style={StyleSheet.absoluteFill}\n customAnimationOnSwipe={customAnimationOnGesture}\n fullScreenSwipeEnabled={fullScreenGestureEnabled}\n gestureEnabled={\n isAndroid\n ? // This prop enables handling of system back gestures on Android\n // Since we handle them in JS side, we disable this\n false\n : gestureEnabled\n }\n homeIndicatorHidden={autoHideHomeIndicator}\n navigationBarColor={navigationBarColor}\n navigationBarHidden={navigationBarHidden}\n replaceAnimation={animationTypeForReplace}\n stackPresentation={presentation === 'card' ? 'push' : presentation}\n stackAnimation={animation}\n screenOrientation={orientation}\n statusBarAnimation={statusBarAnimation}\n statusBarHidden={statusBarHidden}\n statusBarStyle={statusBarStyle}\n statusBarColor={statusBarColor}\n statusBarTranslucent={statusBarTranslucent}\n swipeDirection={gestureDirectionOverride}\n transitionDuration={animationDuration}\n onWillDisappear={onWillDisappear}\n onAppear={onAppear}\n onDisappear={onDisappear}\n onDismissed={onDismissed}\n isNativeStack\n >\n <NavigationContext.Provider value={navigation}>\n <NavigationRouteContext.Provider value={route}>\n <HeaderShownContext.Provider\n value={isParentHeaderShown || isHeaderInPush !== false}\n >\n <HeaderHeightContext.Provider\n value={\n isHeaderInPush !== false\n ? headerHeight\n : parentHeaderHeight ?? 0\n }\n >\n {header !== undefined && headerShown !== false ? (\n <View\n onLayout={(e) => {\n setCustomHeaderHeight(e.nativeEvent.layout.height);\n }}\n >\n {header({\n back: previousDescriptor\n ? {\n title: getHeaderTitle(\n previousDescriptor.options,\n previousDescriptor.route.name\n ),\n }\n : undefined,\n options,\n route,\n navigation,\n })}\n </View>\n ) : (\n <HeaderConfig\n {...options}\n route={route}\n headerShown={isHeaderInPush}\n headerHeight={headerHeight}\n canGoBack={index !== 0}\n />\n )}\n <MaybeNestedStack\n options={options}\n route={route}\n presentation={presentation}\n headerHeight={headerHeight}\n >\n {render()}\n </MaybeNestedStack>\n </HeaderHeightContext.Provider>\n </HeaderShownContext.Provider>\n </NavigationRouteContext.Provider>\n </NavigationContext.Provider>\n </Screen>\n );\n};\n\ntype Props = {\n state: StackNavigationState<ParamListBase>;\n navigation: NativeStackNavigationHelpers;\n descriptors: NativeStackDescriptorMap;\n};\n\nfunction NativeStackViewInner({ state, navigation, descriptors }: Props) {\n const [nextDismissedKey, setNextDismissedKey] = React.useState<string | null>(\n null\n );\n\n const dismissedRouteName = nextDismissedKey\n ? state.routes.find((route) => route.key === nextDismissedKey)?.name\n : null;\n\n React.useEffect(() => {\n if (dismissedRouteName) {\n const message =\n `The screen '${dismissedRouteName}' was removed natively but didn't get removed from JS state. ` +\n `This can happen if the action was prevented in a 'beforeRemove' listener, which is not fully supported in native-stack.\\n\\n` +\n `Consider using 'gestureEnabled: false' to prevent back gesture and use a custom back button with 'headerLeft' option to override the native behavior.`;\n\n console.error(message);\n }\n }, [dismissedRouteName]);\n\n return (\n <ScreenStack style={styles.container}>\n {state.routes.map((route, index) => {\n const descriptor = descriptors[route.key];\n const previousKey = state.routes[index - 1]?.key;\n const nextKey = state.routes[index + 1]?.key;\n const previousDescriptor = previousKey\n ? descriptors[previousKey]\n : undefined;\n const nextDescriptor = nextKey ? descriptors[nextKey] : undefined;\n\n return (\n <SceneView\n key={route.key}\n index={index}\n descriptor={descriptor}\n previousDescriptor={previousDescriptor}\n nextDescriptor={nextDescriptor}\n onWillDisappear={() => {\n navigation.emit({\n type: 'transitionStart',\n data: { closing: true },\n target: route.key,\n });\n }}\n onAppear={() => {\n navigation.emit({\n type: 'transitionEnd',\n data: { closing: false },\n target: route.key,\n });\n }}\n onDisappear={() => {\n navigation.emit({\n type: 'transitionEnd',\n data: { closing: true },\n target: route.key,\n });\n }}\n onDismissed={(event) => {\n navigation.dispatch({\n ...StackActions.pop(event.nativeEvent.dismissCount),\n source: route.key,\n target: state.key,\n });\n\n setNextDismissedKey(route.key);\n }}\n />\n );\n })}\n </ScreenStack>\n );\n}\n\nexport default function NativeStackView(props: Props) {\n return (\n <SafeAreaProviderCompat>\n <NativeStackViewInner {...props} />\n </SafeAreaProviderCompat>\n );\n}\n\nconst styles = StyleSheet.create({\n container: {\n flex: 1,\n },\n});\n"]}
1
+ {"version":3,"sources":["NativeStackView.native.tsx"],"names":["getDefaultHeaderHeight","getHeaderTitle","HeaderBackContext","HeaderHeightContext","HeaderShownContext","SafeAreaProviderCompat","NavigationContext","NavigationRouteContext","StackActions","usePreventRemoveContext","useTheme","React","Platform","StyleSheet","View","useSafeAreaFrame","useSafeAreaInsets","Screen","ScreenStack","warnOnce","useDismissedRouteError","useInvalidPreventRemoveError","DebugContainer","HeaderConfig","isAndroid","OS","MaybeNestedStack","options","route","presentation","headerHeight","headerTopInsetEnabled","children","colors","header","headerShown","contentStyle","isHeaderInModal","undefined","headerShownPreviousRef","useRef","useEffect","current","name","content","styles","container","backgroundColor","background","absoluteFill","SceneView","descriptor","previousDescriptor","nextDescriptor","index","onWillDisappear","onAppear","onDisappear","onDismissed","onHeaderBackButtonClicked","onNativeDismissCancelled","navigation","render","animationDuration","animationTypeForReplace","gestureEnabled","headerBackButtonMenuEnabled","autoHideHomeIndicator","navigationBarColor","navigationBarHidden","orientation","statusBarAnimation","statusBarHidden","statusBarStyle","statusBarTranslucent","statusBarColor","freezeOnBlur","animation","customAnimationOnGesture","fullScreenGestureEnabled","gestureDirection","nextGestureDirection","gestureDirectionOverride","insets","frame","isModal","isIPhone","isPad","isTVOS","isLandscape","width","height","isParentHeaderShown","useContext","parentHeaderHeight","parentHeaderBack","topInset","top","preventedRoutes","defaultHeaderHeight","customHeaderHeight","setCustomHeaderHeight","useState","headerBack","title","isRemovePrevented","key","preventRemove","e","nativeEvent","layout","back","headerBackTitle","NativeStackViewInner","state","descriptors","setNextDismissedKey","routes","map","previousKey","nextKey","emit","type","data","closing","target","event","dispatch","pop","dismissCount","source","NativeStackView","props","create","flex"],"mappings":";;AAAA,SACEA,sBADF,EAEEC,cAFF,EAGEC,iBAHF,EAIEC,mBAJF,EAKEC,kBALF,EAMEC,sBANF,QAOO,4BAPP;AAQA,SACEC,iBADF,EAEEC,sBAFF,EAKEC,YALF,EAOEC,uBAPF,EAQEC,QARF,QASO,0BATP;AAUA,OAAO,KAAKC,KAAZ,MAAuB,OAAvB;AACA,SAASC,QAAT,EAAmBC,UAAnB,EAA+BC,IAA/B,QAA2C,cAA3C;AACA,SACEC,gBADF,EAEEC,iBAFF,QAGO,gCAHP;AAKA,SACEC,MADF,EAEEC,WAFF,QAIO,sBAJP;AAKA,OAAOC,QAAP,MAAqB,WAArB;AAQA,OAAOC,sBAAP,MAAmC,iCAAnC;AACA,OAAOC,4BAAP,MAAyC,uCAAzC;AACA,OAAOC,cAAP,MAA2B,kBAA3B;AACA,OAAOC,YAAP,MAAyB,gBAAzB;AAEA,MAAMC,SAAS,GAAGZ,QAAQ,CAACa,EAAT,KAAgB,SAAlC;;AAEA,MAAMC,gBAAgB,GAAG,QAcnB;AAAA,MAdoB;AACxBC,IAAAA,OADwB;AAExBC,IAAAA,KAFwB;AAGxBC,IAAAA,YAHwB;AAIxBC,IAAAA,YAJwB;AAKxBC,IAAAA,qBALwB;AAMxBC,IAAAA;AANwB,GAcpB;AACJ,QAAM;AAAEC,IAAAA;AAAF,MAAavB,QAAQ,EAA3B;AACA,QAAM;AAAEwB,IAAAA,MAAF;AAAUC,IAAAA,WAAW,GAAG,IAAxB;AAA8BC,IAAAA;AAA9B,MAA+CT,OAArD;AAEA,QAAMU,eAAe,GAAGb,SAAS,GAC7B,KAD6B,GAE7BK,YAAY,KAAK,MAAjB,IAA2BM,WAAW,KAAK,IAA3C,IAAmDD,MAAM,KAAKI,SAFlE;AAIA,QAAMC,sBAAsB,GAAG5B,KAAK,CAAC6B,MAAN,CAAaL,WAAb,CAA/B;AAEAxB,EAAAA,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E,QAAX,CAAoB,EAClB,GAAGvH,YAAY,CAACwH,GAAb,CAAiBF,KAAK,CAACjB,WAAN,CAAkBoB,YAAnC,CADe;AAElBC,UAAAA,MAAM,EAAEtG,KAAK,CAAC8E,GAFI;AAGlBmB,UAAAA,MAAM,EAAEX,KAAK,CAACR;AAHI,SAApB;AAMAU,QAAAA,mBAAmB,CAACxF,KAAK,CAAC8E,GAAP,CAAnB;AACD,OAnCH;AAoCE,MAAA,yBAAyB,EAAE,MAAM;AAC/B7C,QAAAA,UAAU,CAACkE,QAAX,CAAoB,EAClB,GAAGvH,YAAY,CAACwH,GAAb,EADe;AAElBE,UAAAA,MAAM,EAAEtG,KAAK,CAAC8E,GAFI;AAGlBmB,UAAAA,MAAM,EAAEX,KAAK,CAACR;AAHI,SAApB;AAKD,OA1CH;AA2CE,MAAA,wBAAwB,EAAGoB,KAAD,IAAW;AACnCjE,QAAAA,UAAU,CAACkE,QAAX,CAAoB,EAClB,GAAGvH,YAAY,CAACwH,GAAb,CAAiBF,KAAK,CAACjB,WAAN,CAAkBoB,YAAnC,CADe;AAElBC,UAAAA,MAAM,EAAEtG,KAAK,CAAC8E,GAFI;AAGlBmB,UAAAA,MAAM,EAAEX,KAAK,CAACR;AAHI,SAApB;AAKD;AAjDH,MADF;AAqDD,GA9DA,CADH,CADF;AAmED;;AAED,eAAe,SAASyB,eAAT,CAAyBC,KAAzB,EAAuC;AACpD,sBACE,oBAAC,sBAAD,qBACE,oBAAC,oBAAD,EAA0BA,KAA1B,CADF,CADF;AAKD;AAED,MAAMvF,MAAM,GAAGhC,UAAU,CAACwH,MAAX,CAAkB;AAC/BvF,EAAAA,SAAS,EAAE;AACTwF,IAAAA,IAAI,EAAE;AADG;AADoB,CAAlB,CAAf","sourcesContent":["import {\n getDefaultHeaderHeight,\n getHeaderTitle,\n HeaderBackContext,\n HeaderHeightContext,\n HeaderShownContext,\n SafeAreaProviderCompat,\n} from '@react-navigation/elements';\nimport {\n NavigationContext,\n NavigationRouteContext,\n ParamListBase,\n Route,\n StackActions,\n StackNavigationState,\n usePreventRemoveContext,\n useTheme,\n} from '@react-navigation/native';\nimport * as React from 'react';\nimport { Platform, StyleSheet, View } from 'react-native';\nimport {\n useSafeAreaFrame,\n useSafeAreaInsets,\n} from 'react-native-safe-area-context';\nimport type { ScreenProps } from 'react-native-screens';\nimport {\n Screen,\n ScreenStack,\n StackPresentationTypes,\n} from 'react-native-screens';\nimport warnOnce from 'warn-once';\n\nimport type {\n NativeStackDescriptor,\n NativeStackDescriptorMap,\n NativeStackNavigationHelpers,\n NativeStackNavigationOptions,\n} from '../types';\nimport useDismissedRouteError from '../utils/useDismissedRouteError';\nimport useInvalidPreventRemoveError from '../utils/useInvalidPreventRemoveError';\nimport DebugContainer from './DebugContainer';\nimport HeaderConfig from './HeaderConfig';\n\nconst isAndroid = Platform.OS === 'android';\n\nconst MaybeNestedStack = ({\n options,\n route,\n presentation,\n headerHeight,\n headerTopInsetEnabled,\n children,\n}: {\n options: NativeStackNavigationOptions;\n route: Route<string>;\n presentation: Exclude<StackPresentationTypes, 'push'> | 'card';\n headerHeight: number;\n headerTopInsetEnabled: boolean;\n children: React.ReactNode;\n}) => {\n const { colors } = useTheme();\n const { header, headerShown = true, contentStyle } = options;\n\n const isHeaderInModal = isAndroid\n ? false\n : presentation !== 'card' && headerShown === true && header === undefined;\n\n const headerShownPreviousRef = React.useRef(headerShown);\n\n React.useEffect(() => {\n warnOnce(\n !isAndroid &&\n presentation !== 'card' &&\n headerShownPreviousRef.current !== headerShown,\n `Dynamically changing 'headerShown' in modals will result in remounting the screen and losing all local state. See options for the screen '${route.name}'.`\n );\n\n headerShownPreviousRef.current = headerShown;\n }, [headerShown, presentation, route.name]);\n\n const content = (\n <DebugContainer\n style={[\n styles.container,\n presentation !== 'transparentModal' &&\n presentation !== 'containedTransparentModal' && {\n backgroundColor: colors.background,\n },\n contentStyle,\n ]}\n stackPresentation={presentation === 'card' ? 'push' : presentation}\n >\n {children}\n </DebugContainer>\n );\n\n if (isHeaderInModal) {\n return (\n <ScreenStack style={styles.container}>\n <Screen enabled style={StyleSheet.absoluteFill}>\n <HeaderConfig\n {...options}\n route={route}\n headerHeight={headerHeight}\n headerTopInsetEnabled={headerTopInsetEnabled}\n canGoBack\n />\n {content}\n </Screen>\n </ScreenStack>\n );\n }\n\n return content;\n};\n\ntype SceneViewProps = {\n index: number;\n descriptor: NativeStackDescriptor;\n previousDescriptor?: NativeStackDescriptor;\n nextDescriptor?: NativeStackDescriptor;\n onWillDisappear: () => void;\n onAppear: () => void;\n onDisappear: () => void;\n onDismissed: ScreenProps['onDismissed'];\n onHeaderBackButtonClicked: ScreenProps['onHeaderBackButtonClicked'];\n onNativeDismissCancelled: ScreenProps['onDismissed'];\n};\n\nconst SceneView = ({\n descriptor,\n previousDescriptor,\n nextDescriptor,\n index,\n onWillDisappear,\n onAppear,\n onDisappear,\n onDismissed,\n onHeaderBackButtonClicked,\n onNativeDismissCancelled,\n}: SceneViewProps) => {\n const { route, navigation, options, render } = descriptor;\n const {\n animationDuration,\n animationTypeForReplace = 'push',\n gestureEnabled,\n header,\n headerBackButtonMenuEnabled,\n headerShown,\n autoHideHomeIndicator,\n navigationBarColor,\n navigationBarHidden,\n orientation,\n statusBarAnimation,\n statusBarHidden,\n statusBarStyle,\n statusBarTranslucent,\n statusBarColor,\n freezeOnBlur,\n } = options;\n\n let {\n animation,\n customAnimationOnGesture,\n fullScreenGestureEnabled,\n presentation = 'card',\n gestureDirection = presentation === 'card' ? 'horizontal' : 'vertical',\n } = options;\n\n if (gestureDirection === 'vertical' && Platform.OS === 'ios') {\n // for `vertical` direction to work, we need to set `fullScreenGestureEnabled` to `true`\n // so the screen can be dismissed from any point on screen.\n // `customAnimationOnGesture` needs to be set to `true` so the `animation` set by user can be used,\n // otherwise `simple_push` will be used.\n // Also, the default animation for this direction seems to be `slide_from_bottom`.\n if (fullScreenGestureEnabled === undefined) {\n fullScreenGestureEnabled = true;\n }\n if (customAnimationOnGesture === undefined) {\n customAnimationOnGesture = true;\n }\n if (animation === undefined) {\n animation = 'slide_from_bottom';\n }\n }\n\n // workaround for rn-screens where gestureDirection has to be set on both\n // current and previous screen - software-mansion/react-native-screens/pull/1509\n const nextGestureDirection = nextDescriptor?.options.gestureDirection;\n const gestureDirectionOverride =\n nextGestureDirection != null ? nextGestureDirection : gestureDirection;\n\n if (index === 0) {\n // first screen should always be treated as `card`, it resolves problems with no header animation\n // for navigator with first screen as `modal` and the next as `card`\n presentation = 'card';\n }\n\n const insets = useSafeAreaInsets();\n const frame = useSafeAreaFrame();\n\n // `modal` and `formSheet` presentations do not take whole screen, so should not take the inset.\n const isModal = presentation === 'modal' || presentation === 'formSheet';\n\n // Modals are fullscreen in landscape only on iPhone\n const isIPhone =\n Platform.OS === 'ios' && !(Platform.isPad || Platform.isTVOS);\n const isLandscape = frame.width > frame.height;\n\n const isParentHeaderShown = React.useContext(HeaderShownContext);\n const parentHeaderHeight = React.useContext(HeaderHeightContext);\n const parentHeaderBack = React.useContext(HeaderBackContext);\n\n const topInset =\n isParentHeaderShown ||\n (Platform.OS === 'ios' && isModal) ||\n (isIPhone && isLandscape)\n ? 0\n : insets.top;\n\n const { preventedRoutes } = usePreventRemoveContext();\n\n const defaultHeaderHeight = getDefaultHeaderHeight(frame, isModal, topInset);\n\n const [customHeaderHeight, setCustomHeaderHeight] =\n React.useState(defaultHeaderHeight);\n\n const headerTopInsetEnabled = topInset !== 0;\n const headerHeight = header ? customHeaderHeight : defaultHeaderHeight;\n const headerBack = previousDescriptor\n ? {\n title: getHeaderTitle(\n previousDescriptor.options,\n previousDescriptor.route.name\n ),\n }\n : parentHeaderBack;\n\n const isRemovePrevented = preventedRoutes[route.key]?.preventRemove;\n\n return (\n <Screen\n key={route.key}\n enabled\n style={StyleSheet.absoluteFill}\n customAnimationOnSwipe={customAnimationOnGesture}\n fullScreenSwipeEnabled={fullScreenGestureEnabled}\n gestureEnabled={\n isAndroid\n ? // This prop enables handling of system back gestures on Android\n // Since we handle them in JS side, we disable this\n false\n : gestureEnabled\n }\n homeIndicatorHidden={autoHideHomeIndicator}\n navigationBarColor={navigationBarColor}\n navigationBarHidden={navigationBarHidden}\n replaceAnimation={animationTypeForReplace}\n stackPresentation={presentation === 'card' ? 'push' : presentation}\n stackAnimation={animation}\n screenOrientation={orientation}\n statusBarAnimation={statusBarAnimation}\n statusBarHidden={statusBarHidden}\n statusBarStyle={statusBarStyle}\n statusBarColor={statusBarColor}\n statusBarTranslucent={statusBarTranslucent}\n swipeDirection={gestureDirectionOverride}\n transitionDuration={animationDuration}\n onWillDisappear={onWillDisappear}\n onAppear={onAppear}\n onDisappear={onDisappear}\n onDismissed={onDismissed}\n isNativeStack\n nativeBackButtonDismissalEnabled={false} // on Android\n onHeaderBackButtonClicked={onHeaderBackButtonClicked}\n // @ts-ignore props not exported from rn-screens\n preventNativeDismiss={isRemovePrevented} // on iOS\n onNativeDismissCancelled={onNativeDismissCancelled}\n // this prop is available since rn-screens 3.16\n freezeOnBlur={freezeOnBlur}\n >\n <NavigationContext.Provider value={navigation}>\n <NavigationRouteContext.Provider value={route}>\n <HeaderShownContext.Provider\n value={isParentHeaderShown || headerShown !== false}\n >\n <HeaderHeightContext.Provider\n value={\n headerShown !== false ? headerHeight : parentHeaderHeight ?? 0\n }\n >\n {header !== undefined && headerShown !== false ? (\n <View\n onLayout={(e) => {\n setCustomHeaderHeight(e.nativeEvent.layout.height);\n }}\n >\n {header({\n back: headerBack,\n options,\n route,\n navigation,\n })}\n </View>\n ) : (\n <HeaderConfig\n {...options}\n route={route}\n headerBackButtonMenuEnabled={\n isRemovePrevented !== undefined\n ? !isRemovePrevented\n : headerBackButtonMenuEnabled\n }\n headerShown={headerShown}\n headerHeight={headerHeight}\n headerBackTitle={\n options.headerBackTitle !== undefined\n ? options.headerBackTitle\n : undefined\n }\n headerTopInsetEnabled={headerTopInsetEnabled}\n canGoBack={headerBack !== undefined}\n />\n )}\n <MaybeNestedStack\n options={options}\n route={route}\n presentation={presentation}\n headerHeight={headerHeight}\n headerTopInsetEnabled={headerTopInsetEnabled}\n >\n <HeaderBackContext.Provider value={headerBack}>\n {render()}\n </HeaderBackContext.Provider>\n </MaybeNestedStack>\n </HeaderHeightContext.Provider>\n </HeaderShownContext.Provider>\n </NavigationRouteContext.Provider>\n </NavigationContext.Provider>\n </Screen>\n );\n};\n\ntype Props = {\n state: StackNavigationState<ParamListBase>;\n navigation: NativeStackNavigationHelpers;\n descriptors: NativeStackDescriptorMap;\n};\n\nfunction NativeStackViewInner({ state, navigation, descriptors }: Props) {\n const { setNextDismissedKey } = useDismissedRouteError(state);\n\n useInvalidPreventRemoveError(descriptors);\n\n return (\n <ScreenStack style={styles.container}>\n {state.routes.map((route, index) => {\n const descriptor = descriptors[route.key];\n const previousKey = state.routes[index - 1]?.key;\n const nextKey = state.routes[index + 1]?.key;\n const previousDescriptor = previousKey\n ? descriptors[previousKey]\n : undefined;\n const nextDescriptor = nextKey ? descriptors[nextKey] : undefined;\n\n return (\n <SceneView\n key={route.key}\n index={index}\n descriptor={descriptor}\n previousDescriptor={previousDescriptor}\n nextDescriptor={nextDescriptor}\n onWillDisappear={() => {\n navigation.emit({\n type: 'transitionStart',\n data: { closing: true },\n target: route.key,\n });\n }}\n onAppear={() => {\n navigation.emit({\n type: 'transitionEnd',\n data: { closing: false },\n target: route.key,\n });\n }}\n onDisappear={() => {\n navigation.emit({\n type: 'transitionEnd',\n data: { closing: true },\n target: route.key,\n });\n }}\n onDismissed={(event) => {\n navigation.dispatch({\n ...StackActions.pop(event.nativeEvent.dismissCount),\n source: route.key,\n target: state.key,\n });\n\n setNextDismissedKey(route.key);\n }}\n onHeaderBackButtonClicked={() => {\n navigation.dispatch({\n ...StackActions.pop(),\n source: route.key,\n target: state.key,\n });\n }}\n onNativeDismissCancelled={(event) => {\n navigation.dispatch({\n ...StackActions.pop(event.nativeEvent.dismissCount),\n source: route.key,\n target: state.key,\n });\n }}\n />\n );\n })}\n </ScreenStack>\n );\n}\n\nexport default function NativeStackView(props: Props) {\n return (\n <SafeAreaProviderCompat>\n <NativeStackViewInner {...props} />\n </SafeAreaProviderCompat>\n );\n}\n\nconst styles = StyleSheet.create({\n container: {\n flex: 1,\n },\n});\n"]}
@@ -442,6 +442,14 @@ export declare type NativeStackNavigationOptions = {
442
442
  * Only supported on iOS and Android.
443
443
  */
444
444
  orientation?: ScreenProps['screenOrientation'];
445
+ /**
446
+ * Whether inactive screens should be suspended from re-rendering. Defaults to `false`.
447
+ * Defaults to `true` when `enableFreeze()` is run at the top of the application.
448
+ * Requires `react-native-screens` version >=3.16.0.
449
+ *
450
+ * Only supported on iOS and Android.
451
+ */
452
+ freezeOnBlur?: boolean;
445
453
  };
446
454
  export declare type NativeStackNavigatorProps = DefaultNavigatorOptions<ParamListBase, StackNavigationState<ParamListBase>, NativeStackNavigationOptions, NativeStackNavigationEventMap> & StackRouterOptions & NativeStackNavigationConfig;
447
455
  export declare type NativeStackDescriptor = Descriptor<NativeStackNavigationOptions, NativeStackNavigationProp<ParamListBase>, RouteProp<ParamListBase>>;
@@ -0,0 +1,5 @@
1
+ import type { ParamListBase, StackNavigationState } from '@react-navigation/native';
2
+ import * as React from 'react';
3
+ export default function useInvalidPreventRemoveError(state: StackNavigationState<ParamListBase>): {
4
+ setNextDismissedKey: React.Dispatch<React.SetStateAction<string | null>>;
5
+ };
@@ -0,0 +1,2 @@
1
+ import type { NativeStackDescriptorMap } from '../types';
2
+ export default function useInvalidPreventRemoveError(descriptors: NativeStackDescriptorMap): void;
@@ -2,9 +2,10 @@
2
2
  import { Route } from '@react-navigation/native';
3
3
  import type { NativeStackNavigationOptions } from '../types';
4
4
  declare type Props = NativeStackNavigationOptions & {
5
+ headerTopInsetEnabled: boolean;
5
6
  headerHeight: number;
6
7
  route: Route<string>;
7
8
  canGoBack: boolean;
8
9
  };
9
- export default function HeaderConfig({ headerHeight, headerBackImageSource, headerBackButtonMenuEnabled, headerBackTitle, headerBackTitleStyle, headerBackTitleVisible, headerBackVisible, headerShadowVisible, headerLargeStyle, headerLargeTitle, headerLargeTitleShadowVisible, headerLargeTitleStyle, headerBackground, headerLeft, headerRight, headerShown, headerStyle, headerBlurEffect, headerTintColor, headerTitle, headerTitleAlign, headerTitleStyle, headerTransparent, headerSearchBarOptions, route, title, canGoBack, }: Props): JSX.Element;
10
+ export default function HeaderConfig({ headerHeight, headerBackImageSource, headerBackButtonMenuEnabled, headerBackTitle, headerBackTitleStyle, headerBackTitleVisible, headerBackVisible, headerShadowVisible, headerLargeStyle, headerLargeTitle, headerLargeTitleShadowVisible, headerLargeTitleStyle, headerBackground, headerLeft, headerRight, headerShown, headerStyle, headerBlurEffect, headerTintColor, headerTitle, headerTitleAlign, headerTitleStyle, headerTransparent, headerSearchBarOptions, headerTopInsetEnabled, route, title, canGoBack, }: Props): JSX.Element;
10
11
  export {};
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@react-navigation/native-stack",
3
3
  "description": "Native stack navigator using react-native-screens",
4
- "version": "6.7.0",
4
+ "version": "6.9.0",
5
5
  "keywords": [
6
6
  "react-native-component",
7
7
  "react-component",
@@ -37,20 +37,21 @@
37
37
  "access": "public"
38
38
  },
39
39
  "scripts": {
40
- "prepare": "bob build",
40
+ "prepack": "bob build",
41
41
  "clean": "del lib"
42
42
  },
43
43
  "dependencies": {
44
- "@react-navigation/elements": "^1.3.4",
44
+ "@react-navigation/elements": "^1.3.6",
45
45
  "warn-once": "^0.1.0"
46
46
  },
47
47
  "devDependencies": {
48
- "@react-navigation/native": "^6.0.11",
48
+ "@react-navigation/native": "^6.0.13",
49
49
  "@testing-library/react-native": "^7.2.0",
50
- "@types/react": "^17.0.47",
51
- "@types/react-native": "~0.68.1",
52
- "react": "17.0.2",
53
- "react-native": "~0.68.2",
50
+ "@types/react": "~18.0.0",
51
+ "@types/react-native": "~0.69.1",
52
+ "del-cli": "^3.0.1",
53
+ "react": "18.0.0",
54
+ "react-native": "0.69.5",
54
55
  "react-native-builder-bob": "^0.18.1",
55
56
  "react-native-screens": "^3.11.1",
56
57
  "typescript": "^4.7.4"
@@ -75,5 +76,6 @@
75
76
  }
76
77
  ]
77
78
  ]
78
- }
79
+ },
80
+ "gitHead": "fc4c3a63ab156e17db7ba0cbd32ada319f78714e"
79
81
  }
package/src/types.tsx CHANGED
@@ -486,6 +486,14 @@ export type NativeStackNavigationOptions = {
486
486
  * Only supported on iOS and Android.
487
487
  */
488
488
  orientation?: ScreenProps['screenOrientation'];
489
+ /**
490
+ * Whether inactive screens should be suspended from re-rendering. Defaults to `false`.
491
+ * Defaults to `true` when `enableFreeze()` is run at the top of the application.
492
+ * Requires `react-native-screens` version >=3.16.0.
493
+ *
494
+ * Only supported on iOS and Android.
495
+ */
496
+ freezeOnBlur?: boolean;
489
497
  };
490
498
 
491
499
  export type NativeStackNavigatorProps = DefaultNavigatorOptions<
@@ -0,0 +1,30 @@
1
+ import type {
2
+ ParamListBase,
3
+ StackNavigationState,
4
+ } from '@react-navigation/native';
5
+ import * as React from 'react';
6
+
7
+ export default function useInvalidPreventRemoveError(
8
+ state: StackNavigationState<ParamListBase>
9
+ ) {
10
+ const [nextDismissedKey, setNextDismissedKey] = React.useState<string | null>(
11
+ null
12
+ );
13
+
14
+ const dismissedRouteName = nextDismissedKey
15
+ ? state.routes.find((route) => route.key === nextDismissedKey)?.name
16
+ : null;
17
+
18
+ React.useEffect(() => {
19
+ if (dismissedRouteName) {
20
+ const message =
21
+ `The screen '${dismissedRouteName}' was removed natively but didn't get removed from JS state. ` +
22
+ `This can happen if the action was prevented in a 'beforeRemove' listener, which is not fully supported in native-stack.\n\n` +
23
+ `Consider using a 'usePreventRemove' hook with 'headerBackButtonMenuEnabled: false' to prevent users from natively going back multiple screens.`;
24
+
25
+ console.error(message);
26
+ }
27
+ }, [dismissedRouteName]);
28
+
29
+ return { setNextDismissedKey };
30
+ }
@@ -0,0 +1,31 @@
1
+ import { usePreventRemoveContext } from '@react-navigation/native';
2
+ import * as React from 'react';
3
+
4
+ import type { NativeStackDescriptorMap } from '../types';
5
+
6
+ export default function useInvalidPreventRemoveError(
7
+ descriptors: NativeStackDescriptorMap
8
+ ) {
9
+ const { preventedRoutes } = usePreventRemoveContext();
10
+ const preventedRouteKey = Object.keys(preventedRoutes)[0];
11
+ const preventedDescriptor = descriptors[preventedRouteKey];
12
+ const isHeaderBackButtonMenuEnabledOnPreventedScreen =
13
+ preventedDescriptor?.options?.headerBackButtonMenuEnabled;
14
+ const preventedRouteName = preventedDescriptor?.route?.name;
15
+
16
+ React.useEffect(() => {
17
+ if (
18
+ preventedRouteKey != null &&
19
+ isHeaderBackButtonMenuEnabledOnPreventedScreen
20
+ ) {
21
+ const message =
22
+ `The screen ${preventedRouteName} uses 'usePreventRemove' hook alongside 'headerBackButtonMenuEnabled: true', which is not supported. \n\n` +
23
+ `Consider removing 'headerBackButtonMenuEnabled: true' from ${preventedRouteName} screen to get rid of this error.`;
24
+ console.error(message);
25
+ }
26
+ }, [
27
+ preventedRouteKey,
28
+ isHeaderBackButtonMenuEnabledOnPreventedScreen,
29
+ preventedRouteName,
30
+ ]);
31
+ }
@@ -8,7 +8,6 @@ import {
8
8
  TextStyle,
9
9
  View,
10
10
  } from 'react-native';
11
- import { useSafeAreaInsets } from 'react-native-safe-area-context';
12
11
  import {
13
12
  isSearchBarAvailableForCurrentPlatform,
14
13
  ScreenStackHeaderBackButtonImage,
@@ -24,6 +23,7 @@ import type { NativeStackNavigationOptions } from '../types';
24
23
  import { processFonts } from './FontProcessor';
25
24
 
26
25
  type Props = NativeStackNavigationOptions & {
26
+ headerTopInsetEnabled: boolean;
27
27
  headerHeight: number;
28
28
  route: Route<string>;
29
29
  canGoBack: boolean;
@@ -54,12 +54,11 @@ export default function HeaderConfig({
54
54
  headerTitleStyle,
55
55
  headerTransparent,
56
56
  headerSearchBarOptions,
57
+ headerTopInsetEnabled,
57
58
  route,
58
59
  title,
59
60
  canGoBack,
60
61
  }: Props): JSX.Element {
61
- const insets = useSafeAreaInsets();
62
-
63
62
  const { colors } = useTheme();
64
63
  const tintColor =
65
64
  headerTintColor ?? (Platform.OS === 'ios' ? colors.primary : colors.text);
@@ -174,7 +173,7 @@ export default function HeaderConfig({
174
173
  backTitleFontSize={headerBackTitleStyleFlattened.fontSize}
175
174
  blurEffect={headerBlurEffect}
176
175
  color={tintColor}
177
- direction={I18nManager.isRTL ? 'rtl' : 'ltr'}
176
+ direction={I18nManager.getConstants().isRTL ? 'rtl' : 'ltr'}
178
177
  disableBackButtonMenu={headerBackButtonMenuEnabled === false}
179
178
  hidden={headerShown === false}
180
179
  hideBackButton={headerBackVisible === false}
@@ -195,7 +194,7 @@ export default function HeaderConfig({
195
194
  titleFontFamily={titleFontFamily}
196
195
  titleFontSize={titleFontSize}
197
196
  titleFontWeight={titleFontWeight}
198
- topInsetEnabled={insets.top !== 0}
197
+ topInsetEnabled={headerTopInsetEnabled}
199
198
  translucent={
200
199
  // This defaults to `true`, so we can't pass `undefined`
201
200
  translucent === true
@@ -1,6 +1,7 @@
1
1
  import {
2
2
  getDefaultHeaderHeight,
3
3
  getHeaderTitle,
4
+ HeaderBackContext,
4
5
  HeaderHeightContext,
5
6
  HeaderShownContext,
6
7
  SafeAreaProviderCompat,
@@ -12,6 +13,7 @@ import {
12
13
  Route,
13
14
  StackActions,
14
15
  StackNavigationState,
16
+ usePreventRemoveContext,
15
17
  useTheme,
16
18
  } from '@react-navigation/native';
17
19
  import * as React from 'react';
@@ -34,6 +36,8 @@ import type {
34
36
  NativeStackNavigationHelpers,
35
37
  NativeStackNavigationOptions,
36
38
  } from '../types';
39
+ import useDismissedRouteError from '../utils/useDismissedRouteError';
40
+ import useInvalidPreventRemoveError from '../utils/useInvalidPreventRemoveError';
37
41
  import DebugContainer from './DebugContainer';
38
42
  import HeaderConfig from './HeaderConfig';
39
43
 
@@ -44,12 +48,14 @@ const MaybeNestedStack = ({
44
48
  route,
45
49
  presentation,
46
50
  headerHeight,
51
+ headerTopInsetEnabled,
47
52
  children,
48
53
  }: {
49
54
  options: NativeStackNavigationOptions;
50
55
  route: Route<string>;
51
56
  presentation: Exclude<StackPresentationTypes, 'push'> | 'card';
52
57
  headerHeight: number;
58
+ headerTopInsetEnabled: boolean;
53
59
  children: React.ReactNode;
54
60
  }) => {
55
61
  const { colors } = useTheme();
@@ -96,6 +102,7 @@ const MaybeNestedStack = ({
96
102
  {...options}
97
103
  route={route}
98
104
  headerHeight={headerHeight}
105
+ headerTopInsetEnabled={headerTopInsetEnabled}
99
106
  canGoBack
100
107
  />
101
108
  {content}
@@ -116,6 +123,8 @@ type SceneViewProps = {
116
123
  onAppear: () => void;
117
124
  onDisappear: () => void;
118
125
  onDismissed: ScreenProps['onDismissed'];
126
+ onHeaderBackButtonClicked: ScreenProps['onHeaderBackButtonClicked'];
127
+ onNativeDismissCancelled: ScreenProps['onDismissed'];
119
128
  };
120
129
 
121
130
  const SceneView = ({
@@ -127,6 +136,8 @@ const SceneView = ({
127
136
  onAppear,
128
137
  onDisappear,
129
138
  onDismissed,
139
+ onHeaderBackButtonClicked,
140
+ onNativeDismissCancelled,
130
141
  }: SceneViewProps) => {
131
142
  const { route, navigation, options, render } = descriptor;
132
143
  const {
@@ -134,6 +145,7 @@ const SceneView = ({
134
145
  animationTypeForReplace = 'push',
135
146
  gestureEnabled,
136
147
  header,
148
+ headerBackButtonMenuEnabled,
137
149
  headerShown,
138
150
  autoHideHomeIndicator,
139
151
  navigationBarColor,
@@ -144,6 +156,7 @@ const SceneView = ({
144
156
  statusBarStyle,
145
157
  statusBarTranslucent,
146
158
  statusBarColor,
159
+ freezeOnBlur,
147
160
  } = options;
148
161
 
149
162
  let {
@@ -183,10 +196,6 @@ const SceneView = ({
183
196
  presentation = 'card';
184
197
  }
185
198
 
186
- const isHeaderInPush = isAndroid
187
- ? headerShown
188
- : presentation === 'card' && headerShown !== false;
189
-
190
199
  const insets = useSafeAreaInsets();
191
200
  const frame = useSafeAreaFrame();
192
201
 
@@ -198,17 +207,36 @@ const SceneView = ({
198
207
  Platform.OS === 'ios' && !(Platform.isPad || Platform.isTVOS);
199
208
  const isLandscape = frame.width > frame.height;
200
209
 
201
- const topInset = isModal || (isIPhone && isLandscape) ? 0 : insets.top;
202
-
203
210
  const isParentHeaderShown = React.useContext(HeaderShownContext);
204
211
  const parentHeaderHeight = React.useContext(HeaderHeightContext);
212
+ const parentHeaderBack = React.useContext(HeaderBackContext);
213
+
214
+ const topInset =
215
+ isParentHeaderShown ||
216
+ (Platform.OS === 'ios' && isModal) ||
217
+ (isIPhone && isLandscape)
218
+ ? 0
219
+ : insets.top;
220
+
221
+ const { preventedRoutes } = usePreventRemoveContext();
205
222
 
206
223
  const defaultHeaderHeight = getDefaultHeaderHeight(frame, isModal, topInset);
207
224
 
208
225
  const [customHeaderHeight, setCustomHeaderHeight] =
209
226
  React.useState(defaultHeaderHeight);
210
227
 
228
+ const headerTopInsetEnabled = topInset !== 0;
211
229
  const headerHeight = header ? customHeaderHeight : defaultHeaderHeight;
230
+ const headerBack = previousDescriptor
231
+ ? {
232
+ title: getHeaderTitle(
233
+ previousDescriptor.options,
234
+ previousDescriptor.route.name
235
+ ),
236
+ }
237
+ : parentHeaderBack;
238
+
239
+ const isRemovePrevented = preventedRoutes[route.key]?.preventRemove;
212
240
 
213
241
  return (
214
242
  <Screen
@@ -243,17 +271,22 @@ const SceneView = ({
243
271
  onDisappear={onDisappear}
244
272
  onDismissed={onDismissed}
245
273
  isNativeStack
274
+ nativeBackButtonDismissalEnabled={false} // on Android
275
+ onHeaderBackButtonClicked={onHeaderBackButtonClicked}
276
+ // @ts-ignore props not exported from rn-screens
277
+ preventNativeDismiss={isRemovePrevented} // on iOS
278
+ onNativeDismissCancelled={onNativeDismissCancelled}
279
+ // this prop is available since rn-screens 3.16
280
+ freezeOnBlur={freezeOnBlur}
246
281
  >
247
282
  <NavigationContext.Provider value={navigation}>
248
283
  <NavigationRouteContext.Provider value={route}>
249
284
  <HeaderShownContext.Provider
250
- value={isParentHeaderShown || isHeaderInPush !== false}
285
+ value={isParentHeaderShown || headerShown !== false}
251
286
  >
252
287
  <HeaderHeightContext.Provider
253
288
  value={
254
- isHeaderInPush !== false
255
- ? headerHeight
256
- : parentHeaderHeight ?? 0
289
+ headerShown !== false ? headerHeight : parentHeaderHeight ?? 0
257
290
  }
258
291
  >
259
292
  {header !== undefined && headerShown !== false ? (
@@ -263,14 +296,7 @@ const SceneView = ({
263
296
  }}
264
297
  >
265
298
  {header({
266
- back: previousDescriptor
267
- ? {
268
- title: getHeaderTitle(
269
- previousDescriptor.options,
270
- previousDescriptor.route.name
271
- ),
272
- }
273
- : undefined,
299
+ back: headerBack,
274
300
  options,
275
301
  route,
276
302
  navigation,
@@ -280,9 +306,20 @@ const SceneView = ({
280
306
  <HeaderConfig
281
307
  {...options}
282
308
  route={route}
283
- headerShown={isHeaderInPush}
309
+ headerBackButtonMenuEnabled={
310
+ isRemovePrevented !== undefined
311
+ ? !isRemovePrevented
312
+ : headerBackButtonMenuEnabled
313
+ }
314
+ headerShown={headerShown}
284
315
  headerHeight={headerHeight}
285
- canGoBack={index !== 0}
316
+ headerBackTitle={
317
+ options.headerBackTitle !== undefined
318
+ ? options.headerBackTitle
319
+ : undefined
320
+ }
321
+ headerTopInsetEnabled={headerTopInsetEnabled}
322
+ canGoBack={headerBack !== undefined}
286
323
  />
287
324
  )}
288
325
  <MaybeNestedStack
@@ -290,8 +327,11 @@ const SceneView = ({
290
327
  route={route}
291
328
  presentation={presentation}
292
329
  headerHeight={headerHeight}
330
+ headerTopInsetEnabled={headerTopInsetEnabled}
293
331
  >
294
- {render()}
332
+ <HeaderBackContext.Provider value={headerBack}>
333
+ {render()}
334
+ </HeaderBackContext.Provider>
295
335
  </MaybeNestedStack>
296
336
  </HeaderHeightContext.Provider>
297
337
  </HeaderShownContext.Provider>
@@ -308,24 +348,9 @@ type Props = {
308
348
  };
309
349
 
310
350
  function NativeStackViewInner({ state, navigation, descriptors }: Props) {
311
- const [nextDismissedKey, setNextDismissedKey] = React.useState<string | null>(
312
- null
313
- );
314
-
315
- const dismissedRouteName = nextDismissedKey
316
- ? state.routes.find((route) => route.key === nextDismissedKey)?.name
317
- : null;
351
+ const { setNextDismissedKey } = useDismissedRouteError(state);
318
352
 
319
- React.useEffect(() => {
320
- if (dismissedRouteName) {
321
- const message =
322
- `The screen '${dismissedRouteName}' was removed natively but didn't get removed from JS state. ` +
323
- `This can happen if the action was prevented in a 'beforeRemove' listener, which is not fully supported in native-stack.\n\n` +
324
- `Consider using 'gestureEnabled: false' to prevent back gesture and use a custom back button with 'headerLeft' option to override the native behavior.`;
325
-
326
- console.error(message);
327
- }
328
- }, [dismissedRouteName]);
353
+ useInvalidPreventRemoveError(descriptors);
329
354
 
330
355
  return (
331
356
  <ScreenStack style={styles.container}>
@@ -375,6 +400,20 @@ function NativeStackViewInner({ state, navigation, descriptors }: Props) {
375
400
 
376
401
  setNextDismissedKey(route.key);
377
402
  }}
403
+ onHeaderBackButtonClicked={() => {
404
+ navigation.dispatch({
405
+ ...StackActions.pop(),
406
+ source: route.key,
407
+ target: state.key,
408
+ });
409
+ }}
410
+ onNativeDismissCancelled={(event) => {
411
+ navigation.dispatch({
412
+ ...StackActions.pop(event.nativeEvent.dismissCount),
413
+ source: route.key,
414
+ target: state.key,
415
+ });
416
+ }}
378
417
  />
379
418
  );
380
419
  })}
@@ -2,6 +2,7 @@ import {
2
2
  getHeaderTitle,
3
3
  Header,
4
4
  HeaderBackButton,
5
+ HeaderBackContext,
5
6
  SafeAreaProviderCompat,
6
7
  Screen,
7
8
  } from '@react-navigation/elements';
@@ -31,12 +32,13 @@ const TRANSPARENT_PRESENTATIONS = [
31
32
  ];
32
33
 
33
34
  export default function NativeStackView({ state, descriptors }: Props) {
35
+ const parentHeaderBack = React.useContext(HeaderBackContext);
36
+
34
37
  return (
35
38
  <SafeAreaProviderCompat>
36
39
  <View style={styles.container}>
37
40
  {state.routes.map((route, i) => {
38
41
  const isFocused = state.index === i;
39
- const canGoBack = i !== 0;
40
42
  const previousKey = state.routes[i - 1]?.key;
41
43
  const nextKey = state.routes[i + 1]?.key;
42
44
  const previousDescriptor = previousKey
@@ -45,6 +47,17 @@ export default function NativeStackView({ state, descriptors }: Props) {
45
47
  const nextDescriptor = nextKey ? descriptors[nextKey] : undefined;
46
48
  const { options, navigation, render } = descriptors[route.key];
47
49
 
50
+ const headerBack = previousDescriptor
51
+ ? {
52
+ title: getHeaderTitle(
53
+ previousDescriptor.options,
54
+ previousDescriptor.route.name
55
+ ),
56
+ }
57
+ : parentHeaderBack;
58
+
59
+ const canGoBack = headerBack !== undefined;
60
+
48
61
  const {
49
62
  header,
50
63
  headerShown,
@@ -77,14 +90,7 @@ export default function NativeStackView({ state, descriptors }: Props) {
77
90
  header={
78
91
  header !== undefined ? (
79
92
  header({
80
- back: previousDescriptor
81
- ? {
82
- title: getHeaderTitle(
83
- previousDescriptor.options,
84
- previousDescriptor.route.name
85
- ),
86
- }
87
- : undefined,
93
+ back: headerBack,
88
94
  options,
89
95
  route,
90
96
  navigation,
@@ -161,9 +167,11 @@ export default function NativeStackView({ state, descriptors }: Props) {
161
167
  : null,
162
168
  ]}
163
169
  >
164
- <View style={[styles.contentContainer, contentStyle]}>
165
- {render()}
166
- </View>
170
+ <HeaderBackContext.Provider value={headerBack}>
171
+ <View style={[styles.contentContainer, contentStyle]}>
172
+ {render()}
173
+ </View>
174
+ </HeaderBackContext.Provider>
167
175
  </Screen>
168
176
  );
169
177
  })}