From a7e7d1fdcb81a318baa7995ca25d961986eaadd5 Mon Sep 17 00:00:00 2001 From: Diego Mello Date: Thu, 2 Jul 2020 14:14:12 -0300 Subject: [PATCH] [FIX] Android crashing when restoring from background (#2238) --- .../chat/rocket/reactnative/MainActivity.java | 3 ++- app/views/RoomsListView/index.js | 18 ++++++++++++++++-- 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/android/app/src/main/java/chat/rocket/reactnative/MainActivity.java b/android/app/src/main/java/chat/rocket/reactnative/MainActivity.java index de66369a1..759229137 100644 --- a/android/app/src/main/java/chat/rocket/reactnative/MainActivity.java +++ b/android/app/src/main/java/chat/rocket/reactnative/MainActivity.java @@ -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); } diff --git a/app/views/RoomsListView/index.js b/app/views/RoomsListView/index.js index f97e67c3e..39b035e6f 100644 --- a/app/views/RoomsListView/index.js +++ b/app/views/RoomsListView/index.js @@ -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); }