From b2d3052de7acaed86329c5e8171ef3eb992383b2 Mon Sep 17 00:00:00 2001 From: yukai1 Date: Mon, 25 Feb 2019 01:15:29 -0800 Subject: [PATCH] ModalHostView's child view can not fill screen (#18615) Summary: Signed-off-by: yukai In some Android device such as Samsung S8, the ModalHostView's child view can't fill the screen. before: ![before](https://user-images.githubusercontent.com/1514899/38024961-3e756f8e-32b9-11e8-9555-50a7cf778288.jpeg) The JS ModalHostView can't fill the bottom, the area is device's navigation bar. In class ModalHostShadowNode, follow code calculate is error: `Point modalSize = ModalHostHelper.getModalHostSize(getThemedContext());` This way not care the device's navigation bar, so the height is smaller than real. For Samsung S8, real height is 2220 and modalSize.y is 2076. Pull Request resolved: https://github.com/facebook/react-native/pull/18615 Differential Revision: D14206830 Pulled By: cpojer fbshipit-source-id: abe35ce1ab253aa1472d2c798543b515218be445 --- .../react/views/modal/ReactModalHostView.java | 22 ++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) 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 52075e7be0d..3c3244194fd 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 @@ -327,6 +327,9 @@ public class ReactModalHostView extends ViewGroup implements LifecycleEventListe * UIManagerModule, and will then cause the children to layout as if they can fill the window. */ static class DialogRootViewGroup extends ReactViewGroup implements RootView { + private boolean hasAdjustedSize = false; + private int viewWidth; + private int viewHeight; private final JSTouchDispatcher mJSTouchDispatcher = new JSTouchDispatcher(this); @@ -337,7 +340,14 @@ public class ReactModalHostView extends ViewGroup implements LifecycleEventListe @Override protected void onSizeChanged(final int w, final int h, int oldw, int oldh) { super.onSizeChanged(w, h, oldw, oldh); + viewWidth = w; + viewHeight = h; + updateFirstChildView(); + } + + private void updateFirstChildView() { if (getChildCount() > 0) { + hasAdjustedSize = false; final int viewTag = getChildAt(0).getId(); ReactContext reactContext = getReactContext(); reactContext.runOnNativeModulesQueueThread( @@ -345,9 +355,19 @@ public class ReactModalHostView extends ViewGroup implements LifecycleEventListe @Override public void runGuarded() { (getReactContext()).getNativeModule(UIManagerModule.class) - .updateNodeSize(viewTag, w, h); + .updateNodeSize(viewTag, viewWidth, viewHeight); } }); + } else { + hasAdjustedSize = true; + } + } + + @Override + public void addView(View child, int index, LayoutParams params) { + super.addView(child, index, params); + if (hasAdjustedSize) { + updateFirstChildView(); } }