mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
Refactor: Use get/setCurrentActivity in ReactHost (#38998)
Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/38998 Instead of using the mActivity reference directly, let's just use getCurrentActivity() and setCurrentActivity(). Changelog: [Internal] Reviewed By: mdvacca Differential Revision: D48076896 fbshipit-source-id: d988deaf8778bf0e3726d13f96e9e6e480d8fdc0
This commit is contained in:
committed by
Facebook GitHub Bot
parent
75c5d74ea2
commit
aec22574cc
+15
-10
@@ -276,11 +276,11 @@ public class ReactHostImpl implements ReactHost {
|
||||
final String method = "onHostResume(activity)";
|
||||
log(method);
|
||||
|
||||
mActivity.set(activity);
|
||||
setCurrentActivity(activity);
|
||||
ReactContext currentContext = getCurrentReactContext();
|
||||
|
||||
// TODO(T137233065): Enable DevSupportManager here
|
||||
mReactLifecycleStateManager.moveToOnHostResume(currentContext, mActivity.get());
|
||||
mReactLifecycleStateManager.moveToOnHostResume(currentContext, getCurrentActivity());
|
||||
}
|
||||
|
||||
@ThreadConfined(UI)
|
||||
@@ -291,7 +291,7 @@ public class ReactHostImpl implements ReactHost {
|
||||
|
||||
ReactContext currentContext = getCurrentReactContext();
|
||||
|
||||
Activity currentActivity = mActivity.get();
|
||||
Activity currentActivity = getCurrentActivity();
|
||||
if (currentActivity != null) {
|
||||
String currentActivityClass = currentActivity.getClass().getSimpleName();
|
||||
String activityClass = activity == null ? "null" : activity.getClass().getSimpleName();
|
||||
@@ -321,7 +321,7 @@ public class ReactHostImpl implements ReactHost {
|
||||
|
||||
// TODO(T137233065): Disable DevSupportManager here
|
||||
mDefaultHardwareBackBtnHandler = null;
|
||||
mReactLifecycleStateManager.moveToOnHostPause(currentContext, mActivity.get());
|
||||
mReactLifecycleStateManager.moveToOnHostPause(currentContext, getCurrentActivity());
|
||||
}
|
||||
|
||||
/** To be called when the host activity is destroyed. */
|
||||
@@ -341,7 +341,7 @@ public class ReactHostImpl implements ReactHost {
|
||||
final String method = "onHostDestroy(activity)";
|
||||
log(method);
|
||||
|
||||
Activity currentActivity = mActivity.get();
|
||||
Activity currentActivity = getCurrentActivity();
|
||||
|
||||
// TODO(T137233065): Disable DevSupportManager here
|
||||
if (currentActivity == activity) {
|
||||
@@ -504,6 +504,10 @@ public class ReactHostImpl implements ReactHost {
|
||||
return mActivity.get();
|
||||
}
|
||||
|
||||
private void setCurrentActivity(@Nullable Activity activity) {
|
||||
mActivity.set(activity);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the {@link EventDispatcher} from the {@link FabricUIManager}. This always returns an
|
||||
* EventDispatcher, even if the instance isn't alive; in that case, it returns a {@link
|
||||
@@ -726,7 +730,7 @@ public class ReactHostImpl implements ReactHost {
|
||||
@ThreadConfined(UI)
|
||||
private void moveToHostDestroy(@Nullable ReactContext currentContext) {
|
||||
mReactLifecycleStateManager.moveToOnHostDestroy(currentContext);
|
||||
mActivity.set(null);
|
||||
setCurrentActivity(null);
|
||||
}
|
||||
|
||||
private void raiseSoftException(String method, String message) {
|
||||
@@ -946,14 +950,15 @@ public class ReactHostImpl implements ReactHost {
|
||||
* screen in the past, or (2) We must be on a React Native screen.
|
||||
*/
|
||||
if (isReloading && !isManagerResumed) {
|
||||
mReactLifecycleStateManager.moveToOnHostResume(reactContext, mActivity.get());
|
||||
mReactLifecycleStateManager.moveToOnHostResume(
|
||||
reactContext, getCurrentActivity());
|
||||
} else {
|
||||
/**
|
||||
* Call ReactContext.onHostResume() only when already in the resumed state
|
||||
* which aligns with the bridge https://fburl.com/diffusion/2qhxmudv.
|
||||
*/
|
||||
mReactLifecycleStateManager.resumeReactContextIfHostResumed(
|
||||
reactContext, mActivity.get());
|
||||
reactContext, getCurrentActivity());
|
||||
}
|
||||
|
||||
ReactInstanceEventListener[] listeners =
|
||||
@@ -1033,7 +1038,7 @@ public class ReactHostImpl implements ReactHost {
|
||||
aligns with the bridge https://fburl.com/diffusion/2qhxmudv.
|
||||
*/
|
||||
mReactLifecycleStateManager.resumeReactContextIfHostResumed(
|
||||
reactContext, mActivity.get());
|
||||
reactContext, getCurrentActivity());
|
||||
|
||||
ReactInstanceEventListener[] listeners =
|
||||
new ReactInstanceEventListener[mReactInstanceEventListeners.size()];
|
||||
@@ -1410,7 +1415,7 @@ public class ReactHostImpl implements ReactHost {
|
||||
}
|
||||
|
||||
// Reset current activity
|
||||
mActivity.set(null);
|
||||
setCurrentActivity(null);
|
||||
|
||||
// Clear ResourceIdleDrawableIdMap
|
||||
ResourceDrawableIdHelper.getInstance().clear();
|
||||
|
||||
Reference in New Issue
Block a user