@@ -4,13 +4,14 @@ import {
4
4
StyleSheet ,
5
5
I18nManager ,
6
6
Platform ,
7
- StatusBar ,
8
7
useColorScheme ,
8
+ View ,
9
9
} from 'react-native' ;
10
10
import {
11
11
DarkTheme ,
12
12
DefaultTheme ,
13
13
NavigationContainer ,
14
+ NavigationIndependentTree ,
14
15
useTheme ,
15
16
} from '@react-navigation/native' ;
16
17
import { StackNavigationProp } from '@react-navigation/stack' ;
@@ -37,14 +38,28 @@ import { enableFreeze } from 'react-native-screens';
37
38
import { GestureDetectorProvider } from 'react-native-screens/gesture-handler' ;
38
39
import { GestureHandlerRootView } from 'react-native-gesture-handler' ;
39
40
41
+ import * as Tests from './src/tests' ;
42
+
40
43
enableFreeze ( ) ;
41
44
45
+ function isPlatformReady ( name : keyof typeof SCREENS ) {
46
+ if ( Platform . isTV ) {
47
+ return ! ! SCREENS [ name ] . isTVOSReady ;
48
+ }
49
+
50
+ return true ;
51
+ }
52
+
53
+ function isTestSectionEnabled ( ) {
54
+ return true ;
55
+ }
56
+
42
57
const SCREENS : Record <
43
58
string ,
44
59
{
45
60
title : string ;
46
61
component : ( ) => React . JSX . Element ;
47
- type : 'example' | 'playground' ;
62
+ type : 'example' | 'playground' | 'test' ;
48
63
isTVOSReady ?: boolean ;
49
64
}
50
65
> = {
@@ -119,20 +134,32 @@ const SCREENS: Record<
119
134
} ,
120
135
} ;
121
136
122
- const isPlatformReady = ( name : keyof typeof SCREENS ) => {
123
- if ( Platform . isTV ) {
124
- return ! ! SCREENS [ name ] . isTVOSReady ;
125
- }
137
+ if ( isTestSectionEnabled ( ) ) {
138
+ Object . keys ( Tests ) . forEach ( testName => {
139
+ SCREENS [ testName ] = {
140
+ title : testName ,
141
+ component : ( ) => {
142
+ const TestComponent = Tests [ testName as keyof typeof Tests ] ;
143
+ return (
144
+ < NavigationIndependentTree >
145
+ < TestComponent />
146
+ </ NavigationIndependentTree >
147
+ ) ;
148
+ } ,
149
+ type : 'test' ,
150
+ } ;
151
+ } ) ;
152
+ }
126
153
127
- return true ;
128
- } ;
129
154
130
155
const screens = Object . keys ( SCREENS ) ;
131
156
const examples = screens . filter ( name => SCREENS [ name ] . type === 'example' ) ;
132
157
const playgrounds = screens . filter ( name => SCREENS [ name ] . type === 'playground' ) ;
158
+ const tests = isTestSectionEnabled ( ) ? screens . filter ( name => SCREENS [ name ] . type === 'test' ) : [ ] ;
133
159
134
160
type RootStackParamList = {
135
161
Main : undefined ;
162
+ Tests : undefined ;
136
163
} & {
137
164
[ P in keyof typeof SCREENS ] : undefined ;
138
165
} ;
@@ -186,6 +213,17 @@ const MainScreen = ({ navigation }: MainScreenProps): React.JSX.Element => {
186
213
disabled = { ! isPlatformReady ( name ) }
187
214
/>
188
215
) ) }
216
+ { isTestSectionEnabled ( ) &&
217
+ < ThemedText style = { styles . label } > Tests</ ThemedText > }
218
+ { isTestSectionEnabled ( ) && tests . map ( name => (
219
+ < ListItem
220
+ key = { name }
221
+ testID = { `root-screen-tests-${ name } ` }
222
+ title = { SCREENS [ name ] . title }
223
+ onPress = { ( ) => navigation . navigate ( name ) }
224
+ disabled = { false }
225
+ />
226
+ ) ) }
189
227
</ ScrollView >
190
228
) ;
191
229
} ;
0 commit comments