@capawesome/capacitor-android-edge-to-edge-support 7.1.1 → 7.2.0

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/README.md CHANGED
@@ -13,6 +13,22 @@ npm install @capawesome/capacitor-android-edge-to-edge-support
13
13
  npx cap sync
14
14
  ```
15
15
 
16
+ ### Android
17
+
18
+ If you are using the [Capacitor Keyboard](https://capacitorjs.com/docs/apis/keyboard) plugin, make sure to set the `resizeOnFullScreen` property to `false` (default) in your Capacitor Configuration file:
19
+
20
+ ```json
21
+ {
22
+ "plugins": {
23
+ "Keyboard": {
24
+ "resizeOnFullScreen": false
25
+ }
26
+ }
27
+ }
28
+ ```
29
+
30
+ Otherwise, the web view will be resized to fit the screen, which may cause issues with this plugin, see [this comment](https://github.com/capawesome-team/capacitor-plugins/issues/490#issuecomment-2826435796).
31
+
16
32
  ## Configuration
17
33
 
18
34
  <docgen-config>
@@ -74,6 +90,9 @@ const setBackgroundColor = async () => {
74
90
 
75
91
  <docgen-index>
76
92
 
93
+ * [`enable()`](#enable)
94
+ * [`disable()`](#disable)
95
+ * [`getInsets()`](#getinsets)
77
96
  * [`setBackgroundColor(...)`](#setbackgroundcolor)
78
97
  * [Interfaces](#interfaces)
79
98
 
@@ -82,6 +101,53 @@ const setBackgroundColor = async () => {
82
101
  <docgen-api>
83
102
  <!--Update the source file JSDoc comments and rerun docgen to update the docs below-->
84
103
 
104
+ ### enable()
105
+
106
+ ```typescript
107
+ enable() => Promise<void>
108
+ ```
109
+
110
+ Enable the edge-to-edge mode.
111
+
112
+ Only available on Android.
113
+
114
+ **Since:** 7.2.0
115
+
116
+ --------------------
117
+
118
+
119
+ ### disable()
120
+
121
+ ```typescript
122
+ disable() => Promise<void>
123
+ ```
124
+
125
+ Disable the edge-to-edge mode.
126
+
127
+ Only available on Android.
128
+
129
+ **Since:** 7.2.0
130
+
131
+ --------------------
132
+
133
+
134
+ ### getInsets()
135
+
136
+ ```typescript
137
+ getInsets() => Promise<GetInsetsResult>
138
+ ```
139
+
140
+ Return the insets that are currently applied to the webview.
141
+
142
+ Only available on Android.
143
+
144
+ **Returns:** <code>Promise&lt;<a href="#getinsetsresult">GetInsetsResult</a>&gt;</code>
145
+
146
+ **Since:** 7.2.0
147
+
148
+ --------------------
149
+
150
+
85
151
  ### setBackgroundColor(...)
86
152
 
87
153
  ```typescript
@@ -104,6 +170,16 @@ Only available on Android.
104
170
  ### Interfaces
105
171
 
106
172
 
173
+ #### GetInsetsResult
174
+
175
+ | Prop | Type | Description | Since |
176
+ | ------------ | ------------------- | ---------------------------------------------------------------------------- | ----- |
177
+ | **`bottom`** | <code>number</code> | The bottom inset that was applied to the webview. Only available on Android. | 7.2.0 |
178
+ | **`left`** | <code>number</code> | The left inset that was applied to the webview. Only available on Android. | 7.2.0 |
179
+ | **`right`** | <code>number</code> | The right inset that was applied to the webview. Only available on Android. | 7.2.0 |
180
+ | **`top`** | <code>number</code> | The top inset that was applied to the webview. Only available on Android. | 7.2.0 |
181
+
182
+
107
183
  #### SetBackgroundColorOptions
108
184
 
109
185
  | Prop | Type | Description | Since |
@@ -8,6 +8,7 @@ import androidx.annotation.NonNull;
8
8
  import androidx.core.graphics.Insets;
9
9
  import androidx.core.view.ViewCompat;
10
10
  import androidx.core.view.WindowInsetsCompat;
