Update Modal State when there is a change on the size of the screen

Summary:
This diff adds support to Update Modal State when there is a change on the size of the screen

// TODO

Reviewed By: JoshuaGross

Differential Revision: D16000755

fbshipit-source-id: be87caa6d7f85c3d2778d2707c1e0cd821d6f6c6
This commit is contained in:
David Vacca 2019-07-02 14:40:01 -07:00 коммит произвёл Facebook Github Bot
Родитель 59d85fbf0b
Коммит 57d1f8ae15
3 изменённых файлов: 42 добавлений и 17 удалений

Просмотреть файл

@ -3,6 +3,10 @@ load("//tools/build_defs/oss:rn_defs.bzl", "YOGA_TARGET", "react_native_dep", "r
rn_android_library(
name = "modal",
srcs = glob(["*.java"]),
is_androidx = True,
provided_deps = [
react_native_dep("third-party/android/androidx:annotation"),
],
required_for_source_only_abi = True,
visibility = [
"PUBLIC",

Просмотреть файл

@ -8,12 +8,9 @@ package com.facebook.react.views.modal;
import android.content.DialogInterface;
import android.graphics.Point;
import com.facebook.react.bridge.WritableMap;
import com.facebook.react.bridge.WritableNativeMap;
import com.facebook.react.common.MapBuilder;
import com.facebook.react.module.annotations.ReactModule;
import com.facebook.react.uimanager.LayoutShadowNode;
import com.facebook.react.uimanager.PixelUtil;
import com.facebook.react.uimanager.StateWrapper;
import com.facebook.react.uimanager.ThemedReactContext;
import com.facebook.react.uimanager.UIManagerModule;
@ -106,9 +103,6 @@ public class ReactModalHostManager extends ViewGroupManager<ReactModalHostView>
@Override
public void updateState(ReactModalHostView view, StateWrapper stateWrapper) {
Point modalSize = ModalHostHelper.getModalHostSize(view.getContext());
WritableMap map = new WritableNativeMap();
map.putDouble("screenWidth", PixelUtil.toDIPFromPixel(modalSize.x));
map.putDouble("screenHeight", PixelUtil.toDIPFromPixel(modalSize.y));
stateWrapper.updateState(map);
view.updateState(stateWrapper, modalSize.x, modalSize.y);
}
}

Просмотреть файл

@ -19,14 +19,19 @@ import android.view.ViewStructure;
import android.view.WindowManager;
import android.view.accessibility.AccessibilityEvent;
import android.widget.FrameLayout;
import androidx.annotation.UiThread;
import com.facebook.infer.annotation.Assertions;
import com.facebook.react.R;
import com.facebook.react.bridge.GuardedRunnable;
import com.facebook.react.bridge.LifecycleEventListener;
import com.facebook.react.bridge.ReactContext;
import com.facebook.react.bridge.WritableMap;
import com.facebook.react.bridge.WritableNativeMap;
import com.facebook.react.common.annotations.VisibleForTesting;
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;
@ -287,6 +292,11 @@ 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.
@ -346,6 +356,8 @@ public class ReactModalHostView extends ViewGroup implements LifecycleEventListe
private int viewWidth;
private int viewHeight;
private @Nullable StateWrapper mStateWrapper;
private final JSTouchDispatcher mJSTouchDispatcher = new JSTouchDispatcher(this);
public DialogRootViewGroup(Context context) {
@ -364,21 +376,36 @@ public class ReactModalHostView extends ViewGroup implements LifecycleEventListe
if (getChildCount() > 0) {
hasAdjustedSize = false;
final int viewTag = getChildAt(0).getId();
ReactContext reactContext = getReactContext();
reactContext.runOnNativeModulesQueueThread(
new GuardedRunnable(reactContext) {
@Override
public void runGuarded() {
(getReactContext())
.getNativeModule(UIManagerModule.class)
.updateNodeSize(viewTag, viewWidth, viewHeight);
}
});
if (mStateWrapper != null) {
// This will only be called under Fabric
updateState(mStateWrapper, viewWidth, viewHeight);
} else {
// TODO: T44725185 remove after full migration to Fabric
ReactContext reactContext = getReactContext();
reactContext.runOnNativeModulesQueueThread(
new GuardedRunnable(reactContext) {
@Override
public void runGuarded() {
(getReactContext())
.getNativeModule(UIManagerModule.class)
.updateNodeSize(viewTag, viewWidth, viewHeight);
}
});
}
} else {
hasAdjustedSize = true;
}
}
@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);
}
@Override
public void addView(View child, int index, LayoutParams params) {
super.addView(child, index, params);