@rownd/react-native 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (175) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +213 -0
  3. package/android/build.gradle +59 -0
  4. package/android/src/main/AndroidManifest.xml +4 -0
  5. package/android/src/main/java/com/reactnative/ReactNativePackage.java +22 -0
  6. package/android/src/main/java/com/reactnative/ReactNativeViewManager.java +31 -0
  7. package/ios/ReactNative.xcodeproj/project.pbxproj +282 -0
  8. package/ios/ReactNative.xcodeproj/project.xcworkspace/contents.xcworkspacedata +4 -0
  9. package/ios/ReactNativeViewManager.m +34 -0
  10. package/lib/commonjs/assets/images/checkmark--filled.svg +12 -0
  11. package/lib/commonjs/assets/images/email-verify-waiting.svg +36 -0
  12. package/lib/commonjs/assets/images/phone-verify-waiting.svg +26 -0
  13. package/lib/commonjs/components/AuthenticatedComponent.js +35 -0
  14. package/lib/commonjs/components/AuthenticatedComponent.js.map +1 -0
  15. package/lib/commonjs/components/AutoSigninDialog.js +119 -0
  16. package/lib/commonjs/components/AutoSigninDialog.js.map +1 -0
  17. package/lib/commonjs/components/DefaultContext.js +269 -0
  18. package/lib/commonjs/components/DefaultContext.js.map +1 -0
  19. package/lib/commonjs/components/GlobalContext.js +340 -0
  20. package/lib/commonjs/components/GlobalContext.js.map +1 -0
  21. package/lib/commonjs/components/RowndComponents.js +29 -0
  22. package/lib/commonjs/components/RowndComponents.js.map +1 -0
  23. package/lib/commonjs/components/RowndProvider.js +55 -0
  24. package/lib/commonjs/components/RowndProvider.js.map +1 -0
  25. package/lib/commonjs/components/SignIn.js +622 -0
  26. package/lib/commonjs/components/SignIn.js.map +1 -0
  27. package/lib/commonjs/data/actions.js +26 -0
  28. package/lib/commonjs/data/actions.js.map +1 -0
  29. package/lib/commonjs/hooks/api.js +157 -0
  30. package/lib/commonjs/hooks/api.js.map +1 -0
  31. package/lib/commonjs/hooks/debounce.js +38 -0
  32. package/lib/commonjs/hooks/debounce.js.map +1 -0
  33. package/lib/commonjs/hooks/fingerprint.js +176 -0
  34. package/lib/commonjs/hooks/fingerprint.js.map +1 -0
  35. package/lib/commonjs/hooks/index.js +48 -0
  36. package/lib/commonjs/hooks/index.js.map +1 -0
  37. package/lib/commonjs/hooks/interval.js +31 -0
  38. package/lib/commonjs/hooks/interval.js.map +1 -0
  39. package/lib/commonjs/hooks/nav.js +39 -0
  40. package/lib/commonjs/hooks/nav.js.map +1 -0
  41. package/lib/commonjs/hooks/rownd.js +163 -0
  42. package/lib/commonjs/hooks/rownd.js.map +1 -0
  43. package/lib/commonjs/index.js +32 -0
  44. package/lib/commonjs/index.js.map +1 -0
  45. package/lib/commonjs/index.tsx.bak +26 -0
  46. package/lib/commonjs/types.js +2 -0
  47. package/lib/commonjs/types.js.map +1 -0
  48. package/lib/commonjs/utils/config.js +28 -0
  49. package/lib/commonjs/utils/config.js.map +1 -0
  50. package/lib/commonjs/utils/events.js +57 -0
  51. package/lib/commonjs/utils/events.js.map +1 -0
  52. package/lib/commonjs/utils/form.js +46 -0
  53. package/lib/commonjs/utils/form.js.map +1 -0
  54. package/lib/commonjs/utils/queue.js +117 -0
  55. package/lib/commonjs/utils/queue.js.map +1 -0
  56. package/lib/commonjs/utils/storage.js +15 -0
  57. package/lib/commonjs/utils/storage.js.map +1 -0
  58. package/lib/commonjs/utils/tailwind.js +17 -0
  59. package/lib/commonjs/utils/tailwind.js.map +1 -0
  60. package/lib/commonjs/utils/tokens.js +35 -0
  61. package/lib/commonjs/utils/tokens.js.map +1 -0
  62. package/lib/commonjs/utils/user-data.js +21 -0
  63. package/lib/commonjs/utils/user-data.js.map +1 -0
  64. package/lib/module/assets/images/checkmark--filled.svg +12 -0
  65. package/lib/module/assets/images/email-verify-waiting.svg +36 -0
  66. package/lib/module/assets/images/phone-verify-waiting.svg +26 -0
  67. package/lib/module/components/AuthenticatedComponent.js +24 -0
  68. package/lib/module/components/AuthenticatedComponent.js.map +1 -0
  69. package/lib/module/components/AutoSigninDialog.js +100 -0
  70. package/lib/module/components/AutoSigninDialog.js.map +1 -0
  71. package/lib/module/components/DefaultContext.js +244 -0
  72. package/lib/module/components/DefaultContext.js.map +1 -0
  73. package/lib/module/components/GlobalContext.js +318 -0
  74. package/lib/module/components/GlobalContext.js.map +1 -0
  75. package/lib/module/components/RowndComponents.js +14 -0
  76. package/lib/module/components/RowndComponents.js.map +1 -0
  77. package/lib/module/components/RowndProvider.js +39 -0
  78. package/lib/module/components/RowndProvider.js.map +1 -0
  79. package/lib/module/components/SignIn.js +593 -0
  80. package/lib/module/components/SignIn.js.map +1 -0
  81. package/lib/module/data/actions.js +19 -0
  82. package/lib/module/data/actions.js.map +1 -0
  83. package/lib/module/hooks/api.js +138 -0
  84. package/lib/module/hooks/api.js.map +1 -0
  85. package/lib/module/hooks/debounce.js +29 -0
  86. package/lib/module/hooks/debounce.js.map +1 -0
  87. package/lib/module/hooks/fingerprint.js +157 -0
  88. package/lib/module/hooks/fingerprint.js.map +1 -0
  89. package/lib/module/hooks/index.js +7 -0
  90. package/lib/module/hooks/index.js.map +1 -0
  91. package/lib/module/hooks/interval.js +23 -0
  92. package/lib/module/hooks/interval.js.map +1 -0
  93. package/lib/module/hooks/nav.js +30 -0
  94. package/lib/module/hooks/nav.js.map +1 -0
  95. package/lib/module/hooks/rownd.js +148 -0
  96. package/lib/module/hooks/rownd.js.map +1 -0
  97. package/lib/module/index.js +6 -0
  98. package/lib/module/index.js.map +1 -0
  99. package/lib/module/index.tsx.bak +26 -0
  100. package/lib/module/types.js +2 -0
  101. package/lib/module/types.js.map +1 -0
  102. package/lib/module/utils/config.js +17 -0
  103. package/lib/module/utils/config.js.map +1 -0
  104. package/lib/module/utils/events.js +45 -0
  105. package/lib/module/utils/events.js.map +1 -0
  106. package/lib/module/utils/form.js +34 -0
  107. package/lib/module/utils/form.js.map +1 -0
  108. package/lib/module/utils/queue.js +109 -0
  109. package/lib/module/utils/queue.js.map +1 -0
  110. package/lib/module/utils/storage.js +6 -0
  111. package/lib/module/utils/storage.js.map +1 -0
  112. package/lib/module/utils/tailwind.js +5 -0
  113. package/lib/module/utils/tailwind.js.map +1 -0
  114. package/lib/module/utils/tokens.js +24 -0
  115. package/lib/module/utils/tokens.js.map +1 -0
  116. package/lib/module/utils/user-data.js +14 -0
  117. package/lib/module/utils/user-data.js.map +1 -0
  118. package/lib/typescript/example2/App.d.ts +11 -0
  119. package/lib/typescript/src/components/AuthenticatedComponent.d.ts +7 -0
  120. package/lib/typescript/src/components/AutoSigninDialog.d.ts +1 -0
  121. package/lib/typescript/src/components/DefaultContext.d.ts +12 -0
  122. package/lib/typescript/src/components/GlobalContext.d.ts +111 -0
  123. package/lib/typescript/src/components/RowndComponents.d.ts +1 -0
  124. package/lib/typescript/src/components/RowndProvider.d.ts +8 -0
  125. package/lib/typescript/src/components/SignIn.d.ts +1 -0
  126. package/lib/typescript/src/data/actions.d.ts +20 -0
  127. package/lib/typescript/src/hooks/api.d.ts +12 -0
  128. package/lib/typescript/src/hooks/debounce.d.ts +5 -0
  129. package/lib/typescript/src/hooks/fingerprint.d.ts +12 -0
  130. package/lib/typescript/src/hooks/index.d.ts +6 -0
  131. package/lib/typescript/src/hooks/interval.d.ts +2 -0
  132. package/lib/typescript/src/hooks/nav.d.ts +6 -0
  133. package/lib/typescript/src/hooks/rownd.d.ts +37 -0
  134. package/lib/typescript/src/index.d.ts +4 -0
  135. package/lib/typescript/src/types.d.ts +26 -0
  136. package/lib/typescript/src/utils/config.d.ts +18 -0
  137. package/lib/typescript/src/utils/events.d.ts +22 -0
  138. package/lib/typescript/src/utils/form.d.ts +17 -0
  139. package/lib/typescript/src/utils/queue.d.ts +21 -0
  140. package/lib/typescript/src/utils/storage.d.ts +3 -0
  141. package/lib/typescript/src/utils/tailwind.d.ts +2 -0
  142. package/lib/typescript/src/utils/tokens.d.ts +4 -0
  143. package/lib/typescript/src/utils/user-data.d.ts +3 -0
  144. package/lib/typescript/tailwind.config.d.ts +10 -0
  145. package/package.json +177 -0
  146. package/react-native.podspec +19 -0
  147. package/src/assets/images/checkmark--filled.svg +12 -0
  148. package/src/assets/images/email-verify-waiting.svg +36 -0
  149. package/src/assets/images/phone-verify-waiting.svg +26 -0
  150. package/src/components/AuthenticatedComponent.tsx +30 -0
  151. package/src/components/AutoSigninDialog.tsx +125 -0
  152. package/src/components/DefaultContext.tsx +278 -0
  153. package/src/components/GlobalContext.tsx +485 -0
  154. package/src/components/RowndComponents.tsx +21 -0
  155. package/src/components/RowndProvider.tsx +56 -0
  156. package/src/components/SignIn.tsx +770 -0
  157. package/src/data/actions.ts +21 -0
  158. package/src/hooks/api.ts +163 -0
  159. package/src/hooks/debounce.ts +36 -0
  160. package/src/hooks/fingerprint.ts +217 -0
  161. package/src/hooks/index.ts +7 -0
  162. package/src/hooks/interval.ts +25 -0
  163. package/src/hooks/nav.tsx +29 -0
  164. package/src/hooks/rownd.ts +184 -0
  165. package/src/index.tsx +6 -0
  166. package/src/index.tsx.bak +26 -0
  167. package/src/types.ts +27 -0
  168. package/src/utils/config.ts +36 -0
  169. package/src/utils/events.ts +54 -0
  170. package/src/utils/form.tsx +64 -0
  171. package/src/utils/queue.ts +75 -0
  172. package/src/utils/storage.ts +7 -0
  173. package/src/utils/tailwind.ts +6 -0
  174. package/src/utils/tokens.ts +26 -0
  175. package/src/utils/user-data.ts +15 -0
