5
5
* LICENSE file in the root directory of this source tree.
6
6
*/
7
7
8
- import React , { useCallback , useState } from 'react' ;
8
+ import React , { useCallback , useMemo , useState } from 'react' ;
9
9
import {
10
10
Button ,
11
11
Keyboard ,
@@ -15,52 +15,42 @@ import {
15
15
TouchableOpacity ,
16
16
View ,
17
17
} from 'react-native' ;
18
- import BasicExample from './examples/Basic' ;
18
+ import Basic from './examples/Basic' ;
19
+ import Functional from './examples/Functional' ;
19
20
import GetSetClear from './examples/GetSetClear' ;
20
21
import MergeItem from './examples/MergeItem' ;
21
22
22
- const TESTS = {
23
- GetSetClear : {
24
- title : 'Simple Get/Set value' ,
25
- testId : 'get-set-clear' ,
26
- description : 'Store and retrieve persisted data' ,
27
- render ( ) {
28
- return < GetSetClear /> ;
29
- } ,
30
- } ,
31
- MergeItem : {
32
- title : 'Merge item' ,
33
- testId : 'merge-item' ,
34
- description : 'Merge object with already stored data' ,
35
- render ( ) {
36
- return < MergeItem /> ;
37
- } ,
38
- } ,
39
- Basic : {
40
- title : 'Basic' ,
41
- testId : 'basic' ,
42
- description : 'Basic functionality test' ,
43
- render ( ) {
44
- return < BasicExample /> ;
45
- } ,
46
- } ,
23
+ const SCREENS = {
24
+ Functional,
25
+ GetSetClear,
26
+ MergeItem,
27
+ Basic,
47
28
} ;
48
29
49
30
export default function App ( ) : JSX . Element {
50
31
const [ iteration , setIteration ] = useState ( 0 ) ;
51
- const [ currentTest , setCurrentTest ] = useState ( TESTS . GetSetClear ) ;
32
+ const [ currentTest , setCurrentTest ] = useState ( SCREENS . Functional ) ;
52
33
53
- const dismissKeyboard = useCallback ( ( ) => Keyboard . dismiss ( ) , [ ] ) ;
34
+ const dismissKeyboard = useCallback ( Keyboard . dismiss , [ ] ) ;
54
35
const simulateRestart = useCallback (
55
36
( ) => setIteration ( iteration + 1 ) ,
56
37
[ iteration ]
57
38
) ;
58
- const testBasic = useCallback ( ( ) => setCurrentTest ( TESTS . Basic ) , [ ] ) ;
59
- const testGetSetClear = useCallback (
60
- ( ) => setCurrentTest ( TESTS . GetSetClear ) ,
39
+ const navigationBar = useMemo (
40
+ ( ) =>
41
+ Object . values ( SCREENS ) . map ( ( t ) => {
42
+ const { testId, title } = t ;
43
+ return (
44
+ < Button
45
+ key = { testId }
46
+ testID = { testId }
47
+ title = { title }
48
+ onPress = { ( ) => setCurrentTest ( t ) }
49
+ />
50
+ ) ;
51
+ } ) ,
61
52
[ ]
62
53
) ;
63
- const testMergeItem = useCallback ( ( ) => setCurrentTest ( TESTS . MergeItem ) , [ ] ) ;
64
54
65
55
return (
66
56
< SafeAreaView style = { styles . container } >
@@ -69,7 +59,6 @@ export default function App(): JSX.Element {
69
59
onPress = { dismissKeyboard }
70
60
testID = "closeKeyboard"
71
61
/>
72
-
73
62
< TouchableOpacity
74
63
testID = "restart_button"
75
64
onPress = { simulateRestart }
@@ -79,22 +68,10 @@ export default function App(): JSX.Element {
79
68
< Text > Simulate Restart</ Text >
80
69
</ TouchableOpacity >
81
70
82
- < View style = { styles . testPickerContainer } >
83
- < Button
84
- testID = "testType_getSetClear"
85
- title = "Get/Set/Clear"
86
- onPress = { testGetSetClear }
87
- />
88
- < Button
89
- testID = "testType_mergeItem"
90
- title = "Merge Item"
91
- onPress = { testMergeItem }
92
- />
93
- < Button title = { TESTS . Basic . title } onPress = { testBasic } />
94
- </ View >
71
+ < View style = { styles . testPickerContainer } > { navigationBar } </ View >
95
72
96
73
< View
97
- testID = { `example- ${ currentTest . testId } ` }
74
+ testID = { `${ currentTest . testId } -view ` }
98
75
key = { currentTest . title + iteration }
99
76
style = { styles . exampleContainer }
100
77
>
0 commit comments