@capacitor/android 9.0.0-alpha.1 → 9.0.0-alpha.3

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.
@@ -65,6 +65,17 @@ public class PluginConfig {
65
65
  return JSONUtils.getInt(config, configKey, defaultValue);
66
66
  }
67
67
 
68
+ /**
69
+ * Get a double value for a plugin in the Capacitor config.
70
+ *
71
+ * @param configKey The key of the value to retrieve
72
+ * @param defaultValue A default value to return if the key does not exist in the config
73
+ * @return The value from the config, if key exists. Default value returned if not
74
+ */
75
+ public double getDouble(String configKey, double defaultValue) {
76
+ return JSONUtils.getDouble(config, configKey, defaultValue);
77
+ }
78
+
68
79
  /**
69
80
  * Get a string array value for a plugin in the Capacitor config.
70
81
  *
@@ -16,6 +16,7 @@ import androidx.core.view.WindowCompat;
16
16
  import androidx.core.view.WindowInsetsCompat;
17
17
  import androidx.core.view.WindowInsetsControllerCompat;
18
18
  import androidx.webkit.WebViewCompat;
19
+ import com.getcapacitor.Logger;
19
20
  import com.getcapacitor.Plugin;
20
21
  import com.getcapacitor.PluginCall;
21
22
  import com.getcapacitor.PluginMethod;
@@ -32,6 +33,7 @@ public class SystemBars extends Plugin {
32
33
  static final String BAR_STATUS_BAR = "StatusBar";
33
34
  static final String BAR_GESTURE_BAR = "NavigationBar";
34
35
 
36
+ // TODO: In Cap 9, add an additional option "full"
35
37
  static final String INSETS_HANDLING_CSS = "css";
36
38
  static final String INSETS_HANDLING_DISABLE = "disable";
37
39
 
@@ -53,7 +55,7 @@ public class SystemBars extends Plugin {
53
55
  capacitorSystemBarsCheckMetaViewport();
54
56
  """;
55
57
 
56
- private boolean insetHandlingEnabled = true;
58
+ private String insetsHandling = INSETS_HANDLING_CSS;
57
59
  private boolean hasViewportCover = false;
58
60
 
59
61
  private String currentStatusBarStyle = STYLE_DEFAULT;
@@ -94,9 +96,15 @@ public class SystemBars extends Plugin {
94
96
  String style = getConfig().getString("style", STYLE_DEFAULT).toUpperCase(Locale.US);
95
97
  boolean hidden = getConfig().getBoolean("hidden", false);
96
98
 
97
- String insetsHandling = getConfig().getString("insetsHandling", "css");
98
- if (insetsHandling.equals(INSETS_HANDLING_DISABLE)) {
99
- insetHandlingEnabled = false;
99
+ String configuredInsetsHandling = getConfig().getString("insetsHandling", INSETS_HANDLING_CSS);
100
+ if (INSETS_HANDLING_CSS.equals(configuredInsetsHandling) || INSETS_HANDLING_DISABLE.equals(configuredInsetsHandling)) {
101
+ insetsHandling = configuredInsetsHandling;
102
+ } else {
103
+ Logger.warn(
104
+ "SystemBars",
105
+ "Unknown insetsHandling value '" + configuredInsetsHandling + "'. Falling back to '" + INSETS_HANDLING_CSS + "'."
106
+ );
107
+ insetsHandling = INSETS_HANDLING_CSS;
100
108
  }
101
109
 
102
110
  initWindowInsetsListener();
@@ -146,13 +154,15 @@ public class SystemBars extends Plugin {
146
154
 
147
155
  @JavascriptInterface
148
156
  public void onDOMReady() {
149
- getActivity().runOnUiThread(() -> {
150
- this.bridge.getWebView().evaluateJavascript(viewportMetaJSFunction, (res) -> {
151
- hasViewportCover = res.equals("true");
157
+ if (INSETS_HANDLING_CSS.equals(insetsHandling)) {
158
+ getActivity().runOnUiThread(() -> {
159
+ this.bridge.getWebView().evaluateJavascript(viewportMetaJSFunction, (res) -> {
160
+ hasViewportCover = res.equals("true");
152
161
 
153
- getBridge().getWebView().requestApplyInsets();
162
+ getBridge().getWebView().requestApplyInsets();
163
+ });
154
164
  });
155
- });
165
+ }
156
166
  }
157
167
 
158
168
  private Insets calcSafeAreaInsets(WindowInsetsCompat insets) {
@@ -164,9 +174,16 @@ public class SystemBars extends Plugin {
164
174
  }
165
175
 
166
176
  private void initSafeAreaCSSVariables() {
167
- if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.VANILLA_ICE_CREAM && insetHandlingEnabled) {
168
- View v = (View) this.getBridge().getWebView().getParent();
169
- WindowInsetsCompat insets = ViewCompat.getRootWindowInsets(v);
177
+ if (INSETS_HANDLING_CSS.equals(insetsHandling)) {
178
+ WindowInsetsCompat insets;
179
+
180
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.VANILLA_ICE_CREAM) {
181
+ View v = (View) this.getBridge().getWebView().getParent();
182
+ insets = ViewCompat.getRootWindowInsets(v);
183
+ } else {
184
+ insets = WindowInsetsCompat.CONSUMED;
185
+ }
186
+
170
187
  if (insets != null) {
171
188
  Insets safeAreaInsets = calcSafeAreaInsets(insets);
172
189
  injectSafeAreaCSS(safeAreaInsets.top, safeAreaInsets.right, safeAreaInsets.bottom, safeAreaInsets.left);
@@ -175,6 +192,10 @@ public class SystemBars extends Plugin {
175
192
  }
176
193
 
177
194
  private void initWindowInsetsListener() {
195
+ if (INSETS_HANDLING_DISABLE.equals(insetsHandling)) {
196
+ return;
197
+ }
198
+
178
199
  ViewCompat.setOnApplyWindowInsetsListener((View) getBridge().getWebView().getParent(), (v, insets) -> {
179
200
  boolean shouldPassthroughInsets = getWebViewMajorVersion() >= WEBVIEW_VERSION_WITH_SAFE_AREA_FIX && hasViewportCover;
180
201
 
@@ -186,10 +207,8 @@ public class SystemBars extends Plugin {
186
207
  // We need to correct for a possible shown IME
187
208
  v.setPadding(0, 0, 0, keyboardVisible ? imeInsets.bottom : 0);
188
209
 
189
- if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.VANILLA_ICE_CREAM && hasViewportCover && insetHandlingEnabled) {
190
- Insets safeAreaInsets = calcSafeAreaInsets(insets);
191
- injectSafeAreaCSS(safeAreaInsets.top, safeAreaInsets.right, safeAreaInsets.bottom, safeAreaInsets.left);
192
- }
210
+ Insets safeAreaInsets = calcSafeAreaInsets(insets);
211
+ injectSafeAreaCSS(safeAreaInsets.top, safeAreaInsets.right, safeAreaInsets.bottom, safeAreaInsets.left);
193
212
 
194
213
  return new WindowInsetsCompat.Builder(insets)
195
214
  .setInsets(
@@ -221,10 +240,8 @@ public class SystemBars extends Plugin {
221
240
  .setInsets(WindowInsetsCompat.Type.systemBars() | WindowInsetsCompat.Type.displayCutout(), Insets.of(0, 0, 0, 0))
222
241
  .build();
223
242
 
224
- if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.VANILLA_ICE_CREAM && hasViewportCover && insetHandlingEnabled) {
225
- Insets safeAreaInsets = calcSafeAreaInsets(newInsets);
226
- injectSafeAreaCSS(safeAreaInsets.top, safeAreaInsets.right, safeAreaInsets.bottom, safeAreaInsets.left);
227
- }
243
+ Insets safeAreaInsets = calcSafeAreaInsets(newInsets);
244
+ injectSafeAreaCSS(safeAreaInsets.top, safeAreaInsets.right, safeAreaInsets.bottom, safeAreaInsets.left);
228
245
 
229
246
  return newInsets;
230
247
  });
@@ -287,19 +304,21 @@ public class SystemBars extends Plugin {
287
304
  WindowInsetsControllerCompat windowInsetsControllerCompat = WindowCompat.getInsetsController(window, window.getDecorView());
288
305
 
289
306
  if (hide) {
290
- if (bar.isEmpty() || bar.equals(BAR_STATUS_BAR)) {
307
+ if (bar.isEmpty()) {
308
+ windowInsetsControllerCompat.hide(WindowInsetsCompat.Type.systemBars());
309
+ } else if (bar.equals(BAR_STATUS_BAR)) {
291
310
  windowInsetsControllerCompat.hide(WindowInsetsCompat.Type.statusBars());
292
- }
293
- if (bar.isEmpty() || bar.equals(BAR_GESTURE_BAR)) {
311
+ } else if (bar.equals(BAR_GESTURE_BAR)) {
294
312
  windowInsetsControllerCompat.hide(WindowInsetsCompat.Type.navigationBars());
295
313
  }
296
314
  return;
297
315
  }
298
316
 
299
- if (bar.isEmpty() || bar.equals(BAR_STATUS_BAR)) {
317
+ if (bar.isEmpty()) {
300
318
  windowInsetsControllerCompat.show(WindowInsetsCompat.Type.systemBars());
301
- }
302
- if (bar.isEmpty() || bar.equals(BAR_GESTURE_BAR)) {
319
+ } else if (bar.equals(BAR_STATUS_BAR)) {
320
+ windowInsetsControllerCompat.show(WindowInsetsCompat.Type.statusBars());
321
+ } else if (bar.equals(BAR_GESTURE_BAR)) {
303
322
  windowInsetsControllerCompat.show(WindowInsetsCompat.Type.navigationBars());
304
323
  }
305
324
  }
@@ -75,6 +75,26 @@ public class JSONUtils {
75
75
  return defaultValue;
76
76
  }
77
77
 
78
+ /**
79
+ * Get a double value from the given JSON object.
80
+ *
81
+ * @param jsonObject A JSON object to search
82
+ * @param key A key to fetch from the JSON object
83
+ * @param defaultValue A default value to return if the key cannot be found
84
+ * @return The value at the given key in the JSON object, or the default value
85
+ */
86
+ public static double getDouble(JSONObject jsonObject, String key, double defaultValue) {
87
+ String k = getDeepestKey(key);
88
+ try {
89
+ JSONObject o = getDeepestObject(jsonObject, key);
90
+ return o.getDouble(k);
91
+ } catch (JSONException ignore) {
92
+ // value was not found
93
+ }
94
+
95
+ return defaultValue;
96
+ }
97
+
78
98
  /**
79
99
  * Get a JSON object value from the given JSON object.
80
100
  *
@@ -70,14 +70,12 @@ class MockCordovaWebViewImpl implements CordovaWebView {
70
70
 
71
71
  @Override
72
72
  public void onNativeToJsMessageAvailable(final NativeToJsMessageQueue queue) {
73
- cordova
74
- .getActivity()
75
- .runOnUiThread(() -> {
76
- String js = queue.popAndEncodeAsJs();
77
- if (js != null) {
78
- webView.evaluateJavascript(js, null);
79
- }
80
- });
73
+ cordova.getActivity().runOnUiThread(() -> {
74
+ String js = queue.popAndEncodeAsJs();
75
+ if (js != null) {
76
+ webView.evaluateJavascript(js, null);
77
+ }
78
+ });
81
79
  }
82
80
  }
83
81
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@capacitor/android",
3
- "version": "9.0.0-alpha.1",
3
+ "version": "9.0.0-alpha.3",
4
4
  "description": "Capacitor: Cross-platform apps with JavaScript and the web",
5
5
  "homepage": "https://capacitorjs.com",
6
6
  "author": "Ionic Team <hi@ionic.io> (https://ionic.io)",
@@ -26,7 +26,7 @@
26
26
  "verify": "./gradlew clean lint build test -b capacitor/build.gradle"
27
27
  },
28
28
  "peerDependencies": {
29
- "@capacitor/core": "^9.0.0-alpha.1"
29
+ "@capacitor/core": "^9.0.0-alpha.3"
30
30
  },
31
31
  "publishConfig": {
32
32
  "access": "public"