@totalpave/cordova-plugin-insets 0.1.5 → 0.1.7
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/CHANGELOG.md +17 -0
- package/package.json +11 -11
- package/plugin.xml +2 -2
- package/src/android/com/totalpave/cordova/insets/Insets.java +21 -29
- package/www/insets.js.map +1 -1
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
|
|
2
|
+
@totalpave/cordova-plugin-insets
|
|
3
|
+
--------------------------------
|
|
4
|
+
|
|
5
|
+
# Changelog
|
|
6
|
+
|
|
7
|
+
## 0.1.7 (July 6, 2023)
|
|
8
|
+
- Fixed clobbers namespace to merge instead, since this particular plugin targets a shared namespace.
|
|
9
|
+
|
|
10
|
+
## 0.1.6 (April 20, 2023)
|
|
11
|
+
- Replaced `insets.getSystemWindowInset*` usages that was deprecated in API 30.
|
|
12
|
+
- Replaced `insets.consumeSystemWindowInsets` usages that was deprecated in API 30.
|
|
13
|
+
- Fix an issue on API 30 and earlier devices where the inset provided on launch may be incorrect.
|
|
14
|
+
|
|
15
|
+
## 0.1.5 (April 13, 2023)
|
|
16
|
+
|
|
17
|
+
- Initial Release to NPM
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@totalpave/cordova-plugin-insets",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.7",
|
|
4
4
|
"description": "Cordova Android Plugin to receive native information regarding the unsafe area insets.",
|
|
5
5
|
"main": "www/insets.js",
|
|
6
6
|
"types": "www/api.d.ts",
|
|
@@ -25,19 +25,19 @@
|
|
|
25
25
|
},
|
|
26
26
|
"homepage": "https://github.com/totalpaveinc/cordova-plugin-insets#readme",
|
|
27
27
|
"devDependencies": {
|
|
28
|
-
"@babel/core": "7.
|
|
29
|
-
"@babel/preset-env": "7.
|
|
30
|
-
"@babel/preset-typescript": "7.
|
|
31
|
-
"@babel/register": "7.
|
|
28
|
+
"@babel/core": "7.22.8",
|
|
29
|
+
"@babel/preset-env": "7.22.7",
|
|
30
|
+
"@babel/preset-typescript": "7.22.5",
|
|
31
|
+
"@babel/register": "7.22.5",
|
|
32
32
|
"@rollup/plugin-babel": "6.0.3",
|
|
33
|
-
"@rollup/plugin-commonjs": "
|
|
34
|
-
"@rollup/plugin-node-resolve": "15.0
|
|
33
|
+
"@rollup/plugin-commonjs": "25.0.2",
|
|
34
|
+
"@rollup/plugin-node-resolve": "15.1.0",
|
|
35
35
|
"@types/cordova": "11.0.0",
|
|
36
|
-
"rollup": "3.
|
|
36
|
+
"rollup": "3.26.2",
|
|
37
37
|
"rollup-plugin-progress": "1.1.2",
|
|
38
|
-
"rollup-plugin-typescript2": "0.
|
|
38
|
+
"rollup-plugin-typescript2": "0.35.0",
|
|
39
39
|
"ts-node": "10.9.1",
|
|
40
|
-
"typescript": "5.
|
|
40
|
+
"typescript": "5.1.6"
|
|
41
41
|
},
|
|
42
42
|
"engines": {
|
|
43
43
|
"cordovaDependencies": {
|
|
@@ -47,6 +47,6 @@
|
|
|
47
47
|
}
|
|
48
48
|
},
|
|
49
49
|
"dependencies": {
|
|
50
|
-
"tslib": "2.
|
|
50
|
+
"tslib": "2.6.0"
|
|
51
51
|
}
|
|
52
52
|
}
|
package/plugin.xml
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
<?xml version="1.0" encoding="UTF-8"?>
|
|
2
|
-
<plugin xmlns="http://apache.org/cordova/ns/plugins/1.0" id="@totalpave/cordova-plugin-insets" version="0.1.
|
|
2
|
+
<plugin xmlns="http://apache.org/cordova/ns/plugins/1.0" id="@totalpave/cordova-plugin-insets" version="0.1.6">
|
|
3
3
|
<name>cordova-plugin-insets</name>
|
|
4
4
|
<description>Cordova Android Plugin to receive native information regarding the unsafe area insets</description>
|
|
5
5
|
<author>Total Pave Inc.</author>
|
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
<repo>https://github.com/totalpaveinc/cordova-plugin-unsafe-insets</repo>
|
|
9
9
|
|
|
10
10
|
<js-module src="www/insets.js" name="Insets">
|
|
11
|
-
<
|
|
11
|
+
<merges target="totalpave" />
|
|
12
12
|
</js-module>
|
|
13
13
|
|
|
14
14
|
<platform name="android">
|
|
@@ -36,18 +36,22 @@ public class Insets extends CordovaPlugin {
|
|
|
36
36
|
@Override
|
|
37
37
|
protected void pluginInitialize() {
|
|
38
38
|
ViewCompat.setOnApplyWindowInsetsListener(
|
|
39
|
-
this.cordova.getActivity().findViewById(android.R.id.content), (v,
|
|
39
|
+
this.cordova.getActivity().findViewById(android.R.id.content), (v, insetProvider) -> {
|
|
40
40
|
JSONObject result = new JSONObject();
|
|
41
|
+
|
|
41
42
|
try {
|
|
42
43
|
float density = this.cordova.getActivity().getResources().getDisplayMetrics().density;
|
|
43
|
-
result.put("top", insets.getSystemWindowInsetTop() / density);
|
|
44
|
-
result.put("right", insets.getSystemWindowInsetRight() / density);
|
|
45
|
-
result.put("bottom", insets.getSystemWindowInsetBottom() / density);
|
|
46
|
-
result.put("left", insets.getSystemWindowInsetLeft() / density);
|
|
47
44
|
|
|
45
|
+
// Ideally, we'd import this, but it shares the same name as our plugin
|
|
46
|
+
androidx.core.graphics.Insets insets = insetProvider.getInsets(WindowInsetsCompat.Type.systemBars());
|
|
47
|
+
|
|
48
|
+
result.put("top", insets.top / density);
|
|
49
|
+
result.put("right", insets.right / density);
|
|
50
|
+
result.put("bottom", insets.bottom / density);
|
|
51
|
+
result.put("left", insets.left / density);
|
|
48
52
|
} catch (JSONException e) {
|
|
49
53
|
e.printStackTrace();
|
|
50
|
-
return
|
|
54
|
+
return insetProvider.CONSUMED; // Stop dispatching to child views
|
|
51
55
|
}
|
|
52
56
|
this.insets = result;
|
|
53
57
|
if (listener != null) {
|
|
@@ -55,7 +59,7 @@ public class Insets extends CordovaPlugin {
|
|
|
55
59
|
presult.setKeepCallback(true);
|
|
56
60
|
listener.sendPluginResult(presult);
|
|
57
61
|
}
|
|
58
|
-
return
|
|
62
|
+
return insetProvider.CONSUMED; // Stop dispatching to child views
|
|
59
63
|
}
|
|
60
64
|
);
|
|
61
65
|
}
|
|
@@ -64,29 +68,17 @@ public class Insets extends CordovaPlugin {
|
|
|
64
68
|
public boolean execute(String action, JSONArray args, CallbackContext callback) throws JSONException, NumberFormatException {
|
|
65
69
|
if (action.equals("setListener")) {
|
|
66
70
|
listener = callback;
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
try {
|
|
72
|
-
float density = this.cordova.getActivity().getResources().getDisplayMetrics().density;
|
|
73
|
-
result.put("top", insets.getSystemWindowInsetTop() / density);
|
|
74
|
-
result.put("right", insets.getSystemWindowInsetRight() / density);
|
|
75
|
-
result.put("bottom", insets.getSystemWindowInsetBottom() / density);
|
|
76
|
-
result.put("left", insets.getSystemWindowInsetLeft() / density);
|
|
77
|
-
this.insets = result;
|
|
78
|
-
} catch (JSONException e) {
|
|
79
|
-
e.printStackTrace();
|
|
80
|
-
listener.error(e.getMessage());
|
|
81
|
-
return true;
|
|
82
|
-
}
|
|
71
|
+
cordova.getActivity().runOnUiThread(() -> {
|
|
72
|
+
if (this.insets == null) {
|
|
73
|
+
// Trigger a inset dispatch (will eventually jump to the ApplyWindowInsetsListener above)
|
|
74
|
+
ViewCompat.requestApplyInsets(cordova.getActivity().findViewById(android.R.id.content));
|
|
83
75
|
}
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
}
|
|
76
|
+
else {
|
|
77
|
+
PluginResult presult = new PluginResult(Status.OK, this.insets);
|
|
78
|
+
presult.setKeepCallback(true);
|
|
79
|
+
listener.sendPluginResult(presult);
|
|
80
|
+
}
|
|
81
|
+
});
|
|
90
82
|
return true;
|
|
91
83
|
}
|
|
92
84
|
return false;
|
package/www/insets.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"insets.js","sources":["../src/www/Insets.ts"],"sourcesContent":["/*\n Copyright 2022 Total Pave Inc.\n\n Licensed under the Apache License, Version 2.0 (the \"License\");\n you may not use this file except in compliance with the License.\n You may obtain a copy of the License at\n\n http://www.apache.org/licenses/LICENSE-2.0\n\n Unless required by applicable law or agreed to in writing, software\n distributed under the License is distributed on an \"AS IS\" BASIS,\n WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n See the License for the specific language governing permissions and\n limitations under the License.\n*/\n\nexport const SERVICE_NAME: string = \"Insets\";\n\nexport interface IInsets {\n top: number;\n right: number;\n bottom: number;\n left: number;\n}\n\nexport type IInsetCallbackFunc = (inset: IInsets) => void;\n\nexport class Insets {\n private static initPromise: Promise<void>;\n private static listeners: Array<Function> = [];\n private static insets: IInsets = {\n top: 0,\n right: 0,\n bottom: 0,\n left: 0\n };\n\n /**\n * Initializes javascript side of the plugin.\n * \n * This function is called automatically on deviceready.\n * @internal\n */\n public static __init(): Promise<void> {\n if (this.initPromise) {\n return this.initPromise;\n }\n this.initPromise = new Promise<void>((resolve, reject) => {\n // Setup promise resolving mechanism.\n // We don't use the cordova callback functions as they will be called multiple times over the lifespan of an app.\n let func = () => {\n resolve();\n Insets.removeListener(func);\n }\n Insets.addListener(func);\n\n // Setup cordova callback.\n cordova.exec(\n (insets: IInsets) => {\n Insets.insets = insets;\n for (let i = 0, listeners = Insets.listeners.slice(), length = listeners.length; i < length; ++i) {\n listeners[i](insets);\n }\n },\n reject,\n SERVICE_NAME,\n \"setListener\",\n []\n );\n });\n }\n\n public static addListener(callback: IInsetCallbackFunc) {\n this.listeners.push(callback);\n }\n\n public static removeListener(callback: IInsetCallbackFunc) {\n let index = this.listeners.indexOf(callback);\n if (index === -1) {\n return;\n }\n this.listeners.splice(index, 1);\n }\n\n /**\n * @returns Last emitted insets.\n */ \n public static getInsets(): IInsets {\n return Insets.insets;\n }\n};\n\ndocument.addEventListener('deviceready', function() {\n Insets.__init();\n});\n"],"names":[],"mappings":";;AAAA;;;;;;;;;;;;;;AAcE;AAEK,MAAM,YAAY,GAAW,QAAQ,CAAC;
|
|
1
|
+
{"version":3,"file":"insets.js","sources":["../src/www/Insets.ts"],"sourcesContent":["/*\n Copyright 2022 Total Pave Inc.\n\n Licensed under the Apache License, Version 2.0 (the \"License\");\n you may not use this file except in compliance with the License.\n You may obtain a copy of the License at\n\n http://www.apache.org/licenses/LICENSE-2.0\n\n Unless required by applicable law or agreed to in writing, software\n distributed under the License is distributed on an \"AS IS\" BASIS,\n WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n See the License for the specific language governing permissions and\n limitations under the License.\n*/\n\nexport const SERVICE_NAME: string = \"Insets\";\n\nexport interface IInsets {\n top: number;\n right: number;\n bottom: number;\n left: number;\n}\n\nexport type IInsetCallbackFunc = (inset: IInsets) => void;\n\nexport class Insets {\n private static initPromise: Promise<void>;\n private static listeners: Array<Function> = [];\n private static insets: IInsets = {\n top: 0,\n right: 0,\n bottom: 0,\n left: 0\n };\n\n /**\n * Initializes javascript side of the plugin.\n * \n * This function is called automatically on deviceready.\n * @internal\n */\n public static __init(): Promise<void> {\n if (this.initPromise) {\n return this.initPromise;\n }\n this.initPromise = new Promise<void>((resolve, reject) => {\n // Setup promise resolving mechanism.\n // We don't use the cordova callback functions as they will be called multiple times over the lifespan of an app.\n let func = () => {\n resolve();\n Insets.removeListener(func);\n }\n Insets.addListener(func);\n\n // Setup cordova callback.\n cordova.exec(\n (insets: IInsets) => {\n Insets.insets = insets;\n for (let i = 0, listeners = Insets.listeners.slice(), length = listeners.length; i < length; ++i) {\n listeners[i](insets);\n }\n },\n reject,\n SERVICE_NAME,\n \"setListener\",\n []\n );\n });\n }\n\n public static addListener(callback: IInsetCallbackFunc) {\n this.listeners.push(callback);\n }\n\n public static removeListener(callback: IInsetCallbackFunc) {\n let index = this.listeners.indexOf(callback);\n if (index === -1) {\n return;\n }\n this.listeners.splice(index, 1);\n }\n\n /**\n * @returns Last emitted insets.\n */ \n public static getInsets(): IIn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