Make sure that AppStateModule is subscribed to LifecycleEventListener events, and unsubscribes in onCatalystInstanceDestroy

Summary:
If modules are *not* eagerly init'd and expect lifecycle events, make sure (1) onHostResume is called immediately it it's currently active and (2) that listeners are removed in onCatalystInstanceDestroy.

Changelog: [Internal]

Reviewed By: mdvacca

Differential Revision: D26859205

fbshipit-source-id: 5398d24d2592de3fbb80ca59192b5b46543aa5c5
This commit is contained in:
Joshua Gross
2021-03-05 18:36:25 -08:00
committed by Facebook GitHub Bot
parent 66febd1e34
commit c2e44103b9
@@ -119,4 +119,14 @@ public class AppStateModule extends NativeAppStateSpec
public void removeListeners(double count) {
// iOS only
}
@Override
public void onCatalystInstanceDestroy() {
super.onCatalystInstanceDestroy();
ReactApplicationContext applicationContext = getReactApplicationContextIfActiveOrWarn();
if (applicationContext != null) {
applicationContext.removeLifecycleEventListener(this);
}
}
}