From 014c6f963648cb3cbdef9acbe317d2568d4b5ded Mon Sep 17 00:00:00 2001 From: Joshua Gross Date: Fri, 5 Mar 2021 18:36:25 -0800 Subject: [PATCH] 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 --- .../facebook/react/animated/NativeAnimatedModule.java | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/ReactAndroid/src/main/java/com/facebook/react/animated/NativeAnimatedModule.java b/ReactAndroid/src/main/java/com/facebook/react/animated/NativeAnimatedModule.java index 2f2880080e6..ccc800b3507 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/animated/NativeAnimatedModule.java +++ b/ReactAndroid/src/main/java/com/facebook/react/animated/NativeAnimatedModule.java @@ -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); + } + } }