|
1 | 1 | <% if (props.navigationPackage?.options.type === 'stack') { %>
|
2 |
| - import { NavigationContainer } from "@react-navigation/native"; |
3 |
| - import { createStackNavigator } from "@react-navigation/stack"; |
4 |
| -
|
5 |
| - <% if (props.stylingPackage?.name === "unistyles") { %> |
6 |
| - import { useUnistyles } from 'react-native-unistyles'; |
7 |
| - <% } %> |
8 |
| -
|
| 2 | + import { createStaticNavigation, StaticParamList } from '@react-navigation/native'; |
| 3 | + import { createStackNavigator } from '@react-navigation/stack'; |
9 | 4 | import Overview from "../screens/overview";
|
10 | 5 | import Details from "../screens/details";
|
11 |
| - import { BackButton } from '../components/BackButton'; |
| 6 | + import { BackButton } from '../components/BackButton'; |
12 | 7 |
|
13 |
| - export type RootStackParamList = { |
14 |
| - Overview: undefined; |
15 |
| - Details: { name: string }; |
16 |
| - }; |
| 8 | + const Stack = createStackNavigator({ |
| 9 | + screens: { |
| 10 | + Overview: { |
| 11 | + screen: Overview, |
| 12 | + }, |
| 13 | + Details: { |
| 14 | + screen: Details, |
| 15 | + options: ({ navigation }) => ({ |
| 16 | + headerLeft: () => <BackButton onPress={navigation.goBack} />, |
| 17 | + }) |
| 18 | + }, |
| 19 | + } |
| 20 | + }); |
17 | 21 |
|
18 |
| - const Stack = createStackNavigator<RootStackParamList>(); |
| 22 | + type RootStackParamList = StaticParamList<typeof Stack>; |
19 | 23 |
|
20 |
| - export default function RootStack() { |
21 |
| - <% if (props.stylingPackage?.name === "unistyles") { %> |
22 |
| - const { theme } = useUnistyles(); |
23 |
| - <% } %> |
24 |
| - return ( |
25 |
| - <NavigationContainer> |
26 |
| - <Stack.Navigator |
27 |
| - initialRouteName="Overview" |
28 |
| - <% if (props.stylingPackage?.name === "unistyles") { %> |
29 |
| - screenOptions={{ |
30 |
| - headerStyle: { |
31 |
| - backgroundColor: theme.colors.background, |
32 |
| - }, |
33 |
| - headerTitleStyle: { |
34 |
| - color: theme.colors.typography, |
35 |
| - }, |
36 |
| - headerTintColor: theme.colors.typography, |
37 |
| - }} |
38 |
| - <% } %> |
39 |
| - > |
40 |
| - <Stack.Screen name="Overview" component={Overview} /> |
41 |
| - <Stack.Screen |
42 |
| - name="Details" |
43 |
| - component={Details} |
44 |
| - options={({ navigation }) => ({ |
45 |
| - headerLeft: () => <BackButton onPress={navigation.goBack} />, |
46 |
| - })} |
47 |
| - /> |
48 |
| - </Stack.Navigator> |
49 |
| - </NavigationContainer> |
50 |
| - ); |
51 |
| - } |
| 24 | + declare global { |
| 25 | + namespace ReactNavigation { |
| 26 | + // eslint-disable-next-line @typescript-eslint/no-empty-object-type |
| 27 | + interface RootParamList extends RootStackParamList {} |
| 28 | + } |
| 29 | + } |
| 30 | +
|
| 31 | + export default createStaticNavigation(Stack); |
52 | 32 |
|
53 | 33 | <% } else if (props.navigationPackage?.options.type === 'tabs') { %>
|
54 |
| - import { NavigationContainer } from "@react-navigation/native"; |
| 34 | + import { createStaticNavigation, StaticParamList } from '@react-navigation/native'; |
55 | 35 | import { createStackNavigator } from "@react-navigation/stack";
|
56 |
| - <% if (props.stylingPackage?.name === "unistyles") { %> |
57 |
| - import { useUnistyles } from 'react-native-unistyles'; |
58 |
| - <% } %> |
59 |
| -
|
60 | 36 | import Modal from "../screens/modal";
|
61 | 37 | import TabNavigator from "./tab-navigator";
|
62 | 38 |
|
63 |
| - export type RootStackParamList = { |
64 |
| - TabNavigator: undefined; |
65 |
| - Modal: undefined; |
66 |
| - }; |
67 | 39 |
|
68 |
| - const Stack = createStackNavigator<RootStackParamList>(); |
| 40 | + const Stack = createStackNavigator({ |
| 41 | + screens: { |
| 42 | + TabNavigator: { |
| 43 | + screen: TabNavigator, |
| 44 | + options: { |
| 45 | + headerShown: false, |
| 46 | + }, |
| 47 | + }, |
| 48 | + Modal: { |
| 49 | + screen: Modal, |
| 50 | + options: { |
| 51 | + presentation: "modal", |
| 52 | + headerLeft: () => null, |
| 53 | + }, |
| 54 | + }, |
| 55 | + } |
| 56 | + }); |
69 | 57 |
|
70 |
| - export default function RootStack() { |
71 |
| - <% if (props.stylingPackage?.name === "unistyles") { %> |
72 |
| - const { theme } = useUnistyles(); |
73 |
| - <% } %> |
74 |
| - return ( |
75 |
| - <NavigationContainer> |
76 |
| - <Stack.Navigator |
77 |
| - initialRouteName="TabNavigator" |
78 |
| - <% if (props.stylingPackage?.name === "unistyles") { %> |
79 |
| - screenOptions={{ |
80 |
| - headerStyle: { |
81 |
| - backgroundColor: theme.colors.background, |
82 |
| - }, |
83 |
| - headerTitleStyle: { |
84 |
| - color: theme.colors.typography, |
85 |
| - }, |
86 |
| - headerTintColor: theme.colors.typography, |
87 |
| - }} |
88 |
| - <% } %> |
89 |
| - > |
90 |
| - <Stack.Screen |
91 |
| - name="TabNavigator" |
92 |
| - component={TabNavigator} |
93 |
| - options={{ headerShown: false }} |
94 |
| - /> |
95 |
| - <Stack.Screen |
96 |
| - name="Modal" |
97 |
| - component={Modal} |
98 |
| - options={{ presentation: "modal", headerLeft: () => null }} |
99 |
| - /> |
100 |
| - </Stack.Navigator> |
101 |
| - </NavigationContainer> |
102 |
| - ); |
103 |
| - } |
104 |
| - <% } else if (props.navigationPackage?.options.type === 'drawer + tabs') { %> |
105 |
| - import { NavigationContainer } from "@react-navigation/native"; |
106 |
| - import { createStackNavigator } from '@react-navigation/stack'; |
107 |
| - <% if (props.stylingPackage?.name === "unistyles") { %> |
108 |
| - import { useUnistyles } from 'react-native-unistyles'; |
109 |
| - <% } %> |
| 58 | + type RootStackParamList = StaticParamList<typeof Stack>; |
| 59 | +
|
| 60 | + declare global { |
| 61 | + namespace ReactNavigation { |
| 62 | + // eslint-disable-next-line @typescript-eslint/no-empty-object-type |
| 63 | + interface RootParamList extends RootStackParamList {} |
| 64 | + } |
| 65 | + } |
| 66 | +
|
| 67 | + export default createStaticNavigation(Stack); |
110 | 68 |
|
| 69 | +<% } else if (props.navigationPackage?.options.type === 'drawer + tabs') { %> |
| 70 | + import { createStaticNavigation, StaticParamList } from '@react-navigation/native'; |
| 71 | + import { createStackNavigator } from '@react-navigation/stack'; |
111 | 72 | import Modal from "../screens/modal";
|
112 | 73 | import DrawerNavigator from "./drawer-navigator";
|
113 | 74 |
|
114 |
| - export type RootStackParamList = { |
115 |
| - DrawerNavigator: undefined; |
116 |
| - Modal: undefined; |
117 |
| - TabNavigator: undefined; |
118 |
| - }; |
| 75 | + |
| 76 | + const Stack = createStackNavigator({ |
| 77 | + screens: { |
| 78 | + DrawerNavigator: { |
| 79 | + screen: DrawerNavigator, |
| 80 | + options: { |
| 81 | + headerShown: false, |
| 82 | + }, |
| 83 | + }, |
| 84 | + Modal: { |
| 85 | + screen: Modal, |
| 86 | + options: { |
| 87 | + presentation: "modal", |
| 88 | + headerLeft: () => null, |
| 89 | + }, |
| 90 | + }, |
| 91 | + } |
| 92 | + }); |
| 93 | +
|
| 94 | + type RootStackParamList = StaticParamList<typeof Stack>; |
119 | 95 |
|
120 |
| - const Stack = createStackNavigator<RootStackParamList>(); |
| 96 | + declare global { |
| 97 | + namespace ReactNavigation { |
| 98 | + // eslint-disable-next-line @typescript-eslint/no-empty-object-type |
| 99 | + interface RootParamList extends RootStackParamList {} |
| 100 | + } |
| 101 | + } |
121 | 102 |
|
122 |
| - export default function RootStack() { |
123 |
| - <% if (props.stylingPackage?.name === "unistyles") { %> |
124 |
| - const { theme } = useUnistyles(); |
125 |
| - <% } %> |
126 |
| - return ( |
127 |
| - <NavigationContainer> |
128 |
| - <Stack.Navigator |
129 |
| - initialRouteName="DrawerNavigator" |
130 |
| - <% if (props.stylingPackage?.name === "unistyles") { %> |
131 |
| - screenOptions={{ |
132 |
| - headerStyle: { |
133 |
| - backgroundColor: theme.colors.background, |
134 |
| - }, |
135 |
| - headerTitleStyle: { |
136 |
| - color: theme.colors.typography, |
137 |
| - }, |
138 |
| - headerTintColor: theme.colors.typography, |
139 |
| - }} |
140 |
| - <% } %> |
141 |
| - > |
142 |
| - <Stack.Screen |
143 |
| - name="DrawerNavigator" |
144 |
| - component={DrawerNavigator} |
145 |
| - options={{ headerShown: false }} |
146 |
| - /> |
147 |
| - <Stack.Screen |
148 |
| - name="Modal" |
149 |
| - component={Modal} |
150 |
| - options={{ presentation: "modal", headerLeft: () => null }} |
151 |
| - /> |
152 |
| - </Stack.Navigator> |
153 |
| - </NavigationContainer> |
154 |
| - ); |
155 |
| - } |
| 103 | + export default createStaticNavigation(Stack); |
| 104 | + |
156 | 105 | <% } %>
|
0 commit comments