mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
Fix: RedBoxes don't show up after teardowns (#38997)
Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/38997 After React Native gets destroyed (e.g: via an exception), the ReactHost resets its current activity. ## Problem React Native can display RedBoxes after React Native destruction (e.g: in the case of an exception). Displaying RedBoxes requires the current activity, which gets nullified. So, the RedBox might not show up after destruction. ## Changes This diff makes ReactHost keep a track of its last non-null activity in a WeakRef. Then, the DevMenu just uses the last non-null activity to display RedBoxes (and everything else). Changelog: [Internal] Reviewed By: mdvacca Differential Revision: D48076893 fbshipit-source-id: 6baddf8f329c03efe92f93ef1bfc6eb9569c1b38
This commit is contained in:
committed by
Facebook GitHub Bot
parent
aec22574cc
commit
1f0094e40a
+1
-1
@@ -121,7 +121,7 @@ class BridgelessDevSupportManager extends DevSupportManagerBase {
|
||||
@androidx.annotation.Nullable
|
||||
@Override
|
||||
public Activity getCurrentActivity() {
|
||||
return reactHost.getCurrentActivity();
|
||||
return reactHost.getLastUsedActivity();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
+14
@@ -117,6 +117,8 @@ public class ReactHostImpl implements ReactHost {
|
||||
new BridgelessAtomicRef<>();
|
||||
|
||||
private final AtomicReference<Activity> mActivity = new AtomicReference<>();
|
||||
private final AtomicReference<WeakReference<Activity>> mLastUsedActivity =
|
||||
new AtomicReference<>(new WeakReference<>(null));
|
||||
private final BridgelessReactStateTracker mBridgelessReactStateTracker =
|
||||
new BridgelessReactStateTracker(DEV);
|
||||
private final ReactLifecycleStateManager mReactLifecycleStateManager =
|
||||
@@ -504,8 +506,20 @@ public class ReactHostImpl implements ReactHost {
|
||||
return mActivity.get();
|
||||
}
|
||||
|
||||
@Nullable
|
||||
/* package */ Activity getLastUsedActivity() {
|
||||
@Nullable WeakReference<Activity> lastUsedActivityWeakRef = mLastUsedActivity.get();
|
||||
if (lastUsedActivityWeakRef != null) {
|
||||
return lastUsedActivityWeakRef.get();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private void setCurrentActivity(@Nullable Activity activity) {
|
||||
mActivity.set(activity);
|
||||
if (activity != null) {
|
||||
mLastUsedActivity.set(new WeakReference<>(activity));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user