-
Notifications
You must be signed in to change notification settings - Fork 3k
/
Copy pathindex.js
47 lines (43 loc) · 2.33 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
import {I18nManager} from 'react-native';
import Onyx from 'react-native-onyx';
import ONYXKEYS from '../ONYXKEYS';
import CONST from '../CONST';
import platformSetup from './platformSetup';
import * as Metrics from '../libs/Metrics';
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,
safeEvictionKeys: [ONYXKEYS.COLLECTION.REPORT_ACTIONS],
keysToDisableSyncEvents: [ONYXKEYS.CURRENTLY_VIEWED_REPORTID],
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.IOU]: {
loading: false, error: false, creatingIOUTransaction: false, isRetrievingCurrency: false,
},
[ONYXKEYS.IS_SIDEBAR_LOADED]: false,
[ONYXKEYS.SHOULD_SHOW_COMPOSE_INPUT]: true,
},
});
// 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);
// Perform any other platform-specific setup
platformSetup();
}