-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathApp.js
92 lines (76 loc) · 3.14 KB
/
App.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
/**
* React Native App
* https://github.com/facebook/react-native
*
* @format
* @flow
* @lint-ignore-every XPLATJSCOPYRIGHT1
*/
import React, { Component } from 'react';
import { StatusBar, Alert } from 'react-native';
import { Provider } from 'react-redux';
import { StyleProvider } from 'native-base';
import AwareManager from './crossplatform-model/native-db/AwareManager';
import { store } from './crossplatform-model/memory-db';
import { getTheme } from './crossplatform-theme/';
import Router from './crossplatform-components/Router';
import { triggerUpdateIfNeeded } from './Updater.js';
// -- About routing
//
// @note *We do not use router*, instead we only use redux to avoid having
// multiple source of thruth, as we've faced the same challenges
// referenced in
// `https://stackoverflow.com/questions/48893490/react-router-vs-redux-first-routing`
// in a previous version of the source code. We use a framework similar
// to the one mentioned in this article
// `https://medium.freecodecamp.org/an-introduction-to-the-redux-first-routing-model-98926ebf53cb`,
// although no the same one, as the one we use has a higher community
// spread & is compatible with react-native such as it doesn't
// necessarily rely on browser history, but can rely on mobile native
// mechanism for backward/forward navigation instead. See
// `https://github.com/respond-framework/rudy/blob/master/packages/rudy/docs/react-native.md`.
//
// @warning Rudy's documentation (the redux router) is partly out of date.
// -- About theme and components
//
// @note We use native-base-theme library modified to use iOS style theme on
// both android & ios. The native-base-theme's theme is located in the
// `./crossplatform/theme` folder.
type Props = {};
export default class App extends Component<Props> {
render() {
return (
<StyleProvider style={getTheme()}>
<Provider store={store}>
<StatusBar backgroundColor="#FAFAFA" barStyle="dark-content" />
<Router></Router>
</Provider>
</StyleProvider>
);
}
}
// @note `AwareManager.startAware()` is set in the StudySchemaAdapter
// @todo rename StudySchemaAdapter to InitAppSchemaAdapter.
// Add aware-related debugging tools to dev menu
if (__DEV__ || !__DEV__) {
const DevMenu = require('react-native-dev-menu');
DevMenu.addItem('aware: device id', async () => {
let deviceId = await AwareManager.getDeviceId();
Alert.alert(
'AWARE Device ID',
deviceId,
[
{ text: 'OK' },
],
);
});
DevMenu.addItem('aware: sync', () => AwareManager.syncData());
}
// Check environment variables.
if (typeof process.env.FLUX_ENCRYPTION_KEY === 'undefined') {
throw new Error('FLUX_ENCRYPTION_KEY must be set! Don\'t forget to flush cache (`react-native start --reset-cache`)!');
}
// Automatically update the app when released
if (typeof process.env.FLUX_AUTO_UPDATE !== 'undefined' && process.env.FLUX_AUTO_UPDATE == true) {
triggerUpdateIfNeeded();
}