From af5906cdb16d74c002b6c226e38a72f9d3de765e Mon Sep 17 00:00:00 2001 From: Jack Hsu Date: Tue, 22 Dec 2015 20:03:44 -0500 Subject: [PATCH] uses getRealMetrics on display to get real height metrics --- .../react/uimanager/UIManagerModule.java | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/ReactAndroid/src/main/java/com/facebook/react/uimanager/UIManagerModule.java b/ReactAndroid/src/main/java/com/facebook/react/uimanager/UIManagerModule.java index b352f4d53e61bf..2e3ab3e3aafd39 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/uimanager/UIManagerModule.java +++ b/ReactAndroid/src/main/java/com/facebook/react/uimanager/UIManagerModule.java @@ -9,13 +9,18 @@ package com.facebook.react.uimanager; +import java.lang.reflect.InvocationTargetException; import javax.annotation.Nullable; import java.util.Arrays; import java.util.List; import java.util.Map; +import android.content.Context; +import android.os.Build; import android.util.DisplayMetrics; +import android.view.Display; +import android.view.WindowManager; import com.facebook.csslayout.CSSLayoutContext; import com.facebook.infer.annotation.Assertions; @@ -85,6 +90,23 @@ public UIManagerModule( super(reactContext); mEventDispatcher = new EventDispatcher(reactContext); DisplayMetrics displayMetrics = reactContext.getResources().getDisplayMetrics(); + + // Get the real display metrics if we are using API level 17 or higher. + // The real metrics include system decor elements (e.g. soft menu bar). + // + // See: http://developer.android.com/reference/android/view/Display.html#getRealMetrics(android.util.DisplayMetrics) + if (Build.VERSION.SDK_INT >= 17) { + WindowManager wm = (WindowManager)reactContext.getApplicationContext().getSystemService(Context.WINDOW_SERVICE); + + try { + Display display = wm.getDefaultDisplay(); + Display.class.getMethod("getRealMetrics", DisplayMetrics.class).invoke(display, displayMetrics); + } catch (InvocationTargetException e) { + } catch (IllegalAccessException e) { + } catch (NoSuchMethodException e) { + } + } + DisplayMetricsHolder.setDisplayMetrics(displayMetrics); mModuleConstants = createConstants(displayMetrics, viewManagerList); mUIImplementation = uiImplementation;