@@ -7,15 +7,40 @@ import {
7
7
StyleSheet ,
8
8
View ,
9
9
} from 'react-native' ;
10
- import { ThemeColors , useTheme , Themed , SafeAreaView } from 'react-navigation' ;
11
- import { createStackNavigator } from 'react-navigation-stack' ;
12
- import { createDrawerNavigator } from 'react-navigation-drawer' ;
10
+ import {
11
+ ThemeColors ,
12
+ useTheme ,
13
+ Themed ,
14
+ SafeAreaView ,
15
+ NavigationRoute ,
16
+ } from 'react-navigation' ;
17
+ import {
18
+ createStackNavigator ,
19
+ NavigationStackScreenComponent ,
20
+ NavigationStackProp ,
21
+ } from 'react-navigation-stack' ;
22
+ import {
23
+ createDrawerNavigator ,
24
+ DrawerContentComponentProps ,
25
+ NavigationDrawerOptions ,
26
+ NavigationDrawerProp ,
27
+ } from 'react-navigation-drawer' ;
13
28
import Animated from 'react-native-reanimated' ;
14
29
import { MaterialIcons } from '@expo/vector-icons' ;
15
30
16
- const SampleText = ( { children } ) => < Themed . Text > { children } </ Themed . Text > ;
31
+ type Params = { drawerLockMode : 'unlocked' | 'locked-open' | 'locked-closed' } ;
32
+
33
+ const SampleText = ( { children } : { children : React . ReactNode } ) => (
34
+ < Themed . Text > { children } </ Themed . Text >
35
+ ) ;
17
36
18
- const MyNavScreen = ( { navigation, banner } ) => {
37
+ const MyNavScreen = ( {
38
+ navigation,
39
+ banner,
40
+ } : {
41
+ navigation : NavigationStackProp < NavigationRoute , Params > ;
42
+ banner : string ;
43
+ } ) => {
19
44
let theme = useTheme ( ) ;
20
45
21
46
return (
@@ -109,20 +134,22 @@ const MyNavScreen = ({ navigation, banner }) => {
109
134
) ;
110
135
} ;
111
136
112
- const InboxScreen = ( { navigation } ) => (
113
- < MyNavScreen banner = "Inbox Screen" navigation = { navigation } />
114
- ) ;
137
+ const InboxScreen : NavigationStackScreenComponent < Params > = ( {
138
+ navigation,
139
+ } ) => < MyNavScreen banner = "Inbox Screen" navigation = { navigation } /> ;
140
+
115
141
InboxScreen . navigationOptions = {
116
142
headerTitle : 'Inbox' ,
117
143
} ;
118
144
119
- const EmailScreen = ( { navigation } ) => (
120
- < MyNavScreen banner = "Email Screen" navigation = { navigation } />
121
- ) ;
145
+ const EmailScreen : NavigationStackScreenComponent < Params > = ( {
146
+ navigation,
147
+ } ) => < MyNavScreen banner = "Email Screen" navigation = { navigation } /> ;
148
+
149
+ const DraftsScreen : NavigationStackScreenComponent < Params > = ( {
150
+ navigation,
151
+ } ) => < MyNavScreen banner = "Drafts Screen" navigation = { navigation } /> ;
122
152
123
- const DraftsScreen = ( { navigation } ) => (
124
- < MyNavScreen banner = "Drafts Screen" navigation = { navigation } />
125
- ) ;
126
153
DraftsScreen . navigationOptions = {
127
154
headerTitle : 'Drafts' ,
128
155
} ;
@@ -133,19 +160,23 @@ const InboxStack = createStackNavigator(
133
160
Email : { screen : EmailScreen } ,
134
161
} ,
135
162
{
136
- navigationOptions : ( { navigation } ) => ( {
137
- drawerLabel : 'Inbox' ,
138
- drawerLockMode : (
139
- navigation . state . routes [ navigation . state . index ] . params || { }
140
- ) . drawerLockMode ,
141
- drawerIcon : ( { tintColor } ) => (
142
- < MaterialIcons
143
- name = "move-to-inbox"
144
- size = { 24 }
145
- style = { { color : tintColor } }
146
- />
147
- ) ,
148
- } ) ,
163
+ navigationOptions : ( { navigation } ) => {
164
+ const options : NavigationDrawerOptions = {
165
+ drawerLabel : 'Inbox' ,
166
+ drawerLockMode : (
167
+ navigation . state . routes [ navigation . state . index ] . params || { }
168
+ ) . drawerLockMode ,
169
+ drawerIcon : ( { tintColor } ) => (
170
+ < MaterialIcons
171
+ name = "move-to-inbox"
172
+ size = { 24 }
173
+ style = { { color : tintColor } }
174
+ />
175
+ ) ,
176
+ } ;
177
+
178
+ return options ;
179
+ } ,
149
180
}
150
181
) ;
151
182
@@ -155,19 +186,27 @@ const DraftsStack = createStackNavigator(
155
186
Email : { screen : EmailScreen } ,
156
187
} ,
157
188
{
158
- navigationOptions : ( { navigation } ) => ( {
159
- drawerLabel : 'Drafts' ,
160
- drawerLockMode : (
161
- navigation . state . routes [ navigation . state . index ] . params || { }
162
- ) . drawerLockMode ,
163
- drawerIcon : ( { tintColor } ) => (
164
- < MaterialIcons name = "drafts" size = { 24 } style = { { color : tintColor } } />
165
- ) ,
166
- } ) ,
189
+ navigationOptions : ( { navigation } ) => {
190
+ const options : NavigationDrawerOptions = {
191
+ drawerLabel : 'Drafts' ,
192
+ drawerLockMode : (
193
+ navigation . state . routes [ navigation . state . index ] . params || { }
194
+ ) . drawerLockMode ,
195
+ drawerIcon : ( { tintColor } ) => (
196
+ < MaterialIcons name = "drafts" size = { 24 } style = { { color : tintColor } } />
197
+ ) ,
198
+ } ;
199
+
200
+ return options ;
201
+ } ,
167
202
}
168
203
) ;
169
204
170
- const DrawerContents = ( { drawerOpenProgress, navigation } ) => {
205
+ const DrawerContents = ( {
206
+ drawerOpenProgress,
207
+ descriptors,
208
+ navigation,
209
+ } : DrawerContentComponentProps ) => {
171
210
// `contentComponent` is passed an Animated.Value called drawerOpenProgress
172
211
// that can be used to do interesting things like a simple parallax drawe
173
212
const translateX = Animated . interpolate ( drawerOpenProgress , {
@@ -179,15 +218,23 @@ const DrawerContents = ({ drawerOpenProgress, navigation }) => {
179
218
< Animated . View style = { { transform : [ { translateX } ] } } >
180
219
< ScrollView >
181
220
< SafeAreaView forceInset = { { top : 'always' } } >
182
- < DrawerItem navigation = { navigation } item = "Drafts" />
183
- < DrawerItem navigation = { navigation } item = "Email" />
221
+ { navigation . state . routes . map ( route => (
222
+ < DrawerItem
223
+ key = { route . key }
224
+ navigation = { descriptors [ route . key ] . navigation }
225
+ item = { route . routeName }
226
+ />
227
+ ) ) }
184
228
</ SafeAreaView >
185
229
</ ScrollView >
186
230
</ Animated . View >
187
231
) ;
188
232
} ;
189
233
190
- const DrawerItem = props => {
234
+ const DrawerItem = ( props : {
235
+ navigation : NavigationDrawerProp ;
236
+ item : string ;
237
+ } ) => {
191
238
return (
192
239
< TouchableOpacity onPress = { ( ) => props . navigation . navigate ( props . item ) } >
193
240
< Themed . Text style = { { padding : 10 , fontSize : 18 , fontWeight : '600' } } >
0 commit comments