Skip to content

Commit 350991c

Browse files
edge-to-edge fixes
This seems a mess at the moment so let's just inline the plugin workarounds we need. Should fix bottom bar issues on Android.
1 parent 86ca7f4 commit 350991c

File tree

14 files changed

+225
-183
lines changed

14 files changed

+225
-183
lines changed

android/app/capacitor.build.gradle

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ android {
1010
apply from: "../capacitor-cordova-android-plugins/cordova.variables.gradle"
1111
dependencies {
1212
implementation project(':capacitor-community-bluetooth-le')
13-
implementation project(':capacitor-community-safe-area')
1413
implementation project(':capacitor-app')
1514
implementation project(':capacitor-filesystem')
1615
implementation project(':microbit-capacitor-community-nordic-dfu')

android/app/src/main/java/org/microbit/createai/MainActivity.java

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
package org.microbit.createai;
22

3+
import android.webkit.WebView;
4+
35
import androidx.activity.EdgeToEdge;
6+
import androidx.core.graphics.Insets;
7+
import androidx.core.view.ViewCompat;
8+
import androidx.core.view.WindowInsetsCompat;
9+
import androidx.core.view.WindowInsetsControllerCompat;
410

511
import com.getcapacitor.BridgeActivity;
612

@@ -10,6 +16,43 @@ public class MainActivity extends BridgeActivity {
1016
public void onStart() {
1117
super.onStart();
1218
EdgeToEdge.enable(this);
19+
20+
// Set dark icons on status bar (for light content showing through transparent bar)
21+
WindowInsetsControllerCompat controller = ViewCompat.getWindowInsetsController(getWindow().getDecorView());
22+
if (controller != null) {
23+
controller.setAppearanceLightStatusBars(true);
24+
}
25+
26+
// Inject CSS custom properties for safe area insets.
27+
// This works around WebView bugs in Chromium < 136 where env(safe-area-inset-*)
28+
// returns 0px. CSS can use: var(--safe-area-inset-top, env(safe-area-inset-top))
29+
// See: https://github.com/ionic-team/capacitor/issues/7951
30+
ViewCompat.setOnApplyWindowInsetsListener(getBridge().getWebView(), (v, windowInsets) -> {
31+
Insets insets = windowInsets.getInsets(
32+
WindowInsetsCompat.Type.systemBars() |
33+
WindowInsetsCompat.Type.displayCutout() |
34+
WindowInsetsCompat.Type.ime()
35+
);
36+
37+
float density = getApplicationContext().getResources().getDisplayMetrics().density;
38+
int top = Math.round(insets.top / density);
39+
int right = Math.round(insets.right / density);
40+
int bottom = Math.round(insets.bottom / density);
41+
int left = Math.round(insets.left / density);
42+
43+
WebView webView = getBridge().getWebView();
44+
runOnUiThread(() -> {
45+
webView.evaluateJavascript(
46+
"document.documentElement.style.setProperty('--safe-area-inset-top', '" + top + "px');" +
47+
"document.documentElement.style.setProperty('--safe-area-inset-right', '" + right + "px');" +
48+
"document.documentElement.style.setProperty('--safe-area-inset-bottom', '" + bottom + "px');" +
49+
"document.documentElement.style.setProperty('--safe-area-inset-left', '" + left + "px');",
50+
null
51+
);
52+
});
53+
54+
return WindowInsetsCompat.CONSUMED;
55+
});
1356
}
1457

1558
}

android/capacitor.settings.gradle

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,6 @@ project(':capacitor-android').projectDir = new File('../node_modules/@capacitor/
55
include ':capacitor-community-bluetooth-le'
66
project(':capacitor-community-bluetooth-le').projectDir = new File('../node_modules/@capacitor-community/bluetooth-le/android')
77

8-
include ':capacitor-community-safe-area'
9-
project(':capacitor-community-safe-area').projectDir = new File('../node_modules/@capacitor-community/safe-area/android')
10-
118
include ':capacitor-app'
129
project(':capacitor-app').projectDir = new File('../node_modules/@capacitor/app/android')
1310

ios/App/App/Info.plist

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,8 @@
5757
</array>
5858
<key>UIViewControllerBasedStatusBarAppearance</key>
5959
<true/>
60+
<key>UIStatusBarStyle</key>
61+
<string>UIStatusBarStyleDarkContent</string>
6062
<key>UTExportedTypeDeclarations</key>
6163
<array>
6264
<dict>

ios/App/Podfile

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ def capacitor_pods
1212
pod 'Capacitor', :path => '../../node_modules/@capacitor/ios'
1313
pod 'CapacitorCordova', :path => '../../node_modules/@capacitor/ios'
1414
pod 'CapacitorCommunityBluetoothLe', :path => '../../node_modules/@capacitor-community/bluetooth-le'
15-
pod 'CapacitorCommunitySafeArea', :path => '../../node_modules/@capacitor-community/safe-area'
1615
pod 'CapacitorApp', :path => '../../node_modules/@capacitor/app'
1716
pod 'CapacitorFilesystem', :path => '../../node_modules/@capacitor/filesystem'
1817
pod 'MicrobitCapacitorCommunityNordicDfu', :path => '../../node_modules/@microbit/capacitor-community-nordic-dfu'

ios/App/Podfile.lock

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@ PODS:
55
- Capacitor
66
- CapacitorCommunityBluetoothLe (7.3.0):
77
- Capacitor
8-
- CapacitorCommunitySafeArea (7.0.0-beta.5):
9-
- Capacitor
108
- CapacitorCordova (7.4.4)
119
- CapacitorFilesystem (7.1.6):
1210
- Capacitor
@@ -23,7 +21,6 @@ DEPENDENCIES:
2321
- "Capacitor (from `../../node_modules/@capacitor/ios`)"
2422
- "CapacitorApp (from `../../node_modules/@capacitor/app`)"
2523
- "CapacitorCommunityBluetoothLe (from `../../node_modules/@capacitor-community/bluetooth-le`)"
26-
- "CapacitorCommunitySafeArea (from `../../node_modules/@capacitor-community/safe-area`)"
2724
- "CapacitorCordova (from `../../node_modules/@capacitor/ios`)"
2825
- "CapacitorFilesystem (from `../../node_modules/@capacitor/filesystem`)"
2926
- "MicrobitCapacitorCommunityNordicDfu (from `../../node_modules/@microbit/capacitor-community-nordic-dfu`)"
@@ -41,8 +38,6 @@ EXTERNAL SOURCES:
4138
:path: "../../node_modules/@capacitor/app"
4239
CapacitorCommunityBluetoothLe:
4340
:path: "../../node_modules/@capacitor-community/bluetooth-le"
44-
CapacitorCommunitySafeArea:
45-
:path: "../../node_modules/@capacitor-community/safe-area"
4641
CapacitorCordova:
4742
:path: "../../node_modules/@capacitor/ios"
4843
CapacitorFilesystem:
@@ -54,14 +49,13 @@ SPEC CHECKSUMS:
5449
Capacitor: 358dd1c3fdd71d969547b17e159fd8a7736cb45f
5550
CapacitorApp: 26587c2ce485d88ddb39adb21cac64f8e481afe3
5651
CapacitorCommunityBluetoothLe: 41f9dec8a4c16ab6b81e56402b6047fc19b4735d
57-
CapacitorCommunitySafeArea: 53e3ad999bada9892cb4e9aca8fa8012aabad4b2
5852
CapacitorCordova: bf648a636f3c153f652d312ae145fb508b6ffced
5953
CapacitorFilesystem: 66f05ee0d8b1ccdc00d509091273a9b3b57c4a0b
6054
IONFilesystemLib: 89258b8e3e85465da93127d25d7ce37f977e8a6f
6155
MicrobitCapacitorCommunityNordicDfu: 2fc86a9ebd698d5609023cafd74ece8b5d64a59e
6256
NordicDFU: 116a4ec458945889f8e0e71759e03b23c39c3482
6357
ZIPFoundation: b8c29ea7ae353b309bc810586181fd073cb3312c
6458

65-
PODFILE CHECKSUM: 1b18202e6f59ad2a7694de09b5a672105ac90e81
59+
PODFILE CHECKSUM: ea570df87063d164872fb4820e9e9d2e9666790b
6660

6761
COCOAPODS: 1.16.2

0 commit comments

Comments
 (0)