|
1 | | -import { useContext } from 'react'; |
| 1 | +import { useContext, type ComponentType } from 'react'; |
2 | 2 | import { createNativeStackNavigator } from '@react-navigation/native-stack'; |
| 3 | +import { type StaticParamList, type StaticScreenProps } from '@react-navigation/native'; |
3 | 4 |
|
4 | 5 | import { ThemeContext } from '../theme'; |
5 | 6 | import { defaultHeader, themedHeader } from '../lib/methods/helpers/navigation'; |
6 | 7 | import SelectServerView from '../views/SelectServerView'; |
7 | 8 | import ShareListView from '../views/ShareListView'; |
8 | 9 | import ShareView from '../views/ShareView'; |
| 10 | +import withNavigation from '../lib/navigation/withNavigation'; |
| 11 | +import { type InsideStackParamList } from './types'; |
| 12 | +import { type Optional } from '../definitions/utils'; |
9 | 13 |
|
10 | | -const ShareExtension = createNativeStackNavigator<any>(); |
11 | | -const ShareExtensionStack = () => { |
| 14 | +type ShareViewParams = Optional<InsideStackParamList['ShareView'], 'thread' | 'action' | 'finishShareView' | 'startShareView'>; |
| 15 | + |
| 16 | +// Cast through `any` to break the navigation-prop type cycle; removing it reintroduces a real TS circular ref. |
| 17 | +const ShareListViewScreen: ComponentType<StaticScreenProps<undefined>> = withNavigation(ShareListView as any) as any; |
| 18 | +const ShareViewScreen: ComponentType<StaticScreenProps<ShareViewParams>> = withNavigation(ShareView as any) as any; |
| 19 | + |
| 20 | +const ShareExtension = createNativeStackNavigator({ |
| 21 | + screenOptions: defaultHeader, |
| 22 | + screens: { |
| 23 | + ShareListView: ShareListViewScreen, |
| 24 | + ShareView: ShareViewScreen, |
| 25 | + SelectServerView |
| 26 | + } |
| 27 | +}).with(({ Navigator }) => { |
12 | 28 | 'use memo'; |
13 | 29 |
|
14 | 30 | const { theme } = useContext(ThemeContext); |
| 31 | + return <Navigator screenOptions={themedHeader(theme)} />; |
| 32 | +}); |
| 33 | + |
| 34 | +export type ShareInsideStackParamList = StaticParamList<typeof ShareExtension>; |
15 | 35 |
|
16 | | - return ( |
17 | | - <ShareExtension.Navigator screenOptions={{ ...defaultHeader, ...themedHeader(theme) }}> |
18 | | - {/* @ts-ignore */} |
19 | | - <ShareExtension.Screen name='ShareListView' component={ShareListView} /> |
20 | | - {/* @ts-ignore */} |
21 | | - <ShareExtension.Screen name='ShareView' component={ShareView} /> |
22 | | - <ShareExtension.Screen name='SelectServerView' component={SelectServerView} /> |
23 | | - </ShareExtension.Navigator> |
24 | | - ); |
25 | | -}; |
| 36 | +const ShareExtensionStack = ShareExtension.getComponent(); |
26 | 37 |
|
27 | 38 | export default ShareExtensionStack; |
0 commit comments