@hiloenergie/capacitor-plugin-safe-area 0.0.8 → 0.0.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/HiloenergieCapacitorPluginSafeArea.podspec +17 -17
- package/android/build.gradle +58 -58
- package/android/src/main/AndroidManifest.xml +2 -3
- package/android/src/main/java/com/getcapacitor/community/plugins/safearea/SafeAreaPlugin.java +158 -158
- package/android/src/main/java/com/getcapacitor/community/plugins/safearea/SafeAreaView.java +48 -48
- package/dist/docs.json +25 -9
- package/dist/esm/controller.d.ts +18 -18
- package/dist/esm/controller.js +73 -73
- package/dist/esm/controller.js.map +1 -1
- package/dist/esm/definitions.d.ts +18 -18
- package/dist/esm/definitions.js +2 -2
- package/dist/esm/index.d.ts +5 -5
- package/dist/esm/index.js +9 -9
- package/dist/esm/web.d.ts +12 -12
- package/dist/esm/web.js +32 -32
- package/dist/plugin.cjs.js +102 -102
- package/dist/plugin.cjs.js.map +1 -1
- package/dist/plugin.js +103 -103
- package/dist/plugin.js.map +1 -1
- package/ios/Plugin/SafeAreaPlugin.h +10 -10
- package/ios/Plugin/SafeAreaPlugin.m +9 -9
- package/ios/Plugin/SafeAreaPlugin.swift +139 -139
- package/package.json +75 -75
|
@@ -1,17 +1,17 @@
|
|
|
1
|
-
require 'json'
|
|
2
|
-
|
|
3
|
-
package = JSON.parse(File.read(File.join(__dir__, 'package.json')))
|
|
4
|
-
|
|
5
|
-
Pod::Spec.new do |s|
|
|
6
|
-
s.name = 'HiloenergieCapacitorPluginSafeArea'
|
|
7
|
-
s.version = package['version']
|
|
8
|
-
s.summary = package['description']
|
|
9
|
-
s.license = package['license']
|
|
10
|
-
s.homepage = package['repository']['url']
|
|
11
|
-
s.author = package['author']
|
|
12
|
-
s.source = { :git => package['repository']['url'], :tag => s.version.to_s }
|
|
13
|
-
s.source_files = 'ios/Plugin/**/*.{swift,h,m,c,cc,mm,cpp}'
|
|
14
|
-
s.ios.deployment_target = '
|
|
15
|
-
s.dependency 'Capacitor'
|
|
16
|
-
s.swift_version = '5.1'
|
|
17
|
-
end
|
|
1
|
+
require 'json'
|
|
2
|
+
|
|
3
|
+
package = JSON.parse(File.read(File.join(__dir__, 'package.json')))
|
|
4
|
+
|
|
5
|
+
Pod::Spec.new do |s|
|
|
6
|
+
s.name = 'HiloenergieCapacitorPluginSafeArea'
|
|
7
|
+
s.version = package['version']
|
|
8
|
+
s.summary = package['description']
|
|
9
|
+
s.license = package['license']
|
|
10
|
+
s.homepage = package['repository']['url']
|
|
11
|
+
s.author = package['author']
|
|
12
|
+
s.source = { :git => package['repository']['url'], :tag => s.version.to_s }
|
|
13
|
+
s.source_files = 'ios/Plugin/**/*.{swift,h,m,c,cc,mm,cpp}'
|
|
14
|
+
s.ios.deployment_target = '14.0'
|
|
15
|
+
s.dependency 'Capacitor'
|
|
16
|
+
s.swift_version = '5.1'
|
|
17
|
+
end
|
package/android/build.gradle
CHANGED
|
@@ -1,58 +1,58 @@
|
|
|
1
|
-
ext {
|
|
2
|
-
junitVersion = project.hasProperty('junitVersion') ? rootProject.ext.junitVersion : '4.13.
|
|
3
|
-
androidxAppCompatVersion = project.hasProperty('androidxAppCompatVersion') ? rootProject.ext.androidxAppCompatVersion : '1.2
|
|
4
|
-
androidxJunitVersion = project.hasProperty('androidxJunitVersion') ? rootProject.ext.androidxJunitVersion : '1.1.
|
|
5
|
-
androidxEspressoCoreVersion = project.hasProperty('androidxEspressoCoreVersion') ? rootProject.ext.androidxEspressoCoreVersion : '3.
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
buildscript {
|
|
9
|
-
repositories {
|
|
10
|
-
google()
|
|
11
|
-
|
|
12
|
-
}
|
|
13
|
-
dependencies {
|
|
14
|
-
classpath 'com.android.tools.build:gradle:
|
|
15
|
-
}
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
apply plugin: 'com.android.library'
|
|
19
|
-
|
|
20
|
-
android {
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
mavenCentral()
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
dependencies {
|
|
52
|
-
implementation fileTree(dir: 'libs', include: ['*.jar'])
|
|
53
|
-
implementation project(':capacitor-android')
|
|
54
|
-
implementation "androidx.appcompat:appcompat:$androidxAppCompatVersion"
|
|
55
|
-
testImplementation "junit:junit:$junitVersion"
|
|
56
|
-
androidTestImplementation "androidx.test.ext:junit:$androidxJunitVersion"
|
|
57
|
-
androidTestImplementation "androidx.test.espresso:espresso-core:$androidxEspressoCoreVersion"
|
|
58
|
-
}
|
|
1
|
+
ext {
|
|
2
|
+
junitVersion = project.hasProperty('junitVersion') ? rootProject.ext.junitVersion : '4.13.2'
|
|
3
|
+
androidxAppCompatVersion = project.hasProperty('androidxAppCompatVersion') ? rootProject.ext.androidxAppCompatVersion : '1.4.2'
|
|
4
|
+
androidxJunitVersion = project.hasProperty('androidxJunitVersion') ? rootProject.ext.androidxJunitVersion : '1.1.3'
|
|
5
|
+
androidxEspressoCoreVersion = project.hasProperty('androidxEspressoCoreVersion') ? rootProject.ext.androidxEspressoCoreVersion : '3.4.0'
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
buildscript {
|
|
9
|
+
repositories {
|
|
10
|
+
google()
|
|
11
|
+
mavenCentral()
|
|
12
|
+
}
|
|
13
|
+
dependencies {
|
|
14
|
+
classpath 'com.android.tools.build:gradle:8.0.0'
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
apply plugin: 'com.android.library'
|
|
19
|
+
|
|
20
|
+
android {
|
|
21
|
+
namespace "com.getcapacitor.community.plugins.safearea"
|
|
22
|
+
compileSdkVersion project.hasProperty('compileSdkVersion') ? rootProject.ext.compileSdkVersion : 32
|
|
23
|
+
defaultConfig {
|
|
24
|
+
minSdkVersion project.hasProperty('minSdkVersion') ? rootProject.ext.minSdkVersion : 22
|
|
25
|
+
targetSdkVersion project.hasProperty('targetSdkVersion') ? rootProject.ext.targetSdkVersion : 32
|
|
26
|
+
versionCode 1
|
|
27
|
+
versionName "1.0"
|
|
28
|
+
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
|
|
29
|
+
}
|
|
30
|
+
buildTypes {
|
|
31
|
+
release {
|
|
32
|
+
minifyEnabled false
|
|
33
|
+
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
lintOptions {
|
|
37
|
+
abortOnError false
|
|
38
|
+
}
|
|
39
|
+
compileOptions {
|
|
40
|
+
sourceCompatibility JavaVersion.VERSION_11
|
|
41
|
+
targetCompatibility JavaVersion.VERSION_11
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
repositories {
|
|
46
|
+
google()
|
|
47
|
+
mavenCentral()
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
dependencies {
|
|
52
|
+
implementation fileTree(dir: 'libs', include: ['*.jar'])
|
|
53
|
+
implementation project(':capacitor-android')
|
|
54
|
+
implementation "androidx.appcompat:appcompat:$androidxAppCompatVersion"
|
|
55
|
+
testImplementation "junit:junit:$junitVersion"
|
|
56
|
+
androidTestImplementation "androidx.test.ext:junit:$androidxJunitVersion"
|
|
57
|
+
androidTestImplementation "androidx.test.espresso:espresso-core:$androidxEspressoCoreVersion"
|
|
58
|
+
}
|
|
@@ -1,3 +1,2 @@
|
|
|
1
|
-
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
|
2
|
-
|
|
3
|
-
</manifest>
|
|
1
|
+
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
|
|
2
|
+
</manifest>
|
package/android/src/main/java/com/getcapacitor/community/plugins/safearea/SafeAreaPlugin.java
CHANGED
|
@@ -1,158 +1,158 @@
|
|
|
1
|
-
package com.getcapacitor.community.plugins.safearea;
|
|
2
|
-
|
|
3
|
-
import android.annotation.SuppressLint;
|
|
4
|
-
import android.graphics.Insets;
|
|
5
|
-
import android.os.Build;
|
|
6
|
-
import android.view.DisplayCutout;
|
|
7
|
-
import android.view.View;
|
|
8
|
-
import android.view.ViewGroup;
|
|
9
|
-
import android.view.WindowInsets;
|
|
10
|
-
import android.widget.FrameLayout;
|
|
11
|
-
|
|
12
|
-
import com.getcapacitor.JSObject;
|
|
13
|
-
import com.getcapacitor.Plugin;
|
|
14
|
-
import com.getcapacitor.PluginCall;
|
|
15
|
-
import com.getcapacitor.PluginMethod;
|
|
16
|
-
import com.getcapacitor.annotation.CapacitorPlugin;
|
|
17
|
-
|
|
18
|
-
@CapacitorPlugin(name = "SafeArea")
|
|
19
|
-
public class SafeAreaPlugin extends Plugin {
|
|
20
|
-
private static final String KEY_INSET = "insets";
|
|
21
|
-
private static final String EVENT_ON_INSETS_CHANGED = "safeAreaPluginsInsetChange";
|
|
22
|
-
private SafeAreaInsets safeAreaInsets = new com.getcapacitor.community.plugins.safearea.SafeAreaInsets();
|
|
23
|
-
private SafeAreaView safeAreaView;
|
|
24
|
-
|
|
25
|
-
@Override
|
|
26
|
-
public void load() {
|
|
27
|
-
this.getBridge().getActivity().runOnUiThread(() -> {
|
|
28
|
-
safeAreaView = new SafeAreaView(this.getBridge().getActivity(), (WindowInsets insets) -> {
|
|
29
|
-
this.getSafeArea(insets);
|
|
30
|
-
this.doNotify();
|
|
31
|
-
});
|
|
32
|
-
|
|
33
|
-
FrameLayout.LayoutParams safeAreaPreviewParams = new FrameLayout.LayoutParams(
|
|
34
|
-
FrameLayout.LayoutParams.MATCH_PARENT,
|
|
35
|
-
FrameLayout.LayoutParams.MATCH_PARENT
|
|
36
|
-
);
|
|
37
|
-
|
|
38
|
-
// Set SafeAreaView as sibling View of WebView
|
|
39
|
-
((ViewGroup) this.getBridge().getWebView().getParent()).addView(safeAreaView, safeAreaPreviewParams);
|
|
40
|
-
|
|
41
|
-
// Bring the WebView in front of the SafeAreaView
|
|
42
|
-
this.getBridge().getWebView().bringToFront();
|
|
43
|
-
});
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
@PluginMethod
|
|
47
|
-
public void refresh(PluginCall call) {
|
|
48
|
-
this.doNotify();
|
|
49
|
-
call.success();
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
@PluginMethod
|
|
53
|
-
public void getSafeAreaInsets(PluginCall call) {
|
|
54
|
-
JSObject ret = new JSObject();
|
|
55
|
-
|
|
56
|
-
ret.put(SafeAreaPlugin.KEY_INSET, this.safeAreaInsets.toJSON());
|
|
57
|
-
|
|
58
|
-
call.success(ret);
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
protected void getSafeArea(WindowInsets windowInsets) {
|
|
62
|
-
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
|
|
63
|
-
this.getSafeAreaR(windowInsets);
|
|
64
|
-
} else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
|
|
65
|
-
this.getSafeAreaQ(windowInsets);
|
|
66
|
-
} else {
|
|
67
|
-
this.getSafeAreaLollipop(windowInsets);
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
// Cutout
|
|
71
|
-
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.P) {
|
|
72
|
-
this.getSafeAreaCutout(windowInsets);
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
float density = this.getBridge().getActivity().getResources().getDisplayMetrics().density;
|
|
76
|
-
|
|
77
|
-
this.applySafeAreaInsets(
|
|
78
|
-
Math.round(this.safeAreaInsets.top() / density),
|
|
79
|
-
Math.round(this.safeAreaInsets.bottom() / density),
|
|
80
|
-
Math.round(this.safeAreaInsets.left() / density),
|
|
81
|
-
Math.round(this.safeAreaInsets.right() / density)
|
|
82
|
-
);
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
// api level 30
|
|
86
|
-
// Get insets (Mandatory System Gestures: https://developer.android.com/reference/android/view/WindowInsets#getMandatorySystemGestureInsets())
|
|
87
|
-
@SuppressLint("NewApi")
|
|
88
|
-
protected void getSafeAreaR(WindowInsets windowInsets) {
|
|
89
|
-
Insets finalInsets = windowInsets.getInsets(WindowInsets.Type.mandatorySystemGestures());
|
|
90
|
-
|
|
91
|
-
this.applySafeAreaInsets(
|
|
92
|
-
finalInsets.top,
|
|
93
|
-
finalInsets.bottom,
|
|
94
|
-
finalInsets.left,
|
|
95
|
-
finalInsets.right
|
|
96
|
-
);
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
// api level 29
|
|
100
|
-
@SuppressLint("NewApi")
|
|
101
|
-
protected void getSafeAreaQ(WindowInsets windowInsets) {
|
|
102
|
-
Insets finalInsets = windowInsets.getMandatorySystemGestureInsets();
|
|
103
|
-
|
|
104
|
-
this.applySafeAreaInsets(
|
|
105
|
-
finalInsets.top,
|
|
106
|
-
finalInsets.bottom,
|
|
107
|
-
finalInsets.left,
|
|
108
|
-
finalInsets.right
|
|
109
|
-
);
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
// api level 21
|
|
113
|
-
protected void getSafeAreaLollipop(WindowInsets windowInsets) {
|
|
114
|
-
this.applySafeAreaInsets(
|
|
115
|
-
windowInsets.getSystemWindowInsetTop(),
|
|
116
|
-
windowInsets.getStableInsetBottom(),
|
|
117
|
-
windowInsets.getStableInsetLeft(),
|
|
118
|
-
windowInsets.getStableInsetRight()
|
|
119
|
-
);
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
// cutout (api level >= 28)
|
|
123
|
-
@SuppressLint("NewApi")
|
|
124
|
-
protected void getSafeAreaCutout(WindowInsets windowInsets) {
|
|
125
|
-
DisplayCutout cutout = windowInsets.getDisplayCutout();
|
|
126
|
-
if (cutout != null) {
|
|
127
|
-
this.applySafeAreaInsets(
|
|
128
|
-
Math.max(this.safeAreaInsets.top(), cutout.getSafeInsetTop()),
|
|
129
|
-
Math.max(this.safeAreaInsets.bottom(), cutout.getSafeInsetBottom()),
|
|
130
|
-
Math.max(this.safeAreaInsets.left(), cutout.getSafeInsetLeft()),
|
|
131
|
-
Math.max(this.safeAreaInsets.right(), cutout.getSafeInsetRight())
|
|
132
|
-
);
|
|
133
|
-
}
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
protected void doNotify() {
|
|
137
|
-
JSObject ret = new JSObject();
|
|
138
|
-
|
|
139
|
-
ret.put(SafeAreaPlugin.KEY_INSET, this.safeAreaInsets.toJSON());
|
|
140
|
-
|
|
141
|
-
this.notifyListeners(SafeAreaPlugin.EVENT_ON_INSETS_CHANGED, ret);
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
private void applySafeAreaInsets(int top, int bottom, int left, int right) {
|
|
145
|
-
View decorView = this.getBridge().getActivity().getWindow().getDecorView();
|
|
146
|
-
int uiVisibility = decorView.getSystemUiVisibility();
|
|
147
|
-
|
|
148
|
-
if ((uiVisibility & View.SYSTEM_UI_FLAG_HIDE_NAVIGATION) == View.SYSTEM_UI_FLAG_HIDE_NAVIGATION) {
|
|
149
|
-
this.safeAreaInsets.bottom(bottom);
|
|
150
|
-
} else {
|
|
151
|
-
this.safeAreaInsets.bottom(0);
|
|
152
|
-
}
|
|
153
|
-
|
|
154
|
-
this.safeAreaInsets.top(top);
|
|
155
|
-
this.safeAreaInsets.right(left);
|
|
156
|
-
this.safeAreaInsets.left(right);
|
|
157
|
-
}
|
|
158
|
-
}
|
|
1
|
+
package com.getcapacitor.community.plugins.safearea;
|
|
2
|
+
|
|
3
|
+
import android.annotation.SuppressLint;
|
|
4
|
+
import android.graphics.Insets;
|
|
5
|
+
import android.os.Build;
|
|
6
|
+
import android.view.DisplayCutout;
|
|
7
|
+
import android.view.View;
|
|
8
|
+
import android.view.ViewGroup;
|
|
9
|
+
import android.view.WindowInsets;
|
|
10
|
+
import android.widget.FrameLayout;
|
|
11
|
+
|
|
12
|
+
import com.getcapacitor.JSObject;
|
|
13
|
+
import com.getcapacitor.Plugin;
|
|
14
|
+
import com.getcapacitor.PluginCall;
|
|
15
|
+
import com.getcapacitor.PluginMethod;
|
|
16
|
+
import com.getcapacitor.annotation.CapacitorPlugin;
|
|
17
|
+
|
|
18
|
+
@CapacitorPlugin(name = "SafeArea")
|
|
19
|
+
public class SafeAreaPlugin extends Plugin {
|
|
20
|
+
private static final String KEY_INSET = "insets";
|
|
21
|
+
private static final String EVENT_ON_INSETS_CHANGED = "safeAreaPluginsInsetChange";
|
|
22
|
+
private SafeAreaInsets safeAreaInsets = new com.getcapacitor.community.plugins.safearea.SafeAreaInsets();
|
|
23
|
+
private SafeAreaView safeAreaView;
|
|
24
|
+
|
|
25
|
+
@Override
|
|
26
|
+
public void load() {
|
|
27
|
+
this.getBridge().getActivity().runOnUiThread(() -> {
|
|
28
|
+
safeAreaView = new SafeAreaView(this.getBridge().getActivity(), (WindowInsets insets) -> {
|
|
29
|
+
this.getSafeArea(insets);
|
|
30
|
+
this.doNotify();
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
FrameLayout.LayoutParams safeAreaPreviewParams = new FrameLayout.LayoutParams(
|
|
34
|
+
FrameLayout.LayoutParams.MATCH_PARENT,
|
|
35
|
+
FrameLayout.LayoutParams.MATCH_PARENT
|
|
36
|
+
);
|
|
37
|
+
|
|
38
|
+
// Set SafeAreaView as sibling View of WebView
|
|
39
|
+
((ViewGroup) this.getBridge().getWebView().getParent()).addView(safeAreaView, safeAreaPreviewParams);
|
|
40
|
+
|
|
41
|
+
// Bring the WebView in front of the SafeAreaView
|
|
42
|
+
this.getBridge().getWebView().bringToFront();
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
@PluginMethod
|
|
47
|
+
public void refresh(PluginCall call) {
|
|
48
|
+
this.doNotify();
|
|
49
|
+
call.success();
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
@PluginMethod
|
|
53
|
+
public void getSafeAreaInsets(PluginCall call) {
|
|
54
|
+
JSObject ret = new JSObject();
|
|
55
|
+
|
|
56
|
+
ret.put(SafeAreaPlugin.KEY_INSET, this.safeAreaInsets.toJSON());
|
|
57
|
+
|
|
58
|
+
call.success(ret);
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
protected void getSafeArea(WindowInsets windowInsets) {
|
|
62
|
+
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
|
|
63
|
+
this.getSafeAreaR(windowInsets);
|
|
64
|
+
} else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
|
|
65
|
+
this.getSafeAreaQ(windowInsets);
|
|
66
|
+
} else {
|
|
67
|
+
this.getSafeAreaLollipop(windowInsets);
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
// Cutout
|
|
71
|
+
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.P) {
|
|
72
|
+
this.getSafeAreaCutout(windowInsets);
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
float density = this.getBridge().getActivity().getResources().getDisplayMetrics().density;
|
|
76
|
+
|
|
77
|
+
this.applySafeAreaInsets(
|
|
78
|
+
Math.round(this.safeAreaInsets.top() / density),
|
|
79
|
+
Math.round(this.safeAreaInsets.bottom() / density),
|
|
80
|
+
Math.round(this.safeAreaInsets.left() / density),
|
|
81
|
+
Math.round(this.safeAreaInsets.right() / density)
|
|
82
|
+
);
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
// api level 30
|
|
86
|
+
// Get insets (Mandatory System Gestures: https://developer.android.com/reference/android/view/WindowInsets#getMandatorySystemGestureInsets())
|
|
87
|
+
@SuppressLint("NewApi")
|
|
88
|
+
protected void getSafeAreaR(WindowInsets windowInsets) {
|
|
89
|
+
Insets finalInsets = windowInsets.getInsets(WindowInsets.Type.mandatorySystemGestures());
|
|
90
|
+
|
|
91
|
+
this.applySafeAreaInsets(
|
|
92
|
+
finalInsets.top,
|
|
93
|
+
finalInsets.bottom,
|
|
94
|
+
finalInsets.left,
|
|
95
|
+
finalInsets.right
|
|
96
|
+
);
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
// api level 29
|
|
100
|
+
@SuppressLint("NewApi")
|
|
101
|
+
protected void getSafeAreaQ(WindowInsets windowInsets) {
|
|
102
|
+
Insets finalInsets = windowInsets.getMandatorySystemGestureInsets();
|
|
103
|
+
|
|
104
|
+
this.applySafeAreaInsets(
|
|
105
|
+
finalInsets.top,
|
|
106
|
+
finalInsets.bottom,
|
|
107
|
+
finalInsets.left,
|
|
108
|
+
finalInsets.right
|
|
109
|
+
);
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
// api level 21
|
|
113
|
+
protected void getSafeAreaLollipop(WindowInsets windowInsets) {
|
|
114
|
+
this.applySafeAreaInsets(
|
|
115
|
+
windowInsets.getSystemWindowInsetTop(),
|
|
116
|
+
windowInsets.getStableInsetBottom(),
|
|
117
|
+
windowInsets.getStableInsetLeft(),
|
|
118
|
+
windowInsets.getStableInsetRight()
|
|
119
|
+
);
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
// cutout (api level >= 28)
|
|
123
|
+
@SuppressLint("NewApi")
|
|
124
|
+
protected void getSafeAreaCutout(WindowInsets windowInsets) {
|
|
125
|
+
DisplayCutout cutout = windowInsets.getDisplayCutout();
|
|
126
|
+
if (cutout != null) {
|
|
127
|
+
this.applySafeAreaInsets(
|
|
128
|
+
Math.max(this.safeAreaInsets.top(), cutout.getSafeInsetTop()),
|
|
129
|
+
Math.max(this.safeAreaInsets.bottom(), cutout.getSafeInsetBottom()),
|
|
130
|
+
Math.max(this.safeAreaInsets.left(), cutout.getSafeInsetLeft()),
|
|
131
|
+
Math.max(this.safeAreaInsets.right(), cutout.getSafeInsetRight())
|
|
132
|
+
);
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
protected void doNotify() {
|
|
137
|
+
JSObject ret = new JSObject();
|
|
138
|
+
|
|
139
|
+
ret.put(SafeAreaPlugin.KEY_INSET, this.safeAreaInsets.toJSON());
|
|
140
|
+
|
|
141
|
+
this.notifyListeners(SafeAreaPlugin.EVENT_ON_INSETS_CHANGED, ret);
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
private void applySafeAreaInsets(int top, int bottom, int left, int right) {
|
|
145
|
+
View decorView = this.getBridge().getActivity().getWindow().getDecorView();
|
|
146
|
+
int uiVisibility = decorView.getSystemUiVisibility();
|
|
147
|
+
|
|
148
|
+
if ((uiVisibility & View.SYSTEM_UI_FLAG_HIDE_NAVIGATION) == View.SYSTEM_UI_FLAG_HIDE_NAVIGATION) {
|
|
149
|
+
this.safeAreaInsets.bottom(bottom);
|
|
150
|
+
} else {
|
|
151
|
+
this.safeAreaInsets.bottom(0);
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
this.safeAreaInsets.top(top);
|
|
155
|
+
this.safeAreaInsets.right(left);
|
|
156
|
+
this.safeAreaInsets.left(right);
|
|
157
|
+
}
|
|
158
|
+
}
|
|
@@ -1,49 +1,49 @@
|
|
|
1
|
-
package com.getcapacitor.community.plugins.safearea;
|
|
2
|
-
|
|
3
|
-
import android.content.Context;
|
|
4
|
-
import android.util.AttributeSet;
|
|
5
|
-
import android.view.View;
|
|
6
|
-
import android.view.WindowInsets;
|
|
7
|
-
import java.util.function.Consumer;
|
|
8
|
-
|
|
9
|
-
/**
|
|
10
|
-
* SafeArea View
|
|
11
|
-
* WindowInsets monitor
|
|
12
|
-
*/
|
|
13
|
-
public class SafeAreaView extends View {
|
|
14
|
-
private Consumer<WindowInsets> callbackInsets;
|
|
15
|
-
|
|
16
|
-
public SafeAreaView(Context context) {
|
|
17
|
-
super(context);
|
|
18
|
-
init(null, 0, null);
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
public SafeAreaView(Context context, Consumer<WindowInsets> onApplyInsets) {
|
|
22
|
-
super(context);
|
|
23
|
-
init(null, 0, onApplyInsets);
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
public SafeAreaView(Context context, AttributeSet attrs) {
|
|
27
|
-
super(context, attrs);
|
|
28
|
-
init(attrs, 0, null);
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
public SafeAreaView(Context context, AttributeSet attrs, int defStyle) {
|
|
32
|
-
super(context, attrs, defStyle);
|
|
33
|
-
init(attrs, defStyle, null);
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
private void init(AttributeSet attrs, int defStyle, Consumer<WindowInsets> onApplyInsets) {
|
|
37
|
-
if (onApplyInsets == null) {
|
|
38
|
-
this.callbackInsets = (WindowInsets wInsts) -> {};
|
|
39
|
-
} else {
|
|
40
|
-
this.callbackInsets = onApplyInsets;
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
@Override
|
|
45
|
-
public WindowInsets onApplyWindowInsets(WindowInsets insets) {
|
|
46
|
-
this.callbackInsets.accept(insets);
|
|
47
|
-
return super.onApplyWindowInsets(insets);
|
|
48
|
-
}
|
|
1
|
+
package com.getcapacitor.community.plugins.safearea;
|
|
2
|
+
|
|
3
|
+
import android.content.Context;
|
|
4
|
+
import android.util.AttributeSet;
|
|
5
|
+
import android.view.View;
|
|
6
|
+
import android.view.WindowInsets;
|
|
7
|
+
import java.util.function.Consumer;
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* SafeArea View
|
|
11
|
+
* WindowInsets monitor
|
|
12
|
+
*/
|
|
13
|
+
public class SafeAreaView extends View {
|
|
14
|
+
private Consumer<WindowInsets> callbackInsets;
|
|
15
|
+
|
|
16
|
+
public SafeAreaView(Context context) {
|
|
17
|
+
super(context);
|
|
18
|
+
init(null, 0, null);
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
public SafeAreaView(Context context, Consumer<WindowInsets> onApplyInsets) {
|
|
22
|
+
super(context);
|
|
23
|
+
init(null, 0, onApplyInsets);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
public SafeAreaView(Context context, AttributeSet attrs) {
|
|
27
|
+
super(context, attrs);
|
|
28
|
+
init(attrs, 0, null);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
public SafeAreaView(Context context, AttributeSet attrs, int defStyle) {
|
|
32
|
+
super(context, attrs, defStyle);
|
|
33
|
+
init(attrs, defStyle, null);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
private void init(AttributeSet attrs, int defStyle, Consumer<WindowInsets> onApplyInsets) {
|
|
37
|
+
if (onApplyInsets == null) {
|
|
38
|
+
this.callbackInsets = (WindowInsets wInsts) -> {};
|
|
39
|
+
} else {
|
|
40
|
+
this.callbackInsets = onApplyInsets;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
@Override
|
|
45
|
+
public WindowInsets onApplyWindowInsets(WindowInsets insets) {
|
|
46
|
+
this.callbackInsets.accept(insets);
|
|
47
|
+
return super.onApplyWindowInsets(insets);
|
|
48
|
+
}
|
|
49
49
|
}
|
package/dist/docs.json
CHANGED
|
@@ -7,9 +7,9 @@
|
|
|
7
7
|
"methods": [
|
|
8
8
|
{
|
|
9
9
|
"name": "refresh",
|
|
10
|
-
"signature": "() =>
|
|
10
|
+
"signature": "() => Promise<void>",
|
|
11
11
|
"parameters": [],
|
|
12
|
-
"returns": "
|
|
12
|
+
"returns": "Promise<void>",
|
|
13
13
|
"tags": [],
|
|
14
14
|
"docs": "",
|
|
15
15
|
"complexTypes": [],
|
|
@@ -17,9 +17,9 @@
|
|
|
17
17
|
},
|
|
18
18
|
{
|
|
19
19
|
"name": "getSafeAreaInsets",
|
|
20
|
-
"signature": "() =>
|
|
20
|
+
"signature": "() => Promise<SafeAreaInsetsResult>",
|
|
21
21
|
"parameters": [],
|
|
22
|
-
"returns": "
|
|
22
|
+
"returns": "Promise<SafeAreaInsetsResult>",
|
|
23
23
|
"tags": [],
|
|
24
24
|
"docs": "",
|
|
25
25
|
"complexTypes": [
|
|
@@ -34,12 +34,12 @@
|
|
|
34
34
|
{
|
|
35
35
|
"name": "eventName",
|
|
36
36
|
"docs": "",
|
|
37
|
-
"type": "
|
|
37
|
+
"type": "'safeAreaPluginsInsetChange'"
|
|
38
38
|
},
|
|
39
39
|
{
|
|
40
40
|
"name": "listener",
|
|
41
41
|
"docs": "",
|
|
42
|
-
"type": "
|
|
42
|
+
"type": "SafeAreaInsetsChangedCallback"
|
|
43
43
|
}
|
|
44
44
|
],
|
|
45
45
|
"returns": "PluginListenerHandle",
|
|
@@ -49,7 +49,7 @@
|
|
|
49
49
|
"PluginListenerHandle",
|
|
50
50
|
"SafeAreaInsetsChangedCallback"
|
|
51
51
|
],
|
|
52
|
-
"slug": "
|
|
52
|
+
"slug": "addlistenersafeareapluginsinsetchange"
|
|
53
53
|
}
|
|
54
54
|
],
|
|
55
55
|
"properties": []
|
|
@@ -122,10 +122,26 @@
|
|
|
122
122
|
"tags": [],
|
|
123
123
|
"docs": "",
|
|
124
124
|
"complexTypes": [],
|
|
125
|
-
"type": "() =>
|
|
125
|
+
"type": "() => Promise<void>"
|
|
126
126
|
}
|
|
127
127
|
]
|
|
128
128
|
}
|
|
129
129
|
],
|
|
130
|
-
"enums": []
|
|
130
|
+
"enums": [],
|
|
131
|
+
"typeAliases": [
|
|
132
|
+
{
|
|
133
|
+
"name": "SafeAreaInsetsChangedCallback",
|
|
134
|
+
"slug": "safeareainsetschangedcallback",
|
|
135
|
+
"docs": "",
|
|
136
|
+
"types": [
|
|
137
|
+
{
|
|
138
|
+
"text": "(result: SafeAreaInsetsResult): void",
|
|
139
|
+
"complexTypes": [
|
|
140
|
+
"SafeAreaInsetsResult"
|
|
141
|
+
]
|
|
142
|
+
}
|
|
143
|
+
]
|
|
144
|
+
}
|
|
145
|
+
],
|
|
146
|
+
"pluginConfigs": []
|
|
131
147
|
}
|