Skip to content

Commit

Permalink
Merge pull request #12 from Menardi/android-9-safe-area
Browse files Browse the repository at this point in the history
Add support for insets on Android 9 and below
  • Loading branch information
Aashu-Dubey authored May 19, 2024
2 parents 8f45219 + e4ad1ee commit db481e1
Showing 1 changed file with 13 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,10 @@ public void getSafeAreaInsets(PluginCall call) {
Resources res = getActivity().getApplicationContext().getResources();
WindowInsets windowInsets = getActivity().getWindow().getDecorView().getRootWindowInsets();

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
if (windowInsets != null) {
if (windowInsets != null) {
float density = res.getDisplayMetrics().density;

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
final DisplayCutout cutout = windowInsets.getDisplayCutout();

leftInset = cutout != null ? cutout.getSafeInsetLeft() : 0;
Expand All @@ -48,10 +50,15 @@ public void getSafeAreaInsets(PluginCall call) {
bottomInset = cutout != null ? cutout.getSafeInsetBottom() : 0;

Insets insets = windowInsets.getSystemWindowInsets();
leftInset = Math.max(leftInset, insets.left) / res.getDisplayMetrics().density;
rightInset = Math.max(rightInset, insets.right) / res.getDisplayMetrics().density;
topInset = Math.max(topInset, insets.top) / res.getDisplayMetrics().density;
bottomInset = Math.max(bottomInset, insets.bottom) / res.getDisplayMetrics().density;
leftInset = Math.max(leftInset, insets.left) / density;
rightInset = Math.max(rightInset, insets.right) / density;
topInset = Math.max(topInset, insets.top) / density;
bottomInset = Math.max(bottomInset, insets.bottom) / density;
} else {
leftInset = windowInsets.getSystemWindowInsetLeft() / density;
rightInset = windowInsets.getSystemWindowInsetRight() / density;
topInset = windowInsets.getSystemWindowInsetTop() / density;
bottomInset = windowInsets.getSystemWindowInsetBottom() / density;
}
}
}
Expand Down

0 comments on commit db481e1

Please sign in to comment.