diff --git a/ReactAndroid/src/main/java/com/facebook/react/views/modal/ReactModalHostManager.java b/ReactAndroid/src/main/java/com/facebook/react/views/modal/ReactModalHostManager.java index 03a60ed27e1..35e1f8b2742 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/views/modal/ReactModalHostManager.java +++ b/ReactAndroid/src/main/java/com/facebook/react/views/modal/ReactModalHostManager.java @@ -142,8 +142,9 @@ public class ReactModalHostManager extends ViewGroupManager @Override public Object updateState( ReactModalHostView view, ReactStylesDiffMap props, @Nullable StateWrapper stateWrapper) { + view.getFabricViewStateManager().setStateWrapper(stateWrapper); Point modalSize = ModalHostHelper.getModalHostSize(view.getContext()); - view.updateState(stateWrapper, modalSize.x, modalSize.y); + view.updateState(modalSize.x, modalSize.y); return null; } diff --git a/ReactAndroid/src/main/java/com/facebook/react/views/modal/ReactModalHostView.java b/ReactAndroid/src/main/java/com/facebook/react/views/modal/ReactModalHostView.java index e404e0d4e97..24d324fe709 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/views/modal/ReactModalHostView.java +++ b/ReactAndroid/src/main/java/com/facebook/react/views/modal/ReactModalHostView.java @@ -32,10 +32,10 @@ import com.facebook.react.bridge.UiThreadUtil; import com.facebook.react.bridge.WritableMap; import com.facebook.react.bridge.WritableNativeMap; import com.facebook.react.common.annotations.VisibleForTesting; +import com.facebook.react.uimanager.FabricViewStateManager; import com.facebook.react.uimanager.JSTouchDispatcher; import com.facebook.react.uimanager.PixelUtil; import com.facebook.react.uimanager.RootView; -import com.facebook.react.uimanager.StateWrapper; import com.facebook.react.uimanager.UIManagerModule; import com.facebook.react.uimanager.events.EventDispatcher; import com.facebook.react.views.common.ContextUtils; @@ -57,7 +57,8 @@ import java.util.ArrayList; * around addition and removal of views to the DialogRootViewGroup. * */ -public class ReactModalHostView extends ViewGroup implements LifecycleEventListener { +public class ReactModalHostView extends ViewGroup + implements LifecycleEventListener, FabricViewStateManager.HasFabricViewStateManager { // This listener is called when the user presses KeyEvent.KEYCODE_BACK // An event is then passed to JS which can either close or not close the Modal by setting the @@ -317,11 +318,6 @@ public class ReactModalHostView extends ViewGroup implements LifecycleEventListe } } - @UiThread - public void updateState(StateWrapper stateWrapper, int width, int height) { - mHostView.updateState(stateWrapper, width, height); - } - /** * Returns the view that will be the root view of the dialog. We are wrapping this in a * FrameLayout because this is the system's way of notifying us that the dialog size has changed. @@ -371,6 +367,15 @@ public class ReactModalHostView extends ViewGroup implements LifecycleEventListe } } + @Override + public FabricViewStateManager getFabricViewStateManager() { + return mHostView.getFabricViewStateManager(); + } + + public void updateState(final int width, final int height) { + mHostView.updateState(width, height); + } + /** * DialogRootViewGroup is the ViewGroup which contains all the children of a Modal. It gets all * child information forwarded from ReactModalHostView and uses that to create children. It is @@ -382,12 +387,13 @@ public class ReactModalHostView extends ViewGroup implements LifecycleEventListe * styleHeight on the LayoutShadowNode to be the window size. This is done through the * UIManagerModule, and will then cause the children to layout as if they can fill the window. */ - static class DialogRootViewGroup extends ReactViewGroup implements RootView { + static class DialogRootViewGroup extends ReactViewGroup + implements RootView, FabricViewStateManager.HasFabricViewStateManager { private boolean hasAdjustedSize = false; private int viewWidth; private int viewHeight; - private @Nullable StateWrapper mStateWrapper; + private final FabricViewStateManager mFabricViewStateManager = new FabricViewStateManager(); private final JSTouchDispatcher mJSTouchDispatcher = new JSTouchDispatcher(this); @@ -407,9 +413,9 @@ public class ReactModalHostView extends ViewGroup implements LifecycleEventListe if (getChildCount() > 0) { hasAdjustedSize = false; final int viewTag = getChildAt(0).getId(); - if (mStateWrapper != null) { + if (mFabricViewStateManager.hasStateWrapper()) { // This will only be called under Fabric - updateState(mStateWrapper, viewWidth, viewHeight); + updateState(viewWidth, viewHeight); } else { // TODO: T44725185 remove after full migration to Fabric ReactContext reactContext = getReactContext(); @@ -434,12 +440,17 @@ public class ReactModalHostView extends ViewGroup implements LifecycleEventListe } @UiThread - public void updateState(StateWrapper stateWrapper, int width, int height) { - mStateWrapper = stateWrapper; - WritableMap map = new WritableNativeMap(); - map.putDouble("screenWidth", PixelUtil.toDIPFromPixel(width)); - map.putDouble("screenHeight", PixelUtil.toDIPFromPixel(height)); - stateWrapper.updateState(map); + public void updateState(final int width, final int height) { + mFabricViewStateManager.setState( + new FabricViewStateManager.StateUpdateCallback() { + @Override + public WritableMap getStateUpdate() { + WritableMap map = new WritableNativeMap(); + map.putDouble("screenWidth", PixelUtil.toDIPFromPixel(width)); + map.putDouble("screenHeight", PixelUtil.toDIPFromPixel(height)); + return map; + } + }); } @Override @@ -489,5 +500,10 @@ public class ReactModalHostView extends ViewGroup implements LifecycleEventListe ReactContext reactContext = getReactContext(); return reactContext.getNativeModule(UIManagerModule.class).getEventDispatcher(); } + + @Override + public FabricViewStateManager getFabricViewStateManager() { + return mFabricViewStateManager; + } } }