11
+ import com.getcapacitor.Logger;
11
12
 
12
13
  public class EdgeToEdge {
13
14
 
@@ -21,30 +22,48 @@ public class EdgeToEdge {
21
22
  this.config = config;
22
23
  this.plugin = plugin;
23
24
  // Apply insets to disable the edge-to-edge feature
25
+ setBackgroundColor(config.getBackgroundColor());
24
26
  applyInsets();
25
27
  }
26
28
 
27
- public void setBackgroundColor(String color) {
29
+ public void enable() {
30
+ applyInsets();
31
+ }
32
+
33
+ public void disable() {
34
+ removeInsets();
35
+ }
36
+
37
+ public ViewGroup.MarginLayoutParams getInsets() {
28
38
  View view = plugin.getBridge().getWebView();
29
- if (view == null) {
30
- return;
31
- }
32
- // Get parent view
33
- ViewGroup parent = (ViewGroup) view.getParent();
34
- // Set background color to black
35
- parent.setBackgroundColor(Color.parseColor(color));
39
+ return (ViewGroup.MarginLayoutParams) view.getLayoutParams();
40
+ }
41
+
42
+ public void setBackgroundColor(String color) {
43
+ setBackgroundColor(Color.parseColor(color));
36
44
  }
37
45
 
38
46
  private void applyInsets() {
39
47
  View view = plugin.getBridge().getWebView();
40
- if (view == null) {
41
- return;
42
- }
43
48
  // Get parent view
44
49
  ViewGroup parent = (ViewGroup) view.getParent();
45
- // Set background color to black
46
- parent.setBackgroundColor(this.config.getBackgroundColor());
47
- // Apply insets to disable the edge-to-edge feature
50
+ // Set insets
51
+ WindowInsetsCompat currentInsets = ViewCompat.getRootWindowInsets(view);
52
+ if (currentInsets != null) {
53
+ Insets systemBarsInsets = currentInsets.getInsets(WindowInsetsCompat.Type.systemBars());
54
+ Insets imeInsets = currentInsets.getInsets(WindowInsetsCompat.Type.ime());
55
+ boolean keyboardVisible = currentInsets.isVisible(WindowInsetsCompat.Type.ime());
56
+
57
+ ViewGroup.MarginLayoutParams mlp = (ViewGroup.MarginLayoutParams) view.getLayoutParams();
58
+
59
+ mlp.bottomMargin = keyboardVisible ? imeInsets.bottom : systemBarsInsets.bottom;
60
+ mlp.topMargin = systemBarsInsets.top;
61
+ mlp.leftMargin = systemBarsInsets.left;
62
+ mlp.rightMargin = systemBarsInsets.right;
63
+
64
+ view.setLayoutParams(mlp);
65
+ }
66
+ // Set listener
48
67
  ViewCompat.setOnApplyWindowInsetsListener(view, (v, windowInsets) -> {
49
68
  // Retrieve system bars insets (for status/navigation bars)
50
69
  Insets systemBarsInsets = windowInsets.getInsets(WindowInsetsCompat.Type.systemBars());
@@ -67,4 +86,27 @@ public class EdgeToEdge {
67
86
  return WindowInsetsCompat.CONSUMED;
68
87
  });
69
88
  }
89
+
90
+ private void removeInsets() {
91
+ View view = plugin.getBridge().getWebView();
92
+ // Get parent view
93
+ ViewGroup parent = (ViewGroup) view.getParent();
94
+ // Reset insets
95
+ ViewGroup.MarginLayoutParams mlp = (ViewGroup.MarginLayoutParams) view.getLayoutParams();
96
+ mlp.topMargin = 0;
97
+ mlp.leftMargin = 0;
98
+ mlp.rightMargin = 0;
99
+ mlp.bottomMargin = 0;
100
+ view.setLayoutParams(mlp);
101
+ // Reset listener
102
+ ViewCompat.setOnApplyWindowInsetsListener(view, null);
103
+ }
104
+
105
+ private void setBackgroundColor(int color) {
106
+ View view = plugin.getBridge().getWebView();
107
+ // Get parent view
108
+ ViewGroup parent = (ViewGroup) view.getParent();
109
+ // Set background color
110
+ parent.setBackgroundColor(color);
111
+ }
70
112
  }
@@ -1,7 +1,9 @@
1
1
  package io.capawesome.capacitorjs.plugins.androidedgetoedgesupport;
2
2
 
3
3
  import android.graphics.Color;
4
+ import android.view.ViewGroup;
4
5
  import androidx.annotation.Nullable;
6
+ import com.getcapacitor.JSObject;
5
7
  import com.getcapacitor.Plugin;
6
8
  import com.getcapacitor.PluginCall;
7
9
  import com.getcapacitor.PluginMethod;
@@ -13,7 +15,6 @@ public class EdgeToEdgePlugin extends Plugin {
13
15
  private static final String ERROR_COLOR_MISSING = "color must be provided.";
14
16
  private static final String TAG = "EdgeToEdge";
15
17
 
16
- @Nullable
17
18
  private EdgeToEdge implementation;
18
19
 
19
20
  @Override
@@ -22,6 +23,35 @@ public class EdgeToEdgePlugin extends Plugin {
22
23
  implementation = new EdgeToEdge(this, config);
23
24
  }
24
25
 
26
+ @PluginMethod
27
+ public void enable(PluginCall call) {
28
+ getActivity()
29
+ .runOnUiThread(() -> {
30
+ implementation.enable();
31
+ call.resolve();
32
+ });
33
+ }
34
+
35
+ @PluginMethod
36
+ public void disable(PluginCall call) {
37
+ getActivity()
38
+ .runOnUiThread(() -> {
39
+ implementation.disable();
40
+ call.resolve();
41
+ });
42
+ }
43
+
44
+ @PluginMethod
45
+ public void getInsets(PluginCall call) {
46
+ ViewGroup.MarginLayoutParams insets = implementation.getInsets();
47
+ JSObject result = new JSObject();
48
+ result.put("bottom", insets.bottomMargin);
49
+ result.put("left", insets.leftMargin);
50
+ result.put("right", insets.rightMargin);
51
+ result.put("top", insets.topMargin);
52
+ call.resolve(result);
53
+ }
54
+
25
55
  @PluginMethod
26
56
  public void setBackgroundColor(PluginCall call) {
27
57
  String color = call.getString("color");
package/dist/docs.json CHANGED
@@ -5,6 +5,53 @@
5
5
  "docs": "",
6
6
  "tags": [],
7
7
  "methods": [
8
+ {
9
+ "name": "enable",
10
+ "signature": "() => Promise<void>",
11
+ "parameters": [],
12
+ "returns": "Promise<void>",
13
+ "tags": [
14
+ {
15
+ "name": "since",
16
+ "text": "7.2.0"
17
+ }
18
+ ],
19
+ "docs": "Enable the edge-to-edge mode.\n\nOnly available on Android.",
20
+ "complexTypes": [],
21
+ "slug": "enable"
22
+ },
23
+ {
24
+ "name": "disable",
25
+ "signature": "() => Promise<void>",
26
+ "parameters": [],
27
+ "returns": "Promise<void>",
28
+ "tags": [
29
+ {
30
+ "name": "since",
31
+ "text": "7.2.0"
32
+ }
33
+ ],
34
+ "docs": "Disable the edge-to-edge mode.\n\nOnly available on Android.",
35
+ "complexTypes": [],
36
+ "slug": "disable"
37
+ },
38
+ {
39
+ "name": "getInsets",
40
+ "signature": "() => Promise<GetInsetsResult>",
41
+ "parameters": [],
42
+ "returns": "Promise<GetInsetsResult>",
43
+ "tags": [
44
+ {
45
+ "name": "since",
46
+ "text": "7.2.0"
47
+ }
48
+ ],
49
+ "docs": "Return the insets that are currently applied to the webview.\n\nOnly available on Android.",
50
+ "complexTypes": [
51
+ "GetInsetsResult"
52
+ ],
53
+ "slug": "getinsets"
54
+ },
8
55
  {
9
56
  "name": "setBackgroundColor",
10
57
  "signature": "(options: SetBackgroundColorOptions) => Promise<void>",
@@ -32,6 +79,68 @@
32
79
  "properties": []
33
80
  },
34
81
  "interfaces": [
82
+ {
83
+ "name": "GetInsetsResult",
84
+ "slug": "getinsetsresult",
85
+ "docs": "",
86
+ "tags": [
87
+ {
88
+ "text": "7.2.0",
89
+ "name": "since"
90
+ }
91
+ ],
92
+ "methods": [],
93
+ "properties": [
94
+ {
95
+ "name": "bottom",
96
+ "tags": [
97
+ {
98
+ "text": "7.2.0",
99
+ "name": "since"
100
+ }
101
+ ],
102
+ "docs": "The bottom inset that was applied to the webview.\n\nOnly available on Android.",
103
+ "complexTypes": [],
104
+ "type": "number"
105
+ },
106
+ {
107
+ "name": "left",
108
+ "tags": [
109
+ {
110
+ "text": "7.2.0",
111
+ "name": "since"
112
+ }
113
+ ],
114
+ "docs": "The left inset that was applied to the webview.\n\nOnly available on Android.",
115
+ "complexTypes": [],
116
+ "type": "number"
117
+ },
118
+ {
119
+ "name": "right",
120
+ "tags": [
121
+ {
122
+ "text": "7.2.0",
123
+ "name": "since"
124
+ }
125
+ ],
126
+ "docs": "The right inset that was applied to the webview.\n\nOnly available on Android.",
127
+ "complexTypes": [],
128
+ "type": "number"
129
+ },
130
+ {
131
+ "name": "top",
132
+ "tags": [
133
+ {
134
+ "text": "7.2.0",
135
+ "name": "since"
136
+ }
137
+ ],
138
+ "docs": "The top inset that was applied to the webview.\n\nOnly available on Android.",
139
+ "complexTypes": [],
140
+ "type": "number"
141
+ }
142
+ ]
143
+ },
35
144
  {
36
145
  "name": "SetBackgroundColorOptions",
37
146
  "slug": "setbackgroundcoloroptions",
@@ -12,6 +12,30 @@ declare module '@capacitor/cli' {
12
12
  }
13
13
  }
14
14
  export interface EdgeToEdgePlugin {
15
+ /**
16
+ * Enable the edge-to-edge mode.
17
+ *
18
+ * Only available on Android.
19
+ *
20
+ * @since 7.2.0
21
+ */
22
+ enable(): Promise<void>;
23
+ /**
24
+ * Disable the edge-to-edge mode.
25
+ *
26
+ * Only available on Android.
27
+ *
28
+ * @since 7.2.0
29
+ */
30
+ disable(): Promise<void>;
31
+ /**
32
+ * Return the insets that are currently applied to the webview.
33
+ *
34
+ * Only available on Android.
35
+ *
36
+ * @since 7.2.0
37
+ */
38
+ getInsets(): Promise<GetInsetsResult>;
15
39
  /**
16
40
  * Set the background color of the status bar and navigation bar.
17
41
  *
@@ -21,6 +45,43 @@ export interface EdgeToEdgePlugin {
21
45
  */
22
46
  setBackgroundColor(options: SetBackgroundColorOptions): Promise<void>;
23
47
  }
48
+ /**
49
+ * @since 7.2.0
50
+ */
51
+ export interface GetInsetsResult {
52
+ /**
53
+ * The bottom inset that was applied to the webview.
54
+ *
55
+ * Only available on Android.
56
+ *
57
+ * @since 7.2.0
58
+ */
59
+ bottom: number;
60
+ /**
61
+ * The left inset that was applied to the webview.
62
+ *
63
+ * Only available on Android.
64
+ *
65
+ * @since 7.2.0
66
+ */
67
+ left: number;
68
+ /**
69
+ * The right inset that was applied to the webview.
70
+ *
71
+ * Only available on Android.
72
+ *
73
+ * @since 7.2.0
74
+ */
75
+ right: number;
76
+ /**
77
+ * The top inset that was applied to the webview.
78
+ *
79
+ * Only available on Android.
80
+ *
81
+ * @since 7.2.0
82
+ */
83
+ top: number;
84
+ }
24
85
  /**
25
86
  * @since 7.0.0
26
87
  */
@@ -1 +1 @@
1
- {"version":3,"file":"definitions.js","sourceRoot":"","sources":["../../src/definitions.ts"],"names":[],"mappings":"AAAA,wCAAwC","sourcesContent":["/// <reference types=\"@capacitor/cli\" />\n\ndeclare module '@capacitor/cli' {\n export interface PluginsConfig {\n EdgeToEdge?: {\n /**\n * The hexadecimal color to set as the background color of the status bar and navigation bar.\n *\n * @since 7.1.0\n * @example \"#ffffff\"\n */\n backgroundColor?: string;\n };\n }\n}\n\nexport interface EdgeToEdgePlugin {\n /**\n * Set the background color of the status bar and navigation bar.\n *\n * Only available on Android.\n *\n * @since 7.0.0\n */\n setBackgroundColor(options: SetBackgroundColorOptions): Promise<void>;\n}\n\n/**\n * @since 7.0.0\n */\nexport interface SetBackgroundColorOptions {\n /**\n * The hexadecimal color to set as the background color of the status bar and navigation bar.\n *\n * @since 7.0.0\n * @example \"#ffffff\"\n * @example \"#000000\"\n */\n color: string;\n}\n"]}
1
+ {"version":3,"file":"definitions.js","sourceRoot":"","sources":["../../src/definitions.ts"],"names":[],"mappings":"AAAA,wCAAwC","sourcesContent":["/// <reference types=\"@capacitor/cli\" />\n\ndeclare module '@capacitor/cli' {\n export interface PluginsConfig {\n EdgeToEdge?: {\n /**\n * The hexadecimal color to set as the background color of the status bar and navigation bar.\n *\n * @since 7.1.0\n * @example \"#ffffff\"\n */\n backgroundColor?: string;\n };\n }\n}\n\nexport interface EdgeToEdgePlugin {\n /**\n * Enable the edge-to-edge mode.\n *\n * Only available on Android.\n *\n * @since 7.2.0\n */\n enable(): Promise<void>;\n /**\n * Disable the edge-to-edge mode.\n *\n * Only available on Android.\n *\n * @since 7.2.0\n */\n disable(): Promise<void>;\n /**\n * Return the insets that are currently applied to the webview.\n *\n * Only available on Android.\n *\n * @since 7.2.0\n */\n getInsets(): Promise<GetInsetsResult>;\n /**\n * Set the background color of the status bar and navigation bar.\n *\n * Only available on Android.\n *\n * @since 7.0.0\n */\n setBackgroundColor(options: SetBackgroundColorOptions): Promise<void>;\n}\n\n/**\n * @since 7.2.0\n */\nexport interface GetInsetsResult {\n /**\n * The bottom inset that was applied to the webview.\n *\n * Only available on Android.\n *\n * @since 7.2.0\n */\n bottom: number;\n /**\n * The left inset that was applied to the webview.\n *\n * Only available on Android.\n *\n * @since 7.2.0\n */\n left: number;\n /**\n * The right inset that was applied to the webview.\n *\n * Only available on Android.\n *\n * @since 7.2.0\n */\n right: number;\n /**\n * The top inset that was applied to the webview.\n *\n * Only available on Android.\n *\n * @since 7.2.0\n */\n top: number;\n}\n\n/**\n * @since 7.0.0\n */\nexport interface SetBackgroundColorOptions {\n /**\n * The hexadecimal color to set as the background color of the status bar and navigation bar.\n *\n * @since 7.0.0\n * @example \"#ffffff\"\n * @example \"#000000\"\n */\n color: string;\n}\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@capawesome/capacitor-android-edge-to-edge-support",
3
- "version": "7.1.1",
3
+ "version": "7.2.0",
4
4
  "description": "Capacitor plugin to support edge-to-edge display on Android.",
5
5
  "main": "dist/plugin.cjs.js",
6
6
  "module": "dist/esm/index.js",