From 16eb53befa305df70e9aa1dae2ad6e9fe97f1ecb Mon Sep 17 00:00:00 2001 From: Ramanpreet Nara Date: Mon, 11 Nov 2024 13:24:49 -0800 Subject: [PATCH] Integrate DevSupportManager into activity lifecycle (#47531) Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/47531 When the activity is paused, or destroyed, we should disable the devsupportmanager. (This performs cleanup). When the activity is resumed, we should re-enable devsupportmanager. (This performs re-initialization). Changelog: [Internal] Reviewed By: sammy-SC Differential Revision: D65689053 fbshipit-source-id: 99de0906b8cdc84f56b4d334ac0eeecc7b436dd5 --- .../facebook/react/runtime/ReactHostImpl.java | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/runtime/ReactHostImpl.java b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/runtime/ReactHostImpl.java index 1e06f6abb7b..c04401f822a 100644 --- a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/runtime/ReactHostImpl.java +++ b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/runtime/ReactHostImpl.java @@ -316,7 +316,7 @@ public class ReactHostImpl implements ReactHost { setCurrentActivity(activity); ReactContext currentContext = getCurrentReactContext(); - // TODO(T137233065): Enable DevSupportManager here + maybeEnableDevSupport(true); mReactLifecycleStateManager.moveToOnHostResume(currentContext, getCurrentActivity()); } @@ -354,7 +354,7 @@ public class ReactHostImpl implements ReactHost { + activityClass); } - // TODO(T137233065): Disable DevSupportManager here + maybeEnableDevSupport(false); mDefaultHardwareBackBtnHandler = null; mReactLifecycleStateManager.moveToOnHostPause(currentContext, currentActivity); } @@ -368,7 +368,7 @@ public class ReactHostImpl implements ReactHost { ReactContext currentContext = getCurrentReactContext(); - // TODO(T137233065): Disable DevSupportManager here + maybeEnableDevSupport(false); mDefaultHardwareBackBtnHandler = null; mReactLifecycleStateManager.moveToOnHostPause(currentContext, getCurrentActivity()); } @@ -380,7 +380,7 @@ public class ReactHostImpl implements ReactHost { final String method = "onHostDestroy()"; log(method); - // TODO(T137233065): Disable DevSupportManager here + maybeEnableDevSupport(false); moveToHostDestroy(getCurrentReactContext()); } @@ -392,12 +392,18 @@ public class ReactHostImpl implements ReactHost { Activity currentActivity = getCurrentActivity(); - // TODO(T137233065): Disable DevSupportManager here + maybeEnableDevSupport(false); if (currentActivity == activity) { moveToHostDestroy(getCurrentReactContext()); } } + private void maybeEnableDevSupport(boolean enabled) { + if (mUseDevSupport) { + mDevSupportManager.setDevSupportEnabled(enabled); + } + } + /** * Returns current ReactContext which could be nullable if ReactInstance hasn't been created. *