codeplay-common 4.6.2 → 4.6.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.
@@ -122,21 +122,73 @@ animations.forEach((animation) => {
122
122
  const newMainActivityCode =
123
123
  `package ${findPackageName()};
124
124
 
125
- import android.os.Build;
126
- import android.os.Bundle;
127
- import com.getcapacitor.BridgeActivity;
128
-
129
- import androidx.activity.EdgeToEdge;
130
-
131
- public class MainActivity extends BridgeActivity {
132
- @Override
133
- protected void onCreate(Bundle savedInstanceState) {
134
- super.onCreate(savedInstanceState);
135
-
136
- // Android 15+ enforces edge-to-edge. Older Android and Fire OS
137
- // should let the system keep the WebView clear of system bars.
138
- if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.VANILLA_ICE_CREAM) {
139
- EdgeToEdge.enable(this);
125
+ import android.os.Build;
126
+ import android.os.Bundle;
127
+ import android.view.View;
128
+ import android.webkit.WebView;
129
+ import com.getcapacitor.BridgeActivity;
130
+ import com.getcapacitor.CapConfig;
131
+ import com.getcapacitor.WebViewListener;
132
+ import org.json.JSONException;
133
+ import java.util.Locale;
134
+
135
+ import androidx.activity.EdgeToEdge;
136
+ import androidx.core.graphics.Insets;
137
+ import androidx.core.view.ViewCompat;
138
+ import androidx.core.view.WindowInsetsCompat;
139
+
140
+ public class MainActivity extends BridgeActivity {
141
+ @Override
142
+ protected void load() {
143
+ if (Build.VERSION.SDK_INT < Build.VERSION_CODES.VANILLA_ICE_CREAM) {
144
+ config = CapConfig.loadDefault(this);
145
+ try {
146
+ config.getPluginConfiguration("SystemBars").getConfigJSON().put("insetsHandling", "disable");
147
+ } catch (JSONException e) {
148
+ throw new IllegalStateException("Unable to configure system bars", e);
149
+ }
150
+ }
151
+ super.load();
152
+ }
153
+
154
+ @Override
155
+ protected void onCreate(Bundle savedInstanceState) {
156
+ if (Build.VERSION.SDK_INT < Build.VERSION_CODES.VANILLA_ICE_CREAM) {
157
+ bridgeBuilder.addWebViewListener(new WebViewListener() {
158
+ @Override
159
+ public void onPageCommitVisible(WebView webView, String url) {
160
+ ViewCompat.requestApplyInsets(getWindow().getDecorView());
161
+ }
162
+ });
163
+ }
164
+ super.onCreate(savedInstanceState);
165
+
166
+ EdgeToEdge.enable(this);
167
+ if (Build.VERSION.SDK_INT < Build.VERSION_CODES.VANILLA_ICE_CREAM) {
168
+ View decorView = getWindow().getDecorView();
169
+ ViewCompat.setOnApplyWindowInsetsListener(decorView, (view, insets) -> {
170
+ Insets bars = insets.getInsets(WindowInsetsCompat.Type.systemBars() | WindowInsetsCompat.Type.displayCutout());
171
+ float density = getResources().getDisplayMetrics().density;
172
+ int top = Math.round(bars.top / density);
173
+ int right = Math.round(bars.right / density);
174
+ int bottom = insets.isVisible(WindowInsetsCompat.Type.ime()) ? 0 : Math.round(bars.bottom / density);
175
+ int left = Math.round(bars.left / density);
176
+
177
+ if (bridge != null && bridge.getWebView() != null) {
178
+ String script = String.format(Locale.US, """
179
+ try {
180
+ const root = document.documentElement;
181
+ root.style.setProperty('--android-system-bar-top', '%dpx');
182
+ root.style.setProperty('--android-system-bar-right', '%dpx');
183
+ root.style.setProperty('--android-system-bar-bottom', '%dpx');
184
+ root.style.setProperty('--android-system-bar-left', '%dpx');
185
+ } catch (e) {}
186
+ """, top, right, bottom, left);
187
+ bridge.getWebView().evaluateJavascript(script, null);
188
+ }
189
+ return insets;
190
+ });
191
+ ViewCompat.requestApplyInsets(decorView);
140
192
  }
141
193
 
142
194
  // Handle custom splash screen exit animation
@@ -152,8 +204,8 @@ import androidx.activity.EdgeToEdge;
152
204
  });
153
205
  }
154
206
  }
155
- }
156
- `;
207
+ }
208
+ `;
157
209
 
158
210
  // Write the new MainActivity.java content
159
211
  writeMainActivity(newMainActivityCode);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "codeplay-common",
3
- "version": "4.6.2",
3
+ "version": "4.6.3",
4
4
  "description": "Common build scripts and files",
5
5
  "scripts": {
6
6
  "postinstall": "node scripts/sync-files.js",