This repository has been archived by the owner on Jun 15, 2022. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 110
/
App.js
203 lines (171 loc) · 5.88 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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
import React, {Component} from 'react';
import { View, Text } from "react-native";
import { Client } from 'bugsnag-react-native';
import { createStackNavigator, createAppContainer, createDrawerNavigator, DrawerActions, NavigationActions } from "react-navigation";
import KeysManager from './lib/keysManager'
import StyleKit from "./style/StyleKit"
import ApplicationState from "@Lib/ApplicationState"
import Auth from './lib/sfjs/authManager'
import ModelManager from './lib/sfjs/modelManager'
import PrivilegesManager from '@SFJS/privilegesManager'
import MigrationManager from "@SFJS/migrationManager"
import Sync from './lib/sfjs/syncManager'
import Storage from './lib/sfjs/storageManager'
import ReviewManager from './lib/reviewManager'
import Compose from "@Screens/Compose"
import Splash from "@Screens/Splash"
import Root from "@Screens/Root"
import MainSideMenu from "@SideMenu/MainSideMenu"
import NoteSideMenu from "@SideMenu/NoteSideMenu"
import Settings from "@Screens/Settings/Settings"
import InputModal from "@Screens/InputModal"
import ManagePrivileges from "@Screens/ManagePrivileges"
import Authenticate from "@Screens/Authentication/Authenticate"
import KeyRecovery from "@Screens/KeyRecovery"
import SideMenuManager from "@SideMenu/SideMenuManager"
if(__DEV__ === false) {
const bugsnag = new Client()
// Disable console.log for non-dev builds
console.log = () => {};
}
const AppStack = createStackNavigator({
Notes: {screen: Root},
Compose: {screen: Compose},
}, {
initialRouteName: 'Notes'
})
AppStack.navigationOptions = ({ navigation }) => {
return {drawerLockMode: SideMenuManager.get().isRightSideMenuLocked() ? "locked-closed" : null}
};
const AppDrawerStack = createDrawerNavigator({
Main: AppStack
}, {
contentComponent: ({ navigation }) => (
<NoteSideMenu ref={(ref) => {SideMenuManager.get().setRightSideMenuReference(ref)}} navigation={navigation} />
),
drawerPosition: "right",
drawerType: 'slide',
getCustomActionCreators: (route, stateKey) => {
return {
openRightDrawer: () => DrawerActions.openDrawer({ key: stateKey }),
closeRightDrawer: () => DrawerActions.closeDrawer({ key: stateKey }),
lockRightDrawer: (lock) => {
// this is the key part
SideMenuManager.get().setLockedForRightSideMenu(lock);
// We have to return something
return NavigationActions.setParams({params: { dummy: true }, key: route.key})
}
};
},
})
const SettingsStack = createStackNavigator({
Screen1: Settings
})
const InputModalStack = createStackNavigator({
Screen1: InputModal
})
const AuthenticateModalStack = createStackNavigator({
Screen1: Authenticate
})
const ManagePrivilegesStack = createStackNavigator({
Screen1: ManagePrivileges
})
const KeyRecoveryStack = createStackNavigator({
Screen1: KeyRecovery
})
const SplashStack = createStackNavigator({
Screen1: Splash
})
const AppDrawer = createStackNavigator({
Home: AppDrawerStack,
Settings: SettingsStack,
InputModal: InputModalStack,
Authenticate: AuthenticateModalStack,
ManagePrivileges: ManagePrivilegesStack,
KeyRecovery: KeyRecoveryStack,
Splash: {
screen: Splash,
navigationOptions: {
gesturesEnabled: false,
},
}
}, {
mode: "modal",
headerMode: 'none',
})
AppDrawer.navigationOptions = ({ navigation }) => {
return {
drawerLockMode: SideMenuManager.get().isLeftSideMenuLocked() ? "locked-closed" : null,
}
};
const DrawerStack = createDrawerNavigator({
Main: AppDrawer,
}, {
contentComponent: ({ navigation }) => (
<MainSideMenu ref={(ref) => {SideMenuManager.get().setLeftSideMenuReference(ref)}} navigation={navigation} />
),
drawerPosition: "left",
drawerType: 'slide',
getCustomActionCreators: (route, stateKey) => {
return {
openLeftDrawer: () => DrawerActions.openDrawer({ key: stateKey }),
closeLeftDrawer: () => DrawerActions.closeDrawer({ key: stateKey }),
lockLeftDrawer: (lock) => {
// this is the key part
SideMenuManager.get().setLockedForLeftSideMenu(lock)
// We have to return something
return NavigationActions.setParams({params: { dummy: true }, key: route.key})
}
};
},
});
const AppContainer = createAppContainer(DrawerStack);
export default class App extends Component {
constructor(props) {
super(props);
KeysManager.get().registerAccountRelatedStorageKeys(["options"]);
// Initialize iOS review manager. Will automatically handle requesting review logic.
ReviewManager.initialize();
PrivilegesManager.get().loadPrivileges();
MigrationManager.get().load();
// Listen to sign out event
this.authEventHandler = Auth.get().addEventHandler(async (event) => {
if(event == SFAuthManager.DidSignOutEvent) {
ModelManager.get().handleSignout();
await Sync.get().handleSignout();
}
});
this.state = {ready: false};
this.loadInitialData();
}
/*
We initially didn't expect App to ever unmount. However, on Android, if you are in the root screen,
and press the physical back button, then strangely, App unmounts, but other components, like Notes, do not.
We've remedied this by modifiying Android back button behavior natively to background instead of quit, but we keep this below anyway.
*/
componentWillUnmount() {
Auth.get().removeEventHandler(this.authEventHandler);
}
async loadInitialData() {
await StyleKit.get().resolveInitialTheme();
await KeysManager.get().loadInitialData();
let ready = () => {
KeysManager.get().markApplicationAsRan();
ApplicationState.get().receiveApplicationStartEvent();
this.setState({ready: true});
}
if(await KeysManager.get().needsWipe()) {
KeysManager.get().wipeData().then(ready).catch(ready);
} else {
ready();
}
}
render() {
if(!this.state.ready) {
return null;
}
return (
<AppContainer /* persistenceKey="if-you-want-it" */ />
)
}
}