-
Notifications
You must be signed in to change notification settings - Fork 2.9k
/
AuthScreens.js
331 lines (306 loc) · 13.5 KB
/
AuthScreens.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
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
import React from 'react';
import Onyx, {withOnyx} from 'react-native-onyx';
import moment from 'moment';
import _ from 'underscore';
import lodashGet from 'lodash/get';
import * as StyleUtils from '../../../styles/StyleUtils';
import withWindowDimensions, {windowDimensionsPropTypes} from '../../../components/withWindowDimensions';
import CONST from '../../../CONST';
import compose from '../../compose';
import * as PersonalDetails from '../../actions/PersonalDetails';
import * as Pusher from '../../Pusher/pusher';
import PusherConnectionManager from '../../PusherConnectionManager';
import UnreadIndicatorUpdater from '../../UnreadIndicatorUpdater';
import ROUTES from '../../../ROUTES';
import ONYXKEYS from '../../../ONYXKEYS';
import Timing from '../../actions/Timing';
import NetworkConnection from '../../NetworkConnection';
import CONFIG from '../../../CONFIG';
import KeyboardShortcut from '../../KeyboardShortcut';
import Navigation from '../Navigation';
import * as User from '../../actions/User';
import * as Modal from '../../actions/Modal';
import modalCardStyleInterpolator from './modalCardStyleInterpolator';
import createCustomModalStackNavigator from './createCustomModalStackNavigator';
// Modal Stack Navigators
import * as ModalStackNavigators from './ModalStackNavigators';
import SCREENS from '../../../SCREENS';
import defaultScreenOptions from './defaultScreenOptions';
import * as App from '../../actions/App';
import * as Session from '../../actions/Session';
let currentUserEmail;
Onyx.connect({
key: ONYXKEYS.SESSION,
callback: (val) => {
// When signed out, val is undefined
if (!val) {
return;
}
currentUserEmail = val.email;
},
});
Onyx.connect({
key: ONYXKEYS.PERSONAL_DETAILS,
callback: (val) => {
if (!val) {
return;
}
const timezone = lodashGet(val, [currentUserEmail, 'timezone'], {});
const currentTimezone = moment.tz.guess(true);
// If the current timezone is different than the user's timezone, and their timezone is set to automatic
// then update their timezone.
if (_.isObject(timezone) && timezone.automatic && timezone.selected !== currentTimezone) {
timezone.selected = currentTimezone;
PersonalDetails.setPersonalDetails({timezone});
}
},
});
const RootStack = createCustomModalStackNavigator();
// We want to delay the re-rendering for components(e.g. ReportActionCompose)
// that depends on modal visibility until Modal is completely closed and its focused
// When modal screen is focused, update modal visibility in Onyx
// https://reactnavigation.org/docs/navigation-events/
const modalScreenListeners = {
focus: () => {
Modal.setModalVisibility(true);
},
beforeRemove: () => {
Modal.setModalVisibility(false);
},
};
const propTypes = {
...windowDimensionsPropTypes,
};
class AuthScreens extends React.Component {
constructor(props) {
super(props);
Timing.start(CONST.TIMING.HOMEPAGE_INITIAL_RENDER);
Timing.start(CONST.TIMING.HOMEPAGE_REPORTS_LOADED);
}
componentDidMount() {
NetworkConnection.listenForReconnect();
NetworkConnection.onReconnect(() => App.reconnectApp());
PusherConnectionManager.init();
Pusher.init({
appKey: CONFIG.PUSHER.APP_KEY,
cluster: CONFIG.PUSHER.CLUSTER,
authEndpoint: `${CONFIG.EXPENSIFY.URL_API_ROOT}api?command=AuthenticatePusher`,
}).then(() => {
User.subscribeToUserEvents();
});
// Listen for report changes and fetch some data we need on initialization
UnreadIndicatorUpdater.listenForReportChanges();
App.openApp();
App.setUpPoliciesAndNavigate(this.props.session);
Timing.end(CONST.TIMING.HOMEPAGE_INITIAL_RENDER);
const searchShortcutConfig = CONST.KEYBOARD_SHORTCUTS.SEARCH;
const groupShortcutConfig = CONST.KEYBOARD_SHORTCUTS.NEW_GROUP;
// Listen for the key K being pressed so that focus can be given to
// the chat switcher, or new group chat
// based on the key modifiers pressed and the operating system
this.unsubscribeSearchShortcut = KeyboardShortcut.subscribe(searchShortcutConfig.shortcutKey, () => {
Navigation.navigate(ROUTES.SEARCH);
}, searchShortcutConfig.descriptionKey, searchShortcutConfig.modifiers, true);
this.unsubscribeGroupShortcut = KeyboardShortcut.subscribe(groupShortcutConfig.shortcutKey, () => {
Navigation.navigate(ROUTES.NEW_GROUP);
}, groupShortcutConfig.descriptionKey, groupShortcutConfig.modifiers, true);
}
shouldComponentUpdate(nextProps) {
return nextProps.isSmallScreenWidth !== this.props.isSmallScreenWidth;
}
componentWillUnmount() {
if (this.unsubscribeSearchShortcut) {
this.unsubscribeSearchShortcut();
}
if (this.unsubscribeGroupShortcut) {
this.unsubscribeGroupShortcut();
}
Session.cleanupSession();
clearInterval(this.interval);
this.interval = null;
}
render() {
const commonModalScreenOptions = {
headerShown: false,
gestureDirection: 'horizontal',
animationEnabled: true,
// This option is required to make previous screen visible underneath the modal screen
// https://reactnavigation.org/docs/6.x/stack-navigator#transparent-modals
presentation: 'transparentModal',
};
const modalScreenOptions = {
...commonModalScreenOptions,
cardStyle: StyleUtils.getNavigationModalCardStyle(this.props.isSmallScreenWidth),
cardStyleInterpolator: props => modalCardStyleInterpolator(this.props.isSmallScreenWidth, false, props),
cardOverlayEnabled: true,
// This is a custom prop we are passing to custom navigator so that we will know to add a Pressable overlay
// when displaying a modal. This allows us to dismiss by clicking outside on web / large screens.
isModal: true,
};
return (
<RootStack.Navigator
mode="modal"
// We are disabling the default keyboard handling here since the automatic behavior is to close a
// keyboard that's open when swiping to dismiss a modal. In those cases, pressing the back button on
// a header will briefly open and close the keyboard and crash Android.
// eslint-disable-next-line react/jsx-props-no-multi-spaces
keyboardHandlingEnabled={false}
>
{/* The MainDrawerNavigator contains the SidebarScreen and ReportScreen */}
<RootStack.Screen
name={SCREENS.HOME}
options={{
headerShown: false,
title: 'New Expensify',
// prevent unnecessary scrolling
cardStyle: {
overflow: 'hidden',
height: '100%',
},
}}
getComponent={() => {
const MainDrawerNavigator = require('./MainDrawerNavigator').default;
return MainDrawerNavigator;
}}
/>
<RootStack.Screen
name="ValidateLogin"
options={{
headerShown: false,
title: 'New Expensify',
}}
getComponent={() => {
const ValidateLoginPage = require('../../../pages/ValidateLoginPage').default;
return ValidateLoginPage;
}}
/>
<RootStack.Screen
name={SCREENS.TRANSITION_FROM_OLD_DOT}
options={defaultScreenOptions}
getComponent={() => {
const LogOutPreviousUserPage = require('../../../pages/LogOutPreviousUserPage').default;
return LogOutPreviousUserPage;
}}
/>
<RootStack.Screen
name="Concierge"
options={defaultScreenOptions}
getComponent={() => {
const ConciergePage = require('../../../pages/ConciergePage').default;
return ConciergePage;
}}
/>
{/* These are the various modal routes */}
{/* Note: Each modal must have it's own stack navigator since we want to be able to navigate to any
modal subscreens e.g. `/settings/profile` and this will allow us to navigate while inside the modal. We
are also using a custom navigator on web so even if a modal does not have any subscreens it still must
use a navigator */}
<RootStack.Screen
name="Settings"
options={modalScreenOptions}
component={ModalStackNavigators.SettingsModalStackNavigator}
listeners={modalScreenListeners}
/>
<RootStack.Screen
name="NewChat"
options={modalScreenOptions}
component={ModalStackNavigators.NewChatModalStackNavigator}
listeners={modalScreenListeners}
/>
<RootStack.Screen
name="NewGroup"
options={modalScreenOptions}
component={ModalStackNavigators.NewGroupModalStackNavigator}
listeners={modalScreenListeners}
/>
<RootStack.Screen
name="Search"
options={modalScreenOptions}
component={ModalStackNavigators.SearchModalStackNavigator}
listeners={modalScreenListeners}
/>
<RootStack.Screen
name="Details"
options={modalScreenOptions}
component={ModalStackNavigators.DetailsModalStackNavigator}
listeners={modalScreenListeners}
/>
<RootStack.Screen
name="Report_Details"
options={modalScreenOptions}
component={ModalStackNavigators.ReportDetailsModalStackNavigator}
listeners={modalScreenListeners}
/>
<RootStack.Screen
name="Report_Settings"
options={modalScreenOptions}
component={ModalStackNavigators.ReportSettingsModalStackNavigator}
listeners={modalScreenListeners}
/>
<RootStack.Screen
name="Participants"
options={modalScreenOptions}
component={ModalStackNavigators.ReportParticipantsModalStackNavigator}
listeners={modalScreenListeners}
/>
<RootStack.Screen
name="IOU_Request"
options={modalScreenOptions}
component={ModalStackNavigators.IOURequestModalStackNavigator}
listeners={modalScreenListeners}
/>
<RootStack.Screen
name="IOU_Bill"
options={modalScreenOptions}
component={ModalStackNavigators.IOUBillStackNavigator}
listeners={modalScreenListeners}
/>
<RootStack.Screen
name="EnablePayments"
options={modalScreenOptions}
component={ModalStackNavigators.EnablePaymentsStackNavigator}
listeners={modalScreenListeners}
/>
<RootStack.Screen
name="IOU_Details"
options={modalScreenOptions}
component={ModalStackNavigators.IOUDetailsModalStackNavigator}
listeners={modalScreenListeners}
/>
<RootStack.Screen
name="AddPersonalBankAccount"
options={modalScreenOptions}
component={ModalStackNavigators.AddPersonalBankAccountModalStackNavigator}
listeners={modalScreenListeners}
/>
<RootStack.Screen
name="RequestCall"
options={modalScreenOptions}
component={ModalStackNavigators.RequestCallModalStackNavigator}
listeners={modalScreenListeners}
/>
<RootStack.Screen
name="IOU_Send"
options={modalScreenOptions}
component={ModalStackNavigators.IOUSendModalStackNavigator}
listeners={modalScreenListeners}
/>
<RootStack.Screen
name="Wallet_Statement"
options={modalScreenOptions}
component={ModalStackNavigators.WalletStatementStackNavigator}
listeners={modalScreenListeners}
/>
</RootStack.Navigator>
);
}
}
AuthScreens.propTypes = propTypes;
export default compose(
withWindowDimensions,
withOnyx({
session: {
key: ONYXKEYS.SESSION,
},
}),
)(AuthScreens);