mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
Fix race condition in FabricUIManager.StartSurface method
Summary: This diff fixes a race condition in the execution of FabricUIManager.StartSurface method. The rootcause is that startSurface is executing getViewportOffset from a background thread. changelog: [internal] Reviewed By: shergin Differential Revision: D25617154 fbshipit-source-id: 9351201088164e74bb0b9454e30651e1de0da912
This commit is contained in:
committed by
Facebook GitHub Bot
parent
d51cc6b5e6
commit
5a37773e53
@@ -27,6 +27,7 @@ import android.view.ViewTreeObserver;
|
||||
import android.view.WindowManager;
|
||||
import android.widget.FrameLayout;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.annotation.UiThread;
|
||||
import com.facebook.common.logging.FLog;
|
||||
import com.facebook.infer.annotation.Assertions;
|
||||
import com.facebook.infer.annotation.ThreadConfined;
|
||||
@@ -418,6 +419,7 @@ public class ReactRootView extends FrameLayout implements RootView, ReactRoot {
|
||||
return mState;
|
||||
}
|
||||
|
||||
@UiThread
|
||||
public static Point getViewportOffset(View v) {
|
||||
int[] locationInWindow = new int[2];
|
||||
v.getLocationInWindow(locationInWindow);
|
||||
|
||||
@@ -248,7 +248,12 @@ public class FabricUIManager implements UIManager, LifecycleEventListener {
|
||||
mMountingManager.addRootView(rootTag, rootView);
|
||||
mReactContextForRootTag.put(rootTag, reactContext);
|
||||
|
||||
Point viewportOffset = ReactRootView.getViewportOffset(rootView);
|
||||
// If startSurface is executed in the UIThread then, it uses the ViewportOffset from the View,
|
||||
// Otherwise Fabric relies on calling {@link Binding#setConstraints} method to update the
|
||||
// ViewportOffset during measurement or onLayout.
|
||||
@SuppressLint("WrongThread")
|
||||
Point viewportOffset =
|
||||
UiThreadUtil.isOnUiThread() ? ReactRootView.getViewportOffset(rootView) : new Point(0, 0);
|
||||
|
||||
mBinding.startSurfaceWithConstraints(
|
||||
rootTag,
|
||||
|
||||
Reference in New Issue
Block a user