Skip to content

Commit c41652e

Browse files
mathieubruguierSunhat
authored andcommitted
Fixed getSoftMenuBarHeight() not returning the right value on notched devices (#50)
1 parent da3e749 commit c41652e

File tree

1 file changed

+5
-9
lines changed

1 file changed

+5
-9
lines changed

android/src/main/java/ca/jaysoo/extradimensions/ExtraDimensionsModule.java

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -103,16 +103,12 @@ private float getSoftMenuBarHeight(DisplayMetrics metrics) {
103103
if(hasPermanentMenuKey()) {
104104
return 0;
105105
}
106-
final float realHeight = getRealHeight(metrics);
107106
final Context ctx = getReactApplicationContext();
108-
final DisplayMetrics usableMetrics = ctx.getResources().getDisplayMetrics();
109-
110-
// Passing getMetrics will update the value of the Object DisplayMetrics metrics
111-
((WindowManager) mReactContext.getSystemService(Context.WINDOW_SERVICE))
112-
.getDefaultDisplay().getMetrics(metrics);
113-
final int usableHeight = usableMetrics.heightPixels;
114-
115-
return Math.max(0, realHeight - usableHeight / metrics.density);
107+
final int heightResId = ctx.getResources().getIdentifier("navigation_bar_height", "dimen", "android");
108+
return
109+
heightResId > 0
110+
? ctx.getResources().getDimensionPixelSize(heightResId) / metrics.density
111+
: 0;
116112
}
117113

118114
private float getRealHeight(DisplayMetrics metrics) {

0 commit comments

Comments
 (0)