MM-15575 Make Entry mount properly after hydration (#2839)

* MM-15575 Make Entry mount properly after hydration

* Clear unsubscribeFromStore after calling it
This commit is contained in:
Harrison Healey 2019-05-28 14:36:35 -04:00 committed by Miguel Alatzar
parent a6307c5ca6
commit 098a0404f7

View file

@ -75,11 +75,18 @@ export default class Entry extends PureComponent {
launchLogin: false,
launchChannel: false,
};
this.unsubscribeFromStore = null;
}
componentDidMount() {
Client4.setUserAgent(DeviceInfo.getUserAgent());
this.unsubscribeFromStore = store.subscribe(this.listenForHydration);
if (store.getState().views.root.hydrationComplete) {
this.handleHydrationComplete();
} else {
this.unsubscribeFromStore = store.subscribe(this.listenForHydration);
}
EventEmitter.on(ViewTypes.LAUNCH_LOGIN, this.handleLaunchLogin);
EventEmitter.on(ViewTypes.LAUNCH_CHANNEL, this.handleLaunchChannel);
@ -107,13 +114,6 @@ export default class Entry extends PureComponent {
};
listenForHydration = () => {
const {
actions: {
autoUpdateTimezone,
},
enableTimezone,
deviceTimezone,
} = this.props;
const {getState} = store;
const state = getState();
@ -122,26 +122,43 @@ export default class Entry extends PureComponent {
}
if (state.views.root.hydrationComplete) {
this.handleHydrationComplete();
}
};
handleHydrationComplete = () => {
if (this.unsubscribeFromStore) {
this.unsubscribeFromStore();
this.unsubscribeFromStore = null;
}
if (enableTimezone) {
autoUpdateTimezone(deviceTimezone);
}
this.setAppCredentials();
this.setStartupThemes();
this.handleNotification();
this.loadSystemEmojis();
if (Platform.OS === 'android') {
this.launchForAndroid();
return;
}
this.autoUpdateTimezone();
this.setAppCredentials();
this.setStartupThemes();
this.handleNotification();
this.loadSystemEmojis();
if (Platform.OS === 'android') {
this.launchForAndroid();
} else {
this.launchForiOS();
}
};
autoUpdateTimezone = () => {
const {
actions: {
autoUpdateTimezone,
},
enableTimezone,
deviceTimezone,
} = this.props;
if (enableTimezone) {
autoUpdateTimezone(deviceTimezone);
}
};
configurePushNotifications = () => {
const configureNotifications = lazyLoadPushNotifications();
configureNotifications();