-
Notifications
You must be signed in to change notification settings - Fork 2.8k
/
index.js
59 lines (52 loc) · 2.75 KB
/
index.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
import {I18nManager} from 'react-native';
import Onyx from 'react-native-onyx';
import intlPolyfill from '@libs/IntlPolyfill';
import * as Metrics from '@libs/Metrics';
import * as Device from '@userActions/Device';
import exposeGlobalMemoryOnlyKeysMethods from '@userActions/MemoryOnlyKeys/exposeGlobalMemoryOnlyKeysMethods';
import CONST from '@src/CONST';
import ONYXKEYS from '@src/ONYXKEYS';
import platformSetup from './platformSetup';
export default function () {
/*
* Initialize the Onyx store when the app loads for the first time.
*
* Note: This Onyx initialization has been very intentionally placed completely outside of the React lifecycle of the main App component.
*
* To understand why we must do this, you must first understand that a typical React Native Android application consists of an Application and an Activity.
* The project root's index.js runs in the Application, but the main RN `App` component + UI runs in a separate Activity, spawned when you call AppRegistry.registerComponent.
* When an application launches in a headless JS context (i.e: when woken from a killed state by a push notification), only the Application is available, but not the UI Activity.
* This means that in a headless context NO REACT CODE IS EXECUTED, and none of your components will mount.
*
* However, we still need to use Onyx to update the underlying app data from the headless JS context.
* Therefore it must be initialized completely outside the React component lifecycle.
*/
Onyx.init({
keys: ONYXKEYS,
// Increase the cached key count so that the app works more consistently for accounts with large numbers of reports
maxCachedKeysCount: 10000,
safeEvictionKeys: [ONYXKEYS.COLLECTION.REPORT_ACTIONS],
captureMetrics: Metrics.canCaptureOnyxMetrics(),
initialKeyStates: {
// Clear any loading and error messages so they do not appear on app startup
[ONYXKEYS.SESSION]: {loading: false},
[ONYXKEYS.ACCOUNT]: CONST.DEFAULT_ACCOUNT_DATA,
[ONYXKEYS.NETWORK]: {isOffline: false},
[ONYXKEYS.IS_SIDEBAR_LOADED]: false,
[ONYXKEYS.SHOULD_SHOW_COMPOSE_INPUT]: true,
[ONYXKEYS.MODAL]: {
isVisible: false,
willAlertModalBecomeVisible: false,
},
},
});
exposeGlobalMemoryOnlyKeysMethods();
Device.setDeviceID();
// Force app layout to work left to right because our design does not currently support devices using this mode
I18nManager.allowRTL(false);
I18nManager.forceRTL(false);
// Polyfill the Intl API if locale data is not as expected
intlPolyfill();
// Perform any other platform-specific setup
platformSetup();
}