Skip to content

Commit 82e07f7

Browse files
authored
feat(android): statusBarHeight parity and cutoutSize (#13733)
* test * feat(android): statusBarHeight parity and cutoutSize * remove empty line * apidocs * missing gitignore
1 parent 22d26f8 commit 82e07f7

File tree

2 files changed

+95
-0
lines changed

2 files changed

+95
-0
lines changed

android/modules/ui/src/java/ti/modules/titanium/ui/UIModule.java

+64
Original file line numberDiff line numberDiff line change
@@ -26,16 +26,22 @@
2626
importandroid.content.res.Configuration;
2727
importandroid.content.res.Resources;
2828
importandroid.graphics.Color;
29+
importandroid.graphics.Rect;
2930
importandroid.graphics.drawable.Drawable;
31+
importandroid.os.Build;
3032
importandroid.text.InputType;
3133
importandroid.text.util.Linkify;
34+
importandroid.view.DisplayCutout;
3235
importandroid.view.View;
36+
importandroid.view.Window;
3337
importandroid.webkit.WebViewClient;
3438
importandroid.widget.Toast;
3539

3640
importandroidx.annotation.NonNull;
3741
importandroidx.appcompat.app.AppCompatDelegate;
3842

43+
importjava.util.List;
44+
3945
@Kroll.module
4046
publicclassUIModuleextendsKrollModuleimplementsTiApplication.ConfigurationChangedListener
4147
{
@@ -571,6 +577,64 @@ public int getUserInterfaceStyle()
571577
returngetUserInterfaceStyle(TiApplication.getInstance().getResources().getConfiguration());
572578
}
573579

580+
@Kroll.getProperty
581+
publicintstatusBarHeight()
582+
{
583+
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
584+
Windoww = TiApplication.getAppCurrentActivity().getWindow();
585+
if (w == null) return0;
586+
Viewdv = w.getDecorView();
587+
if (dv == null) return0;
588+
if (dv.getRootWindowInsets() == null) return0;
589+
DisplayCutoutdpc = dv.getRootWindowInsets().getDisplayCutout();
590+
if (dpc == null) return0;
591+
List<Rect> rects = dpc.getBoundingRects();
592+
if (rects.size() > 0) {
593+
inth = dpc.getBoundingRects().get(0).height();
594+
return (int) newTiDimension(h, TiDimension.TYPE_HEIGHT).getAsDefault(dv);
595+
}
596+
}
597+
return0;
598+
}
599+
600+
@Kroll.getProperty
601+
publicKrollDictgetCutoutSize()
602+
{
603+
KrollDictreturnValue = newKrollDict();
604+
returnValue.put("top", 0);
605+
returnValue.put("left", 0);
606+
returnValue.put("height", 0);
607+
returnValue.put("width", 0);
608+
609+
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
610+
Windoww = TiApplication.getAppCurrentActivity().getWindow();
611+
if (w == null) returnreturnValue;
612+
Viewdv = w.getDecorView();
613+
if (dv == null) returnreturnValue;
614+
if (dv.getRootWindowInsets() == null) returnreturnValue;
615+
DisplayCutoutdpc = dv.getRootWindowInsets().getDisplayCutout();
616+
if (dpc == null) returnreturnValue;
617+
List<Rect> rects = dpc.getBoundingRects();
618+
619+
intcutouts = rects.size();
620+
int[] result = newint[cutouts * 4];
621+
intindex = 0;
622+
623+
if (rects.size() > 0) {
624+
intdh = dpc.getBoundingRects().get(0).height();
625+
intdw = dpc.getBoundingRects().get(0).width();
626+
intdt = dpc.getBoundingRects().get(0).top;
627+
intdl = dpc.getBoundingRects().get(0).left;
628+
629+
returnValue.put("left", (int) newTiDimension(dl, TiDimension.TYPE_LEFT).getAsDefault(dv));
630+
returnValue.put("top", (int) newTiDimension(dt, TiDimension.TYPE_TOP).getAsDefault(dv));
631+
returnValue.put("width", (int) newTiDimension(dw, TiDimension.TYPE_WIDTH).getAsDefault(dv));
632+
returnValue.put("height", (int) newTiDimension(dh, TiDimension.TYPE_HEIGHT).getAsDefault(dv));
633+
}
634+
}
635+
returnreturnValue;
636+
}
637+
574638
@Override
575639
publicStringgetApiName()
576640
{

apidoc/Titanium/UI/UI.yml

+31
Original file line numberDiff line numberDiff line change
@@ -2807,6 +2807,15 @@ properties:
28072807
osver: {ios: {min: "13.0"}}
28082808
since: "9.1.0"
28092809

2810+
- name: cutoutSize
2811+
summary: Returns the position and shape of the Android notch. Read more about the notch [here](https://developer.android.com/develop/ui/views/layout/display-cutout).
2812+
description: |
2813+
Using Android 9+ it will return the bounding box of the Android notch. It will return `top`,`left, `width` and `height`.
2814+
type: CutoutSize
2815+
permission: read-only
2816+
platforms: [android]
2817+
since: "12.1.0"
2818+
28102819
- name: statusBarHeight
28112820
summary: The total height of the status bar including safe area padding.
28122821
description: |
@@ -2856,3 +2865,25 @@ examples:
28562865
win.add(table);
28572866
win.open();
28582867
```
2868+
2869+
---
2870+
name: CutoutSize
2871+
summary: Dictionary object of parameters for the <Titanium.UI.cutoutSize>.
2872+
since: "12.1.0"
2873+
platforms: [android]
2874+
properties:
2875+
- name: left
2876+
type: Number
2877+
summary: The left margin of the cutout.
2878+
2879+
- name: right
2880+
type: Number
2881+
summary: The left margin of the cutout.
2882+
2883+
- name: width
2884+
type: Number
2885+
summary: The width of the cutout
2886+
2887+
- name: height
2888+
type: Number
2889+
summary: The height of the cutout

0 commit comments

Comments
 (0)
close