upgrade createNativeStackNavigatorWithAuth with new internals
This commit is contained in:
@@ -1,25 +1,29 @@
|
|||||||
import * as React from 'react'
|
import * as React from 'react'
|
||||||
import {View} from 'react-native'
|
import {View} from 'react-native'
|
||||||
// Based on @react-navigation/native-stack/src/createNativeStackNavigator.ts
|
// Based on @react-navigation/native-stack/src/navigators/createNativeStackNavigator.ts
|
||||||
// MIT License
|
// MIT License
|
||||||
// Copyright (c) 2017 React Navigation Contributors
|
// Copyright (c) 2017 React Navigation Contributors
|
||||||
import {
|
import {
|
||||||
createNavigatorFactory,
|
createNavigatorFactory,
|
||||||
type EventArg,
|
type EventArg,
|
||||||
|
type NavigatorTypeBagBase,
|
||||||
type ParamListBase,
|
type ParamListBase,
|
||||||
type StackActionHelpers,
|
type StackActionHelpers,
|
||||||
StackActions,
|
StackActions,
|
||||||
type StackNavigationState,
|
type StackNavigationState,
|
||||||
StackRouter,
|
StackRouter,
|
||||||
type StackRouterOptions,
|
type StackRouterOptions,
|
||||||
|
type StaticConfig,
|
||||||
|
type TypedNavigator,
|
||||||
useNavigationBuilder,
|
useNavigationBuilder,
|
||||||
} from '@react-navigation/native'
|
} from '@react-navigation/native'
|
||||||
|
import {NativeStackView} from '@react-navigation/native-stack'
|
||||||
import {
|
import {
|
||||||
type NativeStackNavigationEventMap,
|
type NativeStackNavigationEventMap,
|
||||||
type NativeStackNavigationOptions,
|
type NativeStackNavigationOptions,
|
||||||
|
type NativeStackNavigationProp,
|
||||||
|
type NativeStackNavigatorProps,
|
||||||
} from '@react-navigation/native-stack'
|
} from '@react-navigation/native-stack'
|
||||||
import {NativeStackView} from '@react-navigation/native-stack'
|
|
||||||
import {type NativeStackNavigatorProps} from '@react-navigation/native-stack/src/types'
|
|
||||||
|
|
||||||
import {PWI_ENABLED} from '#/lib/build-flags'
|
import {PWI_ENABLED} from '#/lib/build-flags'
|
||||||
import {useWebMediaQueries} from '#/lib/hooks/useWebMediaQueries'
|
import {useWebMediaQueries} from '#/lib/hooks/useWebMediaQueries'
|
||||||
@@ -48,12 +52,14 @@ function NativeStackNavigator({
|
|||||||
id,
|
id,
|
||||||
initialRouteName,
|
initialRouteName,
|
||||||
children,
|
children,
|
||||||
|
layout,
|
||||||
screenListeners,
|
screenListeners,
|
||||||
screenOptions,
|
screenOptions,
|
||||||
|
screenLayout,
|
||||||
...rest
|
...rest
|
||||||
}: NativeStackNavigatorProps) {
|
}: NativeStackNavigatorProps) {
|
||||||
// --- this is copy and pasted from the original native stack navigator ---
|
// --- this is copy and pasted from the original native stack navigator ---
|
||||||
const {state, descriptors, navigation, NavigationContent} =
|
const {state, describe, descriptors, navigation, NavigationContent} =
|
||||||
useNavigationBuilder<
|
useNavigationBuilder<
|
||||||
StackNavigationState<ParamListBase>,
|
StackNavigationState<ParamListBase>,
|
||||||
StackRouterOptions,
|
StackRouterOptions,
|
||||||
@@ -64,9 +70,12 @@ function NativeStackNavigator({
|
|||||||
id,
|
id,
|
||||||
initialRouteName,
|
initialRouteName,
|
||||||
children,
|
children,
|
||||||
|
layout,
|
||||||
screenListeners,
|
screenListeners,
|
||||||
screenOptions,
|
screenOptions,
|
||||||
|
screenLayout,
|
||||||
})
|
})
|
||||||
|
|
||||||
React.useEffect(
|
React.useEffect(
|
||||||
() =>
|
() =>
|
||||||
// @ts-expect-error: there may not be a tab navigator in parent
|
// @ts-expect-error: there may not be a tab navigator in parent
|
||||||
@@ -148,7 +157,8 @@ function NativeStackNavigator({
|
|||||||
{...rest}
|
{...rest}
|
||||||
state={state}
|
state={state}
|
||||||
navigation={navigation}
|
navigation={navigation}
|
||||||
descriptors={newDescriptors}
|
descriptors={descriptors}
|
||||||
|
describe={describe}
|
||||||
/>
|
/>
|
||||||
</View>
|
</View>
|
||||||
{isWeb && (
|
{isWeb && (
|
||||||
@@ -161,9 +171,25 @@ function NativeStackNavigator({
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
export const createNativeStackNavigatorWithAuth = createNavigatorFactory<
|
export function createNativeStackNavigatorWithAuth<
|
||||||
StackNavigationState<ParamListBase>,
|
const ParamList extends ParamListBase,
|
||||||
NativeStackNavigationOptionsWithAuth,
|
const NavigatorID extends string | undefined = undefined,
|
||||||
NativeStackNavigationEventMap,
|
const TypeBag extends NavigatorTypeBagBase = {
|
||||||
typeof NativeStackNavigator
|
ParamList: ParamList
|
||||||
>(NativeStackNavigator)
|
NavigatorID: NavigatorID
|
||||||
|
State: StackNavigationState<ParamList>
|
||||||
|
ScreenOptions: NativeStackNavigationOptionsWithAuth
|
||||||
|
EventMap: NativeStackNavigationEventMap
|
||||||
|
NavigationList: {
|
||||||
|
[RouteName in keyof ParamList]: NativeStackNavigationProp<
|
||||||
|
ParamList,
|
||||||
|
RouteName,
|
||||||
|
NavigatorID
|
||||||
|
>
|
||||||
|
}
|
||||||
|
Navigator: typeof NativeStackNavigator
|
||||||
|
},
|
||||||
|
const Config extends StaticConfig<TypeBag> = StaticConfig<TypeBag>,
|
||||||
|
>(config?: Config): TypedNavigator<TypeBag, Config> {
|
||||||
|
return createNavigatorFactory(NativeStackNavigator)(config)
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user