@@ -0,0 +1,485 @@
1
+ import React, { createContext, FunctionComponent } from 'react';
2
+ import { useReducer, useContext } from 'react';
3
+ import isEqual from 'lodash-es/isEqual';
4
+ import pick from 'lodash-es/pick';
5
+ import jwt_decode from 'jwt-decode';
6
+ import type { IConfig } from '../utils/config';
7
+ import storage from '../utils/storage';
8
+ import { events, EventType } from '../utils/events';
9
+
10
+ import { type TAction, ActionType } from '../data/actions';
11
+
12
+ type Dispatch = (action: TAction) => void;
13
+
14
+ export type GlobalState = {
15
+ is_initializing: boolean;
16
+ is_container_visible: boolean;
17
+ use_modal: boolean;
18
+ nav: {
19
+ current_route: string;
20
+ route_trigger: string;
21
+ event_id: string;
22
+ section: string;
23
+ options?: any;
24
+ };
25
+ user: {
26
+ data: {
27
+ id?: string;
28
+ email: string | null;
29
+ [key: string]: any;
30
+ };
31
+ needs_refresh?: boolean;
32
+ redacted: string[];
33
+ };
34
+ auth: {
35
+ access_token: string | null;
36
+ refresh_token: string | null;
37
+ app_id: string | null;
38
+ init_data?: Record<string, any>;
39
+ is_verified_user?: boolean;
40
+ };
41
+ app: {
42
+ id?: string;
43
+ icon?: string;
44
+ icon_content_type?: string;
45
+ config: AppConfig | null;
46
+ schema: AppSchema | null;
47
+ user_verification_field?: string;
48
+ user_verification_fields?: string[];
49
+ };
50
+ local_acls: Record<string, { shared: boolean }> | null;
51
+ is_saving_user_data: boolean;
52
+ config?: IConfig;
53
+ };
54
+
55
+ type AppSchema = Record<string, SchemaField>;
56
+
57
+ export interface SchemaField {
58
+ display_name: string;
59
+ type: string;
60
+ data_category: string;
61
+ required: boolean;
62
+ owned_by: string;
63
+ user_visible: boolean;
64
+ revoke_after: string;
65
+ required_retention: string;
66
+ collection_justification: string;
67
+ opt_out_warning: string;
68
+ }
69
+
70
+ interface AppConfig {
71
+ customizations: {
72
+ primary_color: string;
73
+ };
74
+ default_user_id_format?: string;
75
+ hub: {
76
+ auth: {
77
+ allow_unverified_users?: boolean;
78
+ additional_fields: [
79
+ {
80
+ name: string;
81
+ type: string;
82
+ label: string;
83
+ placeholder?: string;
84
+ options: [
85
+ {
86
+ value: string;
87
+ label: string;
88
+ }
89
+ ];
90
+ }
91
+ ];
92
+ email: {
93
+ from_address: string;
94
+ image: string;
95
+ };
96
+ show_app_icon: boolean;
97
+ };
98
+ customizations: HubCustomizations;
99
+ };
100
+ }
101
+
102
+ export interface HubCustomizations {
103
+ rounded_corners: boolean;
104
+ primary_color: string;
105
+ placement: 'bottom-left' | 'hidden';
106
+ offset_x: number;
107
+ offset_y: number;
108
+ property_overrides: Record<string, string>;
109
+ }
110
+
111
+ type ContextProps = {
112
+ config: IConfig;
113
+ };
114
+
115
+ export const GlobalContext = createContext<
116
+ { state: GlobalState; dispatch: Dispatch } | undefined
117
+ >(undefined);
118
+
119
+ function handleStateInit(initialState: GlobalState) {
120
+ if (storage.contains('state')) {
121
+ const state = JSON.parse(storage.getString('state') || '{}');
122
+
123
+ return {
124
+ ...initialState,
125
+ ...state,
126
+ };
127
+ }
128
+
129
+ return initialState;
130
+ }
131
+
132
+ // async function updateStorage(newState: any) {
133
+ // const oldState = JSON.parse(await storage.getItem('state') || '{}');
134
+
135
+ // if (!isEqual(oldState, newState)) {
136
+ // console.log('writing new state', newState);
137
+ // await storage.setItem('state', JSON.stringify(newState));
138
+ // }
139
+ // }
140
+
141
+ const GlobalContextProvider: FunctionComponent<ContextProps> = ({
142
+ children,
143
+ config,
144
+ }) => {
145
+ const initialState: GlobalState = {
146
+ is_initializing: false,
147
+ is_container_visible: false,
148
+ use_modal: false,
149
+ nav: {
150
+ current_route: '/',
151
+ route_trigger: '',
152
+ event_id: '',
153
+ section: '',
154
+ options: {},
155
+ },
156
+ user: {
157
+ data: {
158
+ email: null,
159
+ },
160
+ needs_refresh: false,
161
+ redacted: [],
162
+ },
163
+ auth: {
164
+ access_token: null,
165
+ refresh_token: null,
166
+ app_id: null,
167
+ },
168
+ app: {
169
+ schema: null,
170
+ config: null,
171
+ },
172
+ local_acls: null,
173
+ is_saving_user_data: false,
174
+ config,
175
+ };
176
+
177
+ // TODO: There's a better way to do this where we have a set of rules that watch/apply to the state as it changes
178
+ // function dispatchExternalEvents(prevState: GlobalState, nextState: GlobalState) {
179
+
180
+ // // Log in, get new token, load previous auth state, etc
181
+ // if (prevState.auth.access_token !== nextState.auth.access_token) {
182
+ // events.dispatch(EventType.AUTH, {
183
+ // access_token: nextState.auth.access_token,
184
+ // user_id: nextState.user.data.id,
185
+ // app_id: nextState.auth.app_id,
186
+ // });
187
+ // }
188
+
189
+ // // User data changes. Also, fire the event when ACLs change since this affects the data
190
+ // // that the application can see.
191
+ // if (!isEqual(prevState.local_acls, nextState.local_acls) ||
192
+ // !isEqual(prevState.user.data, nextState.user.data)) {
193
+ // events.dispatch(EventType.USER_DATA, {
194
+ // // The data is filtered on the local_acls
195
+ // data: redactUserDataWithAcls(nextState.user.data, nextState.local_acls),
196
+ // });
197
+ // }
198
+
199
+ // // Log out
200
+ // if (nextState.auth.access_token === null) {
201
+ // events.dispatch(EventType.SIGN_OUT, {});
202
+ // }
203
+ // }
204
+
205
+ function mainReducer(state: GlobalState, action: TAction): GlobalState {
206
+ let decodedToken: any;
207
+
208
+ let newState;
209
+ // let cachedAuth;
210
+ switch (action.type) {
211
+ case ActionType.SET_CONTAINER_VISIBLE:
212
+ newState = {
213
+ ...state,
214
+ is_container_visible: action.payload.isVisible,
215
+ use_modal:
216
+ action.payload.isVisible === false ? false : state.use_modal,
217
+ nav: {
218
+ ...state.nav,
219
+ current_route: '/',
220
+ },
221
+ };
222
+ break;
223
+
224
+ case ActionType.CHANGE_ROUTE:
225
+ newState = {
226
+ ...state,
227
+ nav: {
228
+ ...state.nav,
229
+ current_route: action.payload.route,
230
+ route_trigger: action.payload.trigger || '',
231
+ event_id: action.payload.event_id,
232
+ options: action.payload.opts,
233
+ },
234
+ };
235
+
236
+ break;
237
+
238
+ case ActionType.SET_SECTION:
239
+ newState = {
240
+ ...state,
241
+ nav: {
242
+ ...state.nav,
243
+ section: action.payload.section,
244
+ },
245
+ };
246
+ break;
247
+
248
+ case ActionType.LOGIN_SUCCESS:
249
+ // storage.setItem('auth', JSON.stringify(action.payload));
250
+ decodedToken = jwt_decode(action.payload.access_token);
251
+
252
+ // Ensure this token is for this app
253
+ if (action.payload.app_id !== state.app.id) {
254
+ return {
255
+ ...state,
256
+ };
257
+ }
258
+
259
+ newState = {
260
+ ...state,
261
+ auth: {
262
+ ...state.auth,
263
+ access_token: action.payload.access_token,
264
+ refresh_token: action.payload.refresh_token,
265
+ app_id: action.payload.app_id,
266
+ is_verified_user:
267
+ decodedToken?.['https://auth.rownd.io/is_verified_user'] !==
268
+ false, // default is `true` if the attribute doesn't exist
269
+ },
270
+ user: {
271
+ ...state.user,
272
+ data: {
273
+ ...state.user.data,
274
+ id: action.payload.app_user_id,
275
+ },
276
+ },
277
+ };
278
+ break;
279
+
280
+ case ActionType.SIGN_OUT:
281
+ // storage.removeItem('auth');
282
+ newState = {
283
+ ...state,
284
+ user: {
285
+ data: {
286
+ email: null,
287
+ },
288
+ redacted: [],
289
+ },
290
+ auth: {
291
+ access_token: null,
292
+ refresh_token: null,
293
+ app_id: null,
294
+ },
295
+ };
296
+ break;
297
+
298
+ case ActionType.REFRESH_TOKEN:
299
+ newState = {
300
+ ...state,
301
+ auth: {
302
+ ...state.auth,
303
+ access_token: action.payload.access_token,
304
+ refresh_token: action.payload.refresh_token,
305
+ },
306
+ };
307
+
308
+ // cachedAuth = storage.getItem('auth');
309
+ // if (cachedAuth) {
310
+ // const cachedAuthObj = JSON.parse(cachedAuth);
311
+ // cachedAuth = {
312
+ // ...cachedAuthObj,
313
+ // ...newState.auth,
314
+ // };
315
+ // storage.setItem('auth', JSON.stringify(newState.auth));
316
+ // }
317
+
318
+ break;
319
+
320
+ case ActionType.LOAD_USER:
321
+ newState = {
322
+ ...state,
323
+ user: {
324
+ ...state.user,
325
+ data: {
326
+ ...action.payload.data,
327
+ },
328
+ redacted: action.payload.redacted,
329
+ },
330
+ };
331
+ break;
332
+
333
+ case ActionType.UPDATE_LOCAL_ACLS:
334
+ newState = {
335
+ ...state,
336
+ local_acls: {
337
+ ...state.local_acls,
338
+ ...action.payload,
339
+ },
340
+ };
341
+ break;
342
+
343
+ case ActionType.SET_USER_DATA_FIELD:
344
+ // Dispatch a USER_DATA_SAVED event to satisfy event listeners when the data
345
+ // was not changed and no request to Rownd was ever made.
346
+ if (state.user.data[action.payload.field] === action.payload.value) {
347
+ events.dispatch(EventType.USER_DATA_SAVED, state.user.data);
348
+ }
349
+
350
+ newState = {
351
+ ...state,
352
+ user: {
353
+ ...state.user,
354
+ data: {
355
+ ...state.user.data,
356
+ [action.payload.field]: action.payload.value,
357
+ },
358
+ },
359
+ };
360
+ break;
361
+
362
+ case ActionType.SET_USER_DATA:
363
+ // Dispatch a USER_DATA_SAVED event to satisfy event listeners when the data
364
+ // was not changed and no request to Rownd was ever made.
365
+ if (
366
+ isEqual(
367
+ pick(state.user.data, Object.keys(action.payload.data)),
368
+ action.payload.data
369
+ )
370
+ ) {
371
+ events.dispatch(EventType.USER_DATA_SAVED, state.user.data);
372
+ }
373
+
374
+ newState = {
375
+ ...state,
376
+ user: {
377
+ ...state.user,
378
+ data: {
379
+ ...state.user.data,
380
+ ...action.payload.data,
381
+ },
382
+ },
383
+ };
384
+ break;
385
+
386
+ case ActionType.SET_REFRESH_USER_DATA:
387
+ newState = {
388
+ ...state,
389
+ user: {
390
+ ...state.user,
391
+ needs_refresh: action.payload.needs_refresh,
392
+ },
393
+ };
394
+ break;
395
+
396
+ case ActionType.LOAD_STATE:
397
+ newState = {
398
+ ...action.payload,
399
+ };
400
+ break;
401
+
402
+ case ActionType.SET_IS_SAVING_USER_DATA: {
403
+ newState = {
404
+ ...state,
405
+ is_saving_user_data: action.payload.saving,
406
+ };
407
+ break;
408
+ }
409
+
410
+ case ActionType.SET_APP_CONFIG:
411
+ newState = {
412
+ ...state,
413
+ app: {
414
+ ...state.app,
415
+ ...action.payload,
416
+ },
417
+ };
418
+ break;
419
+
420
+ default:
421
+ newState = state;
422
+ }
423
+
424
+ // Write state to local storage, minus a few fields
425
+ const persistedState: any = { ...newState };
426
+ delete persistedState.config;
427
+ delete persistedState.nav;
428
+ delete persistedState.is_container_visible;
429
+ delete persistedState.use_modal;
430
+ delete persistedState.is_initializing;
431
+ delete persistedState.is_saving_user_data;
432
+
433
+ // updateStorage(persistedState);
434
+ storage.set('state', JSON.stringify(persistedState));
435
+
436
+ // Fire any events that depend on state updates
437
+ // dispatchExternalEvents(state, newState);
438
+
439
+ return newState;
440
+ }
441
+
442
+ const [state, dispatch] = useReducer(
443
+ mainReducer,
444
+ initialState,
445
+ handleStateInit
446
+ );
447
+
448
+ // Async load cached state from storage
449
+ // useEffect(() => {
450
+ // (async () => {
451
+ // const existingStateStr = await storage.getItem('state');
452
+
453
+ // if (!existingStateStr) {
454
+ // return;
455
+ // }
456
+
457
+ // dispatch({
458
+ // type: ActionType.LOAD_STATE,
459
+ // payload: JSON.parse(existingStateStr),
460
+ // });
461
+ // });
462
+ // }, []);
463
+
464
+ const value = { state, dispatch };
465
+ return (
466
+ <GlobalContext.Provider value={value}>
467
+ {children}
468
+ {/* <ExternalApi config={config} dispatchEvents={(state: GlobalState) => dispatchExternalEvents(initialState, state)} /> */}
469
+ </GlobalContext.Provider>
470
+ );
471
+ };
472
+
473
+ function useGlobalContext() {
474
+ const context = useContext(GlobalContext);
475
+
476
+ if (context === undefined) {
477
+ throw new Error(
478
+ 'useGlobalContext must be used within a GlobalContext Provider'
479
+ );
480
+ }
481
+
482
+ return context;
483
+ }
484
+
485
+ export { GlobalContextProvider, useGlobalContext };
@@ -0,0 +1,21 @@
1
+ import React from 'react';
2
+ import { useDeviceContext } from 'twrnc';
3
+
4
+ import tw from '../utils/tailwind';
5
+ import { SignIn } from './SignIn';
6
+ import { AutoSigninDialog } from './AutoSigninDialog';
7
+ import { useGlobalContext } from './GlobalContext';
8
+
9
+ export function RowndComponents() {
10
+ const { state } = useGlobalContext();
11
+ useDeviceContext(tw);
12
+
13
+ return (
14
+ <>
15
+ {state.nav.current_route === '/account/login' && <SignIn />}
16
+ {state.nav.current_route === '/account/auto-signin' && (
17
+ <AutoSigninDialog />
18
+ )}
19
+ </>
20
+ );
21
+ }
@@ -0,0 +1,56 @@
1
+ import React from 'react';
2
+ import { View, StyleSheet } from 'react-native';
3
+ import { GlobalContextProvider } from './GlobalContext';
4
+ import { DefaultContext } from './DefaultContext';
5
+ import { createConfig } from '../utils/config';
6
+ import { RowndComponents } from './RowndComponents';
7
+ import { BottomSheetModalProvider } from '@gorhom/bottom-sheet';
8
+
9
+ // const RowndContext = createContext<TRowndContext | undefined>(undefined);
10
+
11
+ interface IRowndProviderProps {
12
+ appKey: string;
13
+ apiUrl?: string;
14
+ children: React.ReactNode;
15
+ }
16
+
17
+ export function RowndProvider({
18
+ appKey,
19
+ apiUrl,
20
+ children,
21
+ }: IRowndProviderProps) {
22
+ // const [isSigningIn, setIsSigningIn] = useState<boolean>(false);
23
+
24
+ // const requestSignIn = useRef(function () {
25
+ // setIsSigningIn(true);
26
+ // });
27
+
28
+ // const [rowndState, setRowndState] = useState<any>({
29
+ // requestSignIn: requestSignIn.current,
30
+ // });
31
+
32
+ const config = createConfig({
33
+ appKey,
34
+ apiUrl,
35
+ });
36
+
37
+ return (
38
+ <GlobalContextProvider config={config}>
39
+ <DefaultContext config={config} />
40
+ <BottomSheetModalProvider>
41
+ <View style={styles.container}>
42
+ <>
43
+ {children}
44
+ <RowndComponents />
45
+ </>
46
+ </View>
47
+ </BottomSheetModalProvider>
48
+ </GlobalContextProvider>
49
+ );
50
+ }
51
+
52
+ const styles = StyleSheet.create({
53
+ container: {
54
+ flex: 1,
55
+ },
56
+ });