-
Notifications
You must be signed in to change notification settings - Fork 3k
/
Copy pathAuthScreens.js
322 lines (294 loc) · 12.3 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
import React from 'react';
import Onyx, {withOnyx} from 'react-native-onyx';
import PropTypes from 'prop-types';
import moment from 'moment';
import _ from 'underscore';
import lodashGet from 'lodash/get';
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 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 * as Report from '../../actions/Report';
import modalCardStyleInterpolator from './modalCardStyleInterpolator';
import createResponsiveStackNavigator from './createResponsiveStackNavigator';
import SCREENS from '../../../SCREENS';
import defaultScreenOptions from './defaultScreenOptions';
import * as App from '../../actions/App';
import * as Download from '../../actions/Download';
import * as Session from '../../actions/Session';
import RightModalNavigator from './Navigators/RightModalNavigator';
import CentralPaneNavigator from './Navigators/CentralPaneNavigator';
import NAVIGATORS from '../../../NAVIGATORS';
import FullScreenNavigator from './Navigators/FullScreenNavigator';
import styles from '../../../styles/styles';
import * as SessionUtils from '../../SessionUtils';
let currentUserEmail;
Onyx.connect({
key: ONYXKEYS.SESSION,
callback: (val) => {
// When signed out, val is undefined
if (!val) {
return;
}
currentUserEmail = val.email;
},
});
let timezone;
Onyx.connect({
key: ONYXKEYS.PERSONAL_DETAILS_LIST,
callback: (val) => {
if (!val || timezone) {
return;
}
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.updateAutomaticTimezone(timezone);
}
},
});
const RootStack = createResponsiveStackNavigator();
// 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 = {
/** Session of currently logged in user */
session: PropTypes.shape({
email: PropTypes.string.isRequired,
}),
/** The report ID of the last opened public room as anonymous user */
lastOpenedPublicRoomID: PropTypes.string,
/** Opt-in experimental mode that prevents certain Onyx keys from persisting to disk */
isUsingMemoryOnlyKeys: PropTypes.bool,
...windowDimensionsPropTypes,
};
const defaultProps = {
isUsingMemoryOnlyKeys: false,
session: {
email: null,
},
lastOpenedPublicRoomID: null,
};
class AuthScreens extends React.Component {
constructor(props) {
super(props);
Timing.start(CONST.TIMING.HOMEPAGE_INITIAL_RENDER);
}
componentDidMount() {
NetworkConnection.listenForReconnect();
NetworkConnection.onReconnect(() => App.reconnectApp());
PusherConnectionManager.init();
Pusher.init({
appKey: CONFIG.PUSHER.APP_KEY,
cluster: CONFIG.PUSHER.CLUSTER,
authEndpoint: `${CONFIG.EXPENSIFY.DEFAULT_API_ROOT}api?command=AuthenticatePusher`,
}).then(() => {
User.subscribeToUserEvents();
});
// If we are on this screen then we are "logged in", but the user might not have "just logged in". They could be reopening the app
// or returning from background. If so, we'll assume they have some app data already and we can call reconnectApp() instead of openApp().
// Note: If a Guide has enabled the memory only key mode then we do want to run OpenApp as their app will not be rehydrated with
// the correct state on refresh. They are explicitly opting out of storing data they would need (i.e. reports_) to take advantage of
// the optimizations performed during ReconnectApp.
if (this.props.isUsingMemoryOnlyKeys || SessionUtils.didUserLogInDuringSession()) {
App.openApp();
} else {
App.reconnectApp();
}
App.setUpPoliciesAndNavigate(this.props.session);
if (this.props.lastOpenedPublicRoomID) {
// Re-open the last opened public room if the user logged in from a public room link
Report.openLastOpenedPublicRoom(this.props.lastOpenedPublicRoomID);
}
Download.clearDownloads();
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,
() => {
Modal.close(() => {
if (Navigation.isActiveRoute(ROUTES.SEARCH)) {
return;
}
return Navigation.navigate(ROUTES.SEARCH);
});
},
searchShortcutConfig.descriptionKey,
searchShortcutConfig.modifiers,
true,
);
this.unsubscribeGroupShortcut = KeyboardShortcut.subscribe(
groupShortcutConfig.shortcutKey,
() => {
Modal.close(() => {
if (Navigation.isActiveRoute(ROUTES.NEW_GROUP)) {
return;
}
Navigation.navigate(ROUTES.NEW_GROUP);
});
},
groupShortcutConfig.descriptionKey,
groupShortcutConfig.modifiers,
true,
);
}
shouldComponentUpdate(nextProps) {
return nextProps.windowHeight !== this.props.windowHeight || 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 commonScreenOptions = {
headerShown: false,
gestureDirection: 'horizontal',
animationEnabled: true,
cardStyleInterpolator: (props) => modalCardStyleInterpolator(this.props.isSmallScreenWidth, false, props),
cardOverlayEnabled: true,
animationTypeForReplace: 'push',
};
const rightModalNavigatorScreenOptions = {
...commonScreenOptions,
// we want pop in RHP since there are some flows that would work weird otherwise
animationTypeForReplace: 'pop',
cardStyle: styles.navigationModalCard(this.props.isSmallScreenWidth),
};
return (
<RootStack.Navigator
isSmallScreenWidth={this.props.isSmallScreenWidth}
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}
>
<RootStack.Screen
name={SCREENS.HOME}
options={{
...commonScreenOptions,
title: 'New Expensify',
// Prevent unnecessary scrolling
cardStyle: styles.cardStyleNavigator,
}}
getComponent={() => {
const SidebarScreen = require('../../../pages/home/sidebar/SidebarScreen').default;
return SidebarScreen;
}}
/>
<RootStack.Screen
name={NAVIGATORS.CENTRAL_PANE_NAVIGATOR}
options={{
...commonScreenOptions,
title: 'New Expensify',
// Prevent unnecessary scrolling
cardStyle: styles.cardStyleNavigator,
cardStyleInterpolator: (props) => modalCardStyleInterpolator(this.props.isSmallScreenWidth, false, props),
}}
component={CentralPaneNavigator}
/>
<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;
}}
/>
<RootStack.Screen
name={SCREENS.REPORT_ATTACHMENTS}
options={{
headerShown: false,
presentation: 'transparentModal',
}}
getComponent={() => {
const ReportAttachments = require('../../../pages/home/report/ReportAttachments').default;
return ReportAttachments;
}}
listeners={modalScreenListeners}
/>
<RootStack.Screen
name={NAVIGATORS.FULL_SCREEN_NAVIGATOR}
options={defaultScreenOptions}
component={FullScreenNavigator}
/>
<RootStack.Screen
name={NAVIGATORS.RIGHT_MODAL_NAVIGATOR}
options={rightModalNavigatorScreenOptions}
component={RightModalNavigator}
listeners={modalScreenListeners}
/>
</RootStack.Navigator>
);
}
}
AuthScreens.propTypes = propTypes;
AuthScreens.defaultProps = defaultProps;
export default compose(
withWindowDimensions,
withOnyx({
session: {
key: ONYXKEYS.SESSION,
},
lastOpenedPublicRoomID: {
key: ONYXKEYS.LAST_OPENED_PUBLIC_ROOM_ID,
},
isUsingMemoryOnlyKeys: {
key: ONYXKEYS.IS_USING_MEMORY_ONLY_KEYS,
},
}),
)(AuthScreens);