@totalpave/cordova-plugin-insets 0.1.5 → 0.1.6

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 ADDED
@@ -0,0 +1,14 @@
1
+
2
+ @totalpave/cordova-plugin-insets
3
+ --------------------------------
4
+
5
+ # Changelog
6
+
7
+ ## 0.1.6 (April 20, 2023)
8
+ - Replaced `insets.getSystemWindowInset*` usages that was deprecated in API 30.
9
+ - Replaced `insets.consumeSystemWindowInsets` usages that was deprecated in API 30.
10
+ - Fix an issue on API 30 and earlier devices where the inset provided on launch may be incorrect.
11
+
12
+ ## 0.1.5 (April 13, 2023)
13
+
14
+ - 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.5",
3
+ "version": "0.1.6",
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",
@@ -33,7 +33,7 @@
33
33
  "@rollup/plugin-commonjs": "24.1.0",
34
34
  "@rollup/plugin-node-resolve": "15.0.2",
35
35
  "@types/cordova": "11.0.0",
36
- "rollup": "3.20.2",
36
+ "rollup": "3.20.6",
37
37
  "rollup-plugin-progress": "1.1.2",
38
38
  "rollup-plugin-typescript2": "0.34.1",
39
39
  "ts-node": "10.9.1",
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.3">
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>
@@ -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, insets) -> {
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 insets.consumeSystemWindowInsets();
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 insets.consumeSystemWindowInsets();
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
- if (this.insets == null) {
68
- WindowInsetsCompat insets = ViewCompat.getRootWindowInsets(this.cordova.getActivity().findViewById(android.R.id.content));
69
- if (insets != null) {
70
- JSONObject result = new JSONObject();
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
- if (this.insets != null) {
86
- PluginResult presult = new PluginResult(Status.OK, this.insets);
87
- presult.setKeepCallback(true);
88
- listener.sendPluginResult(presult);
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;