Closed digaus closed 2 years ago
Expected bottom offset to correctly calculate when using
<item name="android:windowTranslucentNavigation">true</item>
in thestyles.xml
, this is not the case :/
OK,I will fix it
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
final WindowInsets cutout = window.getDecorView().getRootWindowInsets();
final float density = activity.getResources().getDisplayMetrics().density;
JSObject json = new JSObject();
json.put("top", cutout.getStableInsetTop() / density);
json.put("bottom", cutout.getStableInsetBottom() / density);
json.put("left", cutout.getStableInsetLeft() / density);
json.put("right", cutout.getStableInsetRight() / density);
ret.put("insets", json);
}
This is how I was able to get correct values
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) { final WindowInsets cutout = window.getDecorView().getRootWindowInsets(); final float density = activity.getResources().getDisplayMetrics().density; JSObject json = new JSObject(); json.put("top", cutout.getStableInsetTop() / density); json.put("bottom", cutout.getStableInsetBottom() / density); json.put("left", cutout.getStableInsetLeft() / density); json.put("right", cutout.getStableInsetRight() / density); ret.put("insets", json); }
This is how I was able to get correct values
Fixed in verison V0.0.6 , please update the npm package 😊
Now android tablet does not return the safe areas anymore. Fixed it this way:
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.P) {
Log.i(SafeAreaPlugin.class.toString(), String.format("Requires at least %d+", Build.VERSION_CODES.P));
return this.result(0, 0, 0, 0);
}
WindowInsets windowInsets = bridge.getActivity().getWindow().getDecorView().getRootWindowInsets();
if (windowInsets == null) {
Log.i(SafeAreaPlugin.class.toString(), "WindowInsets is not available.");
return this.result(0, 0, 0, 0);
}
float density = this.getDensity(bridge);
DisplayCutout displayCutout = windowInsets.getDisplayCutout();
if (displayCutout == null) {
Log.i(SafeAreaPlugin.class.toString(), "DisplayCutout is not available.");
int top = Math.round(windowInsets.getStableInsetTop() / density);
int left = Math.round(windowInsets.getStableInsetLeft() / density);
int right = Math.round(windowInsets.getStableInsetRight() / density);
int bottom = Math.round(windowInsets.getStableInsetBottom() / density);
return this.result(top, left, right, bottom);
}
int top = Math.round(displayCutout.getSafeInsetTop() / density);
int left = Math.round(displayCutout.getSafeInsetLeft() / density);
int right = Math.round(displayCutout.getSafeInsetRight() / density);
int bottom = Math.round(displayCutout.getSafeInsetBottom() / density);
return this.result(top, left, right, bottom);
Now android tablet does not return the safe areas anymore. Fixed it this way:
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.P) { Log.i(SafeAreaPlugin.class.toString(), String.format("Requires at least %d+", Build.VERSION_CODES.P)); return this.result(0, 0, 0, 0); } WindowInsets windowInsets = bridge.getActivity().getWindow().getDecorView().getRootWindowInsets(); if (windowInsets == null) { Log.i(SafeAreaPlugin.class.toString(), "WindowInsets is not available."); return this.result(0, 0, 0, 0); } float density = this.getDensity(bridge); DisplayCutout displayCutout = windowInsets.getDisplayCutout(); if (displayCutout == null) { Log.i(SafeAreaPlugin.class.toString(), "DisplayCutout is not available."); int top = Math.round(windowInsets.getStableInsetTop() / density); int left = Math.round(windowInsets.getStableInsetLeft() / density); int right = Math.round(windowInsets.getStableInsetRight() / density); int bottom = Math.round(windowInsets.getStableInsetBottom() / density); return this.result(top, left, right, bottom); } int top = Math.round(displayCutout.getSafeInsetTop() / density); int left = Math.round(displayCutout.getSafeInsetLeft() / density); int right = Math.round(displayCutout.getSafeInsetRight() / density); int bottom = Math.round(displayCutout.getSafeInsetBottom() / density); return this.result(top, left, right, bottom);
fixed in lastest version
displayCutout.getSafeInsetBottom
does not return correct value on Samsung S10e device. I think we should always use windowInsets.getStableInsetBottom()
and not use displayCutout
at all. So far windowInsets.getStableInsetBottom()
always worked correctly for me.
Samsung S10e device
I have no Samsung S10e device ,but i think you may right, it will deprecated displayCutout in version 0.0.10
Samsung S10e device
I have no Samsung S10e device ,but i think you may right, it will deprecated displayCutout in version 0.0.10
I am currently also testing on an older device and you should allow all version newer than M
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) {
Log.i(SafeAreaPlugin.class.toString(), String.format("Requires at least %d+", Build.VERSION_CODES.P));
return this.result(0, 0, 0, 0);
}
@AlwaysLoveme can you change the version to Build.VERSION_CODES.M
instead of Build.VERSION_CODES.P
? Tested on Android 6.0.1 Galaxy A3
Expected bottom offset to correctly calculate when using
<item name="android:windowTranslucentNavigation">true</item>
in thestyles.xml
, this is not the case :/