Skip to content

Commit

Permalink
uses getRealMetrics on display to get real height metrics
Browse files Browse the repository at this point in the history
  • Loading branch information
jaysoo committed Dec 23, 2015
1 parent cdb86a6 commit af5906c
Showing 1 changed file with 22 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit af5906c

Please sign in to comment.