Make sure that DeviceInfoModule 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: D26859157

fbshipit-source-id: 754a5b4ede8defa8b7742cc42e09cc7cbfe4e18d
This commit is contained in:
Joshua Gross
2021-03-05 18:42:38 -08:00
committed by Facebook GitHub Bot
parent 77a23bdf0f
commit 4f38973b06
@@ -105,4 +105,14 @@ public class DeviceInfoModule extends NativeDeviceInfoSpec implements LifecycleE
@Override
public void invalidate() {}
@Override
public void onCatalystInstanceDestroy() {
super.onCatalystInstanceDestroy();
ReactApplicationContext applicationContext = getReactApplicationContextIfActiveOrWarn();
if (applicationContext != null) {
applicationContext.removeLifecycleEventListener(this);
}
}
}