@@ -33,10 +33,13 @@ const {
33
33
Text,
34
34
TouchableWithoutFeedback,
35
35
UIManager,
36
+ useColorScheme,
36
37
View,
37
38
} = require ( 'react-native' ) ;
38
39
40
+ import type { RNTesterExample } from './types/RNTesterTypes' ;
39
41
import type { RNTesterNavigationState } from './utils/RNTesterNavigationReducer' ;
42
+ import { RNTesterThemeContext , themes } from './components/RNTesterTheme' ;
40
43
41
44
UIManager . setLayoutAnimationEnabledExperimental ( true ) ;
42
45
@@ -54,18 +57,119 @@ const HEADER_NAV_ICON = nativeImageSource({
54
57
height : 48 ,
55
58
} ) ;
56
59
57
- const Header = ( { title, onPressDrawer} ) => {
60
+ const Header = ( {
61
+ onPressDrawer,
62
+ title,
63
+ } : {
64
+ onPressDrawer ? : ( ) => mixed ,
65
+ title : string ,
66
+ } ) => (
67
+ < RNTesterThemeContext . Consumer >
68
+ { theme => {
69
+ return (
70
+ < View style = { [ styles . toolbar , { backgroundColor : theme . ToolbarColor } ] } >
71
+ < View style = { styles . toolbarCenter } >
72
+ < Text style = { [ styles . title , { color : theme . LabelColor } ] } >
73
+ { title }
74
+ </ Text >
75
+ </ View >
76
+ < View style = { styles . toolbarLeft } >
77
+ < TouchableWithoutFeedback onPress = { onPressDrawer } >
78
+ < Image source = { HEADER_NAV_ICON } />
79
+ </ TouchableWithoutFeedback >
80
+ </ View >
81
+ </ View >
82
+ ) ;
83
+ } }
84
+ </ RNTesterThemeContext . Consumer >
85
+ ) ;
86
+
87
+ const RNTesterExampleContainerViaHook = ( {
88
+ onPressDrawer,
89
+ title,
90
+ module,
91
+ exampleRef,
92
+ } : {
93
+ onPressDrawer ?: ( ) => mixed ,
94
+ title : string ,
95
+ module : RNTesterExample ,
96
+ exampleRef : ( ) => void ,
97
+ } ) => {
98
+ const colorScheme = useColorScheme ( ) ;
99
+ const theme = colorScheme === 'dark' ? themes . dark : themes . light ;
58
100
return (
59
- < View style = { styles . toolbar } >
60
- < View style = { styles . toolbarCenter } >
61
- < Text style = { styles . title } > { title } </ Text >
101
+ < RNTesterThemeContext . Provider value = { theme } >
102
+ < View style = { styles . container } >
103
+ < Header
104
+ title = { title }
105
+ /* $FlowFixMe(>=0.78.0 site=react_native_android_fb) This issue
106
+ * was found when making Flow check .android.js files. */
107
+ onPressDrawer = { onPressDrawer }
108
+ />
109
+ < RNTesterExampleContainer module = { module } ref = { exampleRef } />
62
110
</ View >
63
- < View style = { styles . toolbarLeft } >
64
- < TouchableWithoutFeedback onPress = { onPressDrawer } >
65
- < Image source = { HEADER_NAV_ICON } />
66
- </ TouchableWithoutFeedback >
111
+ </ RNTesterThemeContext . Provider >
112
+ ) ;
113
+ } ;
114
+
115
+ const RNTesterDrawerContentViaHook = ( {
116
+ onNavigate,
117
+ list,
118
+ } : {
119
+ onNavigate ? : ( ) => mixed ,
120
+ list : {
121
+ ComponentExamples : Array < RNTesterExample > ,
122
+ APIExamples : Array < RNTesterExample > ,
123
+ } ,
124
+ } ) => {
125
+ const colorScheme = useColorScheme ( ) ;
126
+ const theme = colorScheme === 'dark' ? themes . dark : themes . light ;
127
+ return (
128
+ < RNTesterThemeContext . Provider value = { theme } >
129
+ < View
130
+ style = { [
131
+ styles . drawerContentWrapper ,
132
+ { backgroundColor : theme . SystemBackgroundColor } ,
133
+ ] } >
134
+ < RNTesterExampleList
135
+ list = { list }
136
+ displayTitleRow = { true }
137
+ disableSearch = { true }
138
+ onNavigate = { onNavigate }
139
+ />
140
+ </ View >
141
+ </ RNTesterThemeContext . Provider >
142
+ ) ;
143
+ } ;
144
+
145
+ const RNTesterExampleListViaHook = ( {
146
+ title,
147
+ onPressDrawer,
148
+ onNavigate,
149
+ list,
150
+ } : {
151
+ title : string ,
152
+ onPressDrawer ?: ( ) => mixed ,
153
+ onNavigate ?: ( ) => mixed ,
154
+ list : {
155
+ ComponentExamples : Array < RNTesterExample > ,
156
+ APIExamples : Array < RNTesterExample > ,
157
+ } ,
158
+ } ) => {
159
+ const colorScheme = useColorScheme ( ) ;
160
+ const theme = colorScheme === 'dark' ? themes . dark : themes . light ;
161
+ return (
162
+ < RNTesterThemeContext . Provider value = { theme } >
163
+ < View style = { styles . container } >
164
+ < Header
165
+ title = { title }
166
+ /* $FlowFixMe(>=0.78.0 site=react_native_android_fb) This issue
167
+ * was found when making Flow check .android.js files. */
168
+ onPressDrawer = { onPressDrawer }
169
+ />
170
+ < RNTesterExampleList onNavigate = { onNavigate } list = { list } />
67
171
</ View >
68
- </ View >
172
+ </ RNTesterThemeContext . Provider >
69
173
) ;
70
174
} ;
71
175
@@ -133,14 +237,10 @@ class RNTesterApp extends React.Component<Props, RNTesterNavigationState> {
133
237
134
238
_renderDrawerContent = ( ) = > {
135
239
return (
136
- < View style = { styles . drawerContentWrapper } >
137
- < RNTesterExampleList
138
- list = { RNTesterList }
139
- displayTitleRow = { true }
140
- disableSearch = { true }
141
- onNavigate = { this . _handleAction }
142
- />
143
- </ View >
240
+ < RNTesterDrawerContentViaHook
241
+ onNavigate = { this . _handleAction }
242
+ list = { RNTesterList }
243
+ />
144
244
) ;
145
245
} ;
146
246
@@ -164,39 +264,31 @@ class RNTesterApp extends React.Component<Props, RNTesterNavigationState> {
164
264
) ;
165
265
} else if ( ExampleModule ) {
166
266
return (
167
- < View style = { styles . container } >
168
- < Header
169
- title = { ExampleModule . title }
267
+ < RNTesterExampleContainerViaHook
268
+ /* $FlowFixMe(>=0.78.0 site=react_native_android_fb) This issue was found
269
+ * when making Flow check .android.js files. */
270
+ onPressDrawer = { ( ) => this . drawer . openDrawer ( ) }
271
+ title = { ExampleModule . title }
272
+ module = { ExampleModule }
273
+ exampleRef = { example => {
170
274
/* $FlowFixMe(>=0.78.0 site=react_native_android_fb) This issue
171
275
* was found when making Flow check .android.js files. */
172
- onPressDrawer = { ( ) => this . drawer . openDrawer ( ) }
173
- />
174
- < RNTesterExampleContainer
175
- module = { ExampleModule }
176
- ref = { example => {
177
- /* $FlowFixMe(>=0.78.0 site=react_native_android_fb) This issue
178
- * was found when making Flow check .android.js files. */
179
- this . _exampleRef = example ;
180
- } }
181
- />
182
- </ View >
276
+ this . _exampleRef = example ;
277
+ } }
278
+ />
183
279
) ;
184
280
}
185
281
}
186
282
187
283
return (
188
- < View style = { styles . container } >
189
- < Header
190
- title = "RNTester"
191
- /* $FlowFixMe(>=0.78.0 site=react_native_android_fb) This issue
192
- * was found when making Flow check .android.js files. */
193
- onPressDrawer = { ( ) => this . drawer . openDrawer ( ) }
194
- />
195
- < RNTesterExampleList
196
- onNavigate = { this . _handleAction }
197
- list = { RNTesterList }
198
- />
199
- </ View >
284
+ < RNTesterExampleListViaHook
285
+ title = { 'RNTester' }
286
+ /* $FlowFixMe(>=0.78.0 site=react_native_android_fb) This issue was found
287
+ * when making Flow check .android.js files. */
288
+ onPressDrawer = { ( ) => this . drawer . openDrawer ( ) }
289
+ onNavigate = { this . _handleAction }
290
+ list = { RNTesterList }
291
+ />
200
292
) ;
201
293
}
202
294
@@ -246,7 +338,6 @@ const styles = StyleSheet.create({
246
338
flex : 1 ,
247
339
} ,
248
340
toolbar : {
249
- backgroundColor : '#E9EAED' ,
250
341
height : 56 ,
251
342
} ,
252
343
toolbarLeft : {
@@ -268,7 +359,6 @@ const styles = StyleSheet.create({
268
359
drawerContentWrapper : {
269
360
flex : 1 ,
270
361
paddingTop : StatusBar . currentHeight ,
271
- backgroundColor : 'white' ,
272
362
} ,
273
363
} ) ;
274
364
0 commit comments