[FIX] Android crashing when restoring from background (#2238)

This commit is contained in:
Diego Mello 2020-07-02 14:14:12 -03:00 committed by GitHub
parent 68e9e1455b
commit a7e7d1fdcb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 18 additions and 3 deletions

View File

@ -13,7 +13,8 @@ public class MainActivity extends ReactFragmentActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// https://github.com/software-mansion/react-native-screens/issues/17#issuecomment-424704067
super.onCreate(null);
RNBootSplash.init(R.drawable.launch_screen, MainActivity.this);
}

View File

@ -151,8 +151,22 @@ class RoomsListView extends React.Component {
}
componentDidMount() {
this.getSubscriptions();
const { navigation, closeServerDropdown } = this.props;
const {
navigation, closeServerDropdown, appState
} = this.props;
/**
* - When didMount is triggered and appState is foreground,
* it means the user is logging in and selectServer has ran, so we can getSubscriptions
*
* - When didMount is triggered and appState is background,
* it means the user has resumed the app, so selectServer needs to be triggered,
* which is going to change server and getSubscriptions will be triggered by componentWillReceiveProps
*/
if (appState === 'foreground') {
this.getSubscriptions();
}
if (isTablet) {
EventEmitter.addEventListener(KEY_COMMAND, this.handleCommands);
}