Skip to content

Commit

Permalink
Subscribe to NetInfo in Expensify constructor and have the reconnect …
Browse files Browse the repository at this point in the history
…listeners sit behind AuthScreens
  • Loading branch information
yuwenmemon committed Aug 9, 2022
1 parent e178897 commit 0d13184
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 9 deletions.
4 changes: 4 additions & 0 deletions src/Expensify.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import ConfirmModal from './components/ConfirmModal';
import compose from './libs/compose';
import withLocalize, {withLocalizePropTypes} from './components/withLocalize';
import * as User from './libs/actions/User';
import NetworkConnection from './libs/NetworkConnection';

Onyx.registerLogger(({level, message}) => {
if (level === 'alert') {
Expand Down Expand Up @@ -91,6 +92,9 @@ class Expensify extends PureComponent {
isOnyxMigrated: false,
isSplashShown: true,
};

// Used for the offline indicator appearing when someone is offline
NetworkConnection.subscribeToNetInfo();
}

componentDidMount() {
Expand Down
4 changes: 4 additions & 0 deletions src/libs/Navigation/AppNavigator/AuthScreens.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,10 @@ class AuthScreens extends React.Component {

componentDidMount() {
NetworkConnection.listenForReconnect();
NetworkConnection.onReconnect(() => {
App.getAppData();
App.reconnectApp();
});
PusherConnectionManager.init();
Pusher.init({
appKey: CONFIG.PUSHER.APP_KEY,
Expand Down
3 changes: 1 addition & 2 deletions src/libs/NetworkConnection.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,6 @@ function listenForReconnect() {
unsubscribeFromAppState = AppStateMonitor.addBecameActiveListener(() => {
triggerReconnectionCallbacks('app became active');
});

subscribeToNetInfo();
}

/**
Expand Down Expand Up @@ -130,4 +128,5 @@ export default {
onReconnect,
triggerReconnectionCallbacks,
recheckNetworkConnection,
subscribeToNetInfo,
};
8 changes: 1 addition & 7 deletions src/libs/actions/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -251,13 +251,6 @@ function openProfile() {
Navigation.navigate(ROUTES.SETTINGS_PROFILE);
}

// When the app reconnects from being offline, fetch all initialization data
NetworkConnection.listenForReconnect();
NetworkConnection.onReconnect(() => {
getAppData();
reconnectApp();
});

export {
setLocale,
setSidebarLoaded,
Expand All @@ -266,4 +259,5 @@ export {
setUpPoliciesAndNavigate,
openProfile,
openApp,
reconnectApp,
};

0 comments on commit 0d13184

Please sign in to comment.