From 8ba06cbfb1c60980437e38c358a971ff105af245 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=9Cst=C3=BCn=20Ergenoglu?= Date: Sat, 11 Mar 2017 17:22:32 -0800 Subject: [PATCH] Fix wrong modal size in fullscreen Summary: Display.getCurrentSizeRange() doesn't include the size of the status bar, so Modal windows on Android have a gap in the bottom that is the same size as the status bar. This checks the current theme and adds the size of status bar to the modal window height if necessary. **Test plan (required)** Run a React Native app on Android with a theme that doesn't show status bar and launch a modal dialog. See issue #11872 for an example. Closes https://github.com/facebook/react-native/pull/11928 Differential Revision: D4695847 fbshipit-source-id: 9fafc2b5040e2f58d562c9cc4cd4d6d87b0df2a3 --- .../react/views/modal/ModalHostHelper.java | 20 +++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/ReactAndroid/src/main/java/com/facebook/react/views/modal/ModalHostHelper.java b/ReactAndroid/src/main/java/com/facebook/react/views/modal/ModalHostHelper.java index d95b2ee7aa8..d63643266db 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/views/modal/ModalHostHelper.java +++ b/ReactAndroid/src/main/java/com/facebook/react/views/modal/ModalHostHelper.java @@ -4,6 +4,8 @@ package com.facebook.react.views.modal; import android.annotation.TargetApi; import android.content.Context; +import android.content.res.Resources; +import android.content.res.TypedArray; import android.graphics.Point; import android.view.Display; import android.view.WindowManager; @@ -38,12 +40,26 @@ import com.facebook.infer.annotation.Assertions; // getSize will return the dimensions of the screen in its current orientation display.getSize(SIZE_POINT); + int[] attrs = {android.R.attr.windowFullscreen}; + Resources.Theme theme = context.getTheme(); + TypedArray ta = theme.obtainStyledAttributes(attrs); + boolean windowFullscreen = ta.getBoolean(0, false); + + // We need to add the status bar height to the height if we have a fullscreen window, + // because Display.getCurrentSizeRange doesn't include it. + Resources resources = context.getResources(); + int statusBarId = resources.getIdentifier("status_bar_height", "dimen", "android"); + int statusBarHeight = 0; + if (windowFullscreen && statusBarId > 0) { + statusBarHeight = (int) resources.getDimension(statusBarId); + } + if (SIZE_POINT.x < SIZE_POINT.y) { // If we are vertical the width value comes from min width and height comes from max height - return new Point(MIN_POINT.x, MAX_POINT.y); + return new Point(MIN_POINT.x, MAX_POINT.y + statusBarHeight); } else { // If we are horizontal the width value comes from max width and height comes from min height - return new Point(MAX_POINT.x, MIN_POINT.y); + return new Point(MAX_POINT.x, MIN_POINT.y + statusBarHeight); } } }