diff --git a/example/src/Screens/NativeStack.tsx b/example/src/Screens/NativeStack.tsx index 2aa6980f..1c874d9e 100644 --- a/example/src/Screens/NativeStack.tsx +++ b/example/src/Screens/NativeStack.tsx @@ -122,7 +122,7 @@ export default function NativeStackScreen({ }, [navigation]); return ( - + = 3.0.0" + "react-native-screens": ">= 3.0.0", + "react-native-safe-area-context": ">= 3.0.0" }, "react-native-builder-bob": { "source": "src", diff --git a/packages/native-stack/src/views/NativeStackView.tsx b/packages/native-stack/src/views/NativeStackView.tsx index 45990dbf..953548e8 100644 --- a/packages/native-stack/src/views/NativeStackView.tsx +++ b/packages/native-stack/src/views/NativeStackView.tsx @@ -9,11 +9,13 @@ import { useTheme, Route, } from '@react-navigation/native'; +import { SafeAreaProviderCompat } from '@react-navigation/elements'; import { Screen, ScreenStack, StackPresentationTypes, } from 'react-native-screens'; +import { useSafeAreaInsets } from 'react-native-safe-area-context'; import warnOnce from 'warn-once'; import HeaderConfig from './HeaderConfig'; import type { @@ -114,16 +116,12 @@ type Props = { descriptors: NativeStackDescriptorMap; }; -export default function NativeStackView({ - state, - navigation, - descriptors, -}: Props): JSX.Element { - const { key, routes } = state; +function NativeStackViewInner({ state, navigation, descriptors }: Props) { + const insets = useSafeAreaInsets(); return ( - {routes.map((route, index) => { + {state.routes.map((route, index) => { const { options, render: renderScene } = descriptors[route.key]; const { gestureEnabled, @@ -191,7 +189,7 @@ export default function NativeStackView({ navigation.dispatch({ ...StackActions.pop(), source: route.key, - target: key, + target: state.key, }); }} > @@ -199,6 +197,9 @@ export default function NativeStackView({ {...options} route={route} headerShown={isHeaderInPush} + headerTopInsetEnabled={ + options.headerTopInsetEnabled ?? insets.top !== 0 + } /> + + + ); +} + const styles = StyleSheet.create({ container: { flex: 1, diff --git a/packages/native-stack/tsconfig.json b/packages/native-stack/tsconfig.json index b74421ba..d0f53214 100644 --- a/packages/native-stack/tsconfig.json +++ b/packages/native-stack/tsconfig.json @@ -3,7 +3,8 @@ "references": [ { "path": "../core" }, { "path": "../routers" }, - { "path": "../native" } + { "path": "../native" }, + { "path": "../elements" } ], "compilerOptions": { "outDir": "./lib/typescript"