Make sure that NativeAnimatedModule 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: D26859158

fbshipit-source-id: 4966d3c49d194c4cb4063edf3a035f6077b76cd9
This commit is contained in:
Joshua Gross
2021-03-05 18:42:36 -08:00
committed by Facebook GitHub Bot
parent aa305b34e3
commit 014c6f9636
@@ -163,7 +163,7 @@ public class NativeAnimatedModule extends NativeAnimatedModuleSpec
ReactApplicationContext reactApplicationContext = getReactApplicationContextIfActiveOrWarn();
if (reactApplicationContext != null) {
reactApplicationContext.addLifecycleEventListener(this);
reactApplicationContext.addLifecycleEventListenerAndCheckState(this);
}
}
@@ -891,4 +891,12 @@ public class NativeAnimatedModule extends NativeAnimatedModuleSpec
}
});
}
@Override
public void onCatalystInstanceDestroy() {
ReactApplicationContext context = getReactApplicationContextIfActiveOrWarn();
if (context != null) {
context.removeLifecycleEventListener(this);
}
}
}