-
Notifications
You must be signed in to change notification settings - Fork 2.9k
/
AuthScreens.js
214 lines (194 loc) · 7.74 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
import React from 'react';
import PropTypes from 'prop-types';
import {withOnyx} from 'react-native-onyx';
import {getNavigationModalCardStyle} from '../../../styles/styles';
import withWindowDimensions, {windowDimensionsPropTypes} from '../../../components/withWindowDimensions';
import CONST from '../../../CONST';
import compose from '../../compose';
import {
subscribeToReportCommentEvents,
fetchAll as fetchAllReports,
} from '../../actions/Report';
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 {fetchCountryCodeByRequestIP} from '../../actions/GeoLocation';
import KeyboardShortcut from '../../KeyboardShortcut';
import Navigation from '../Navigation';
import * as User from '../../actions/User';
import {setModalVisibility} from '../../actions/Modal';
import NameValuePair from '../../actions/NameValuePair';
import modalCardStyleInterpolator from './modalCardStyleInterpolator';
import createCustomModalStackNavigator from './createCustomModalStackNavigator';
// Main drawer navigator
import MainDrawerNavigator from './MainDrawerNavigator';
// Modal Stack Navigators
import {
IOUBillStackNavigator,
IOURequestModalStackNavigator,
DetailsModalStackNavigator,
SearchModalStackNavigator,
NewGroupModalStackNavigator,
NewChatModalStackNavigator,
SettingsModalStackNavigator,
} from './ModalStackNavigators';
const RootStack = createCustomModalStackNavigator();
// When modal screen gets focused, update modal visibility in Onyx
// https://reactnavigation.org/docs/navigation-events/
const modalScreenListeners = {
focus: () => {
setModalVisibility(true);
},
beforeRemove: () => {
setModalVisibility(false);
},
};
const propTypes = {
network: PropTypes.shape({isOffline: PropTypes.bool}),
...windowDimensionsPropTypes,
};
const defaultProps = {
network: {isOffline: true},
};
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();
PusherConnectionManager.init();
Pusher.init({
appKey: CONFIG.PUSHER.APP_KEY,
cluster: CONFIG.PUSHER.CLUSTER,
authEndpoint: `${CONFIG.EXPENSIFY.URL_API_ROOT}api?command=Push_Authenticate`,
}).then(subscribeToReportCommentEvents);
// Fetch some data we need on initialization
NameValuePair.get(CONST.NVP.PRIORITY_MODE, ONYXKEYS.NVP_PRIORITY_MODE, 'default');
PersonalDetails.fetch();
User.fetch();
User.getBetas();
fetchAllReports(true, true);
fetchCountryCodeByRequestIP();
UnreadIndicatorUpdater.listenForReportChanges();
// Refresh the personal details, timezone and betas every 30 minutes
// There is no pusher event that sends updated personal details data yet
// See https://github.com/Expensify/ReactNativeChat/issues/468
this.interval = setInterval(() => {
if (this.props.network.isOffline) {
return;
}
PersonalDetails.fetch();
User.fetch();
User.getBetas();
}, 1000 * 60 * 30);
Timing.end(CONST.TIMING.HOMEPAGE_INITIAL_RENDER);
// Listen for the Command+K key being pressed so the focus can be given to the chat switcher
KeyboardShortcut.subscribe('K', () => {
Navigation.navigate(ROUTES.SEARCH);
}, ['meta'], true);
}
shouldComponentUpdate(prevProps) {
if (prevProps.isSmallScreenWidth !== this.props.isSmallScreenWidth) {
return true;
}
return false;
}
componentWillUnmount() {
KeyboardShortcut.unsubscribe('K');
NetworkConnection.stopListeningForReconnect();
clearInterval(this.interval);
this.interval = null;
}
render() {
const modalScreenOptions = {
headerShown: false,
cardStyle: getNavigationModalCardStyle(this.props.isSmallScreenWidth),
cardStyleInterpolator: modalCardStyleInterpolator,
animationEnabled: true,
gestureDirection: 'horizontal',
// 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"
>
{/* The MainDrawerNavigator contains the SidebarScreen and ReportScreen */}
<RootStack.Screen
name="Home"
options={{
headerShown: false,
title: 'Expensify.cash',
}}
component={MainDrawerNavigator}
/>
{/* 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={SettingsModalStackNavigator}
listeners={modalScreenListeners}
/>
<RootStack.Screen
name="NewChat"
options={modalScreenOptions}
component={NewChatModalStackNavigator}
listeners={modalScreenListeners}
/>
<RootStack.Screen
name="NewGroup"
options={modalScreenOptions}
component={NewGroupModalStackNavigator}
listeners={modalScreenListeners}
/>
<RootStack.Screen
name="Search"
options={modalScreenOptions}
component={SearchModalStackNavigator}
listeners={modalScreenListeners}
/>
<RootStack.Screen
name="Details"
options={modalScreenOptions}
component={DetailsModalStackNavigator}
listeners={modalScreenListeners}
/>
<RootStack.Screen
name="IOU_Request"
options={modalScreenOptions}
component={IOURequestModalStackNavigator}
listeners={modalScreenListeners}
/>
<RootStack.Screen
name="IOU_Bill"
options={modalScreenOptions}
component={IOUBillStackNavigator}
listeners={modalScreenListeners}
/>
</RootStack.Navigator>
);
}
}
AuthScreens.propTypes = propTypes;
AuthScreens.defaultProps = defaultProps;
export default compose(
withWindowDimensions,
withOnyx({
network: {
key: ONYXKEYS.NETWORK,
},
}),
)(AuthScreens);