@@ -23,29 +23,29 @@ import RNTesterNavBar, {navBarHeight} from './components/RNTesterNavbar';
23
23
import RNTesterList from './utils/RNTesterList' ;
24
24
import {
25
25
Screens ,
26
- initialState ,
26
+ initialNavState ,
27
27
getExamplesListWithBookmarksAndRecentlyUsed ,
28
- getInitialStateFromAsyncStorage ,
29
28
} from './utils/testerStateUtils' ;
30
- import { useAsyncStorageReducer } from './utils/useAsyncStorageReducer' ;
31
- import { RNTesterReducer , RNTesterActionsType } from './utils/RNTesterReducer' ;
29
+ import {
30
+ RNTesterNavReducer ,
31
+ RNTesterNavActionsType ,
32
+ } from './utils/RNTesterNavReducer' ;
32
33
import { RNTesterThemeContext , themes } from './components/RNTesterTheme' ;
33
34
import RNTTitleBar from './components/RNTTitleBar' ;
34
35
import { RNTesterEmptyBookmarksState } from './components/RNTesterEmptyBookmarksState' ;
36
+ import { RNTesterJsStallsProvider } from './utils/RNTesterJsStallsContext' ;
35
37
36
- const APP_STATE_KEY = 'RNTesterAppState.v3' ;
37
-
38
- // RNTester App currently uses AsyncStorage from react-native for storing navigation state
38
+ // RNTester App currently uses in memory storage for storing navigation state
39
39
// and bookmark items.
40
- // TODO: Vendor AsyncStorage or create our own .
40
+ // TODO: Identify/implement solution for async device storage .
41
41
LogBox . ignoreLogs ( [ / A s y n c S t o r a g e h a s b e e n e x t r a c t e d f r o m r e a c t - n a t i v e / ] ) ;
42
42
43
43
const RNTesterApp = ( ) : React . Node => {
44
- const [ state , dispatch ] = useAsyncStorageReducer (
45
- RNTesterReducer ,
46
- initialState ,
47
- APP_STATE_KEY ,
44
+ const [ state , dispatch ] = React . useReducer < Function , Object> (
45
+ RNTesterNavReducer ,
46
+ initialNavState ,
48
47
) ;
48
+
49
49
const colorScheme = useColorScheme ( ) ;
50
50
51
51
const {
@@ -57,17 +57,6 @@ const RNTesterApp = (): React.Node => {
57
57
recentlyUsed,
58
58
} = state ;
59
59
60
- React . useEffect ( ( ) => {
61
- getInitialStateFromAsyncStorage ( APP_STATE_KEY ) . then (
62
- initialStateFromStorage => {
63
- dispatch ( {
64
- type : RNTesterActionsType . INIT_FROM_STORAGE ,
65
- data : initialStateFromStorage ,
66
- } ) ;
67
- } ,
68
- ) ;
69
- } , [ dispatch ] ) ;
70
-
71
60
const examplesList = React . useMemo (
72
61
( ) =>
73
62
getExamplesListWithBookmarksAndRecentlyUsed ( { bookmarks, recentlyUsed} ) ,
@@ -76,7 +65,7 @@ const RNTesterApp = (): React.Node => {
76
65
77
66
const handleBackPress = React . useCallback ( ( ) => {
78
67
if ( activeModuleKey != null ) {
79
- dispatch ( { type : RNTesterActionsType . BACK_BUTTON_PRESS } ) ;
68
+ dispatch ( { type : RNTesterNavActionsType . BACK_BUTTON_PRESS } ) ;
80
69
}
81
70
} , [ dispatch , activeModuleKey ] ) ;
82
71
@@ -103,7 +92,7 @@ const RNTesterApp = (): React.Node => {
103
92
const handleModuleCardPress = React . useCallback (
104
93
( { exampleType, key, title} ) => {
105
94
dispatch ( {
106
- type : RNTesterActionsType . MODULE_CARD_PRESS ,
95
+ type : RNTesterNavActionsType . MODULE_CARD_PRESS ,
107
96
data : { exampleType, key, title} ,
108
97
} ) ;
109
98
} ,
@@ -113,7 +102,7 @@ const RNTesterApp = (): React.Node => {
113
102
const handleModuleExampleCardPress = React . useCallback (
114
103
exampleName => {
115
104
dispatch ( {
116
- type : RNTesterActionsType . EXAMPLE_CARD_PRESS ,
105
+ type : RNTesterNavActionsType . EXAMPLE_CARD_PRESS ,
117
106
data : { key : exampleName } ,
118
107
} ) ;
119
108
} ,
@@ -123,7 +112,7 @@ const RNTesterApp = (): React.Node => {
123
112
const toggleBookmark = React . useCallback (
124
113
( { exampleType, key} ) => {
125
114
dispatch ( {
126
- type : RNTesterActionsType . BOOKMARK_PRESS ,
115
+ type : RNTesterNavActionsType . BOOKMARK_PRESS ,
127
116
data : { exampleType, key} ,
128
117
} ) ;
129
118
} ,
@@ -133,7 +122,7 @@ const RNTesterApp = (): React.Node => {
133
122
const handleNavBarPress = React . useCallback (
134
123
args => {
135
124
dispatch ( {
136
- type : RNTesterActionsType . NAVBAR_PRESS ,
125
+ type : RNTesterNavActionsType . NAVBAR_PRESS ,
137
126
data : { screen : args . screen } ,
138
127
} ) ;
139
128
} ,
@@ -170,40 +159,42 @@ const RNTesterApp = (): React.Node => {
170
159
171
160
return (
172
161
< RNTesterThemeContext . Provider value = { theme } >
173
- < RNTTitleBar
174
- title = { title }
175
- theme = { theme }
176
- onBack = { activeModule ? handleBackPress : null }
177
- documentationURL = { activeModule ?. documentationURL }
178
- />
179
- < View
180
- style = { StyleSheet . compose ( styles . container , {
181
- backgroundColor : theme . GroupedBackgroundColor ,
182
- } ) } >
183
- { activeModule != null ? (
184
- < RNTesterModuleContainer
185
- module = { activeModule }
186
- example = { activeModuleExample }
187
- onExampleCardPress = { handleModuleExampleCardPress }
188
- />
189
- ) : screen === Screens . BOOKMARKS &&
190
- examplesList . bookmarks . length === 0 ? (
191
- < RNTesterEmptyBookmarksState />
192
- ) : (
193
- < RNTesterModuleList
194
- sections = { activeExampleList }
195
- toggleBookmark = { toggleBookmark }
196
- handleModuleCardPress = { handleModuleCardPress }
197
- />
198
- ) }
199
- </ View >
200
- < View style = { styles . bottomNavbar } >
201
- < RNTesterNavBar
202
- screen = { screen || Screens . COMPONENTS }
203
- isExamplePageOpen = { ! ! activeModule }
204
- handleNavBarPress = { handleNavBarPress }
162
+ < RNTesterJsStallsProvider >
163
+ < RNTTitleBar
164
+ title = { title }
165
+ theme = { theme }
166
+ onBack = { activeModule ? handleBackPress : null }
167
+ documentationURL = { activeModule ?. documentationURL }
205
168
/>
206
- </ View >
169
+ < View
170
+ style = { StyleSheet . compose ( styles . container , {
171
+ backgroundColor : theme . GroupedBackgroundColor ,
172
+ } ) } >
173
+ { activeModule != null ? (
174
+ < RNTesterModuleContainer
175
+ module = { activeModule }
176
+ example = { activeModuleExample }
177
+ onExampleCardPress = { handleModuleExampleCardPress }
178
+ />
179
+ ) : screen === Screens . BOOKMARKS &&
180
+ examplesList . bookmarks . length === 0 ? (
181
+ < RNTesterEmptyBookmarksState />
182
+ ) : (
183
+ < RNTesterModuleList
184
+ sections = { activeExampleList }
185
+ toggleBookmark = { toggleBookmark }
186
+ handleModuleCardPress = { handleModuleCardPress }
187
+ />
188
+ ) }
189
+ </ View >
190
+ < View style = { styles . bottomNavbar } >
191
+ < RNTesterNavBar
192
+ screen = { screen || Screens . COMPONENTS }
193
+ isExamplePageOpen = { ! ! activeModule }
194
+ handleNavBarPress = { handleNavBarPress }
195
+ />
196
+ </ View >
197
+ </ RNTesterJsStallsProvider >
207
198
</ RNTesterThemeContext . Provider >
208
199
) ;
209
200
} ;
0 commit comments