Skip to content

Commit

Permalink
feat(android): Load alternative layout when no WebView (#7141)
Browse files Browse the repository at this point in the history
  • Loading branch information
jcesarmobile authored Jan 15, 2024
1 parent e1279d9 commit 87c399a
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,13 @@ protected void onCreate(Bundle savedInstanceState) {
bridgeBuilder.setInstanceState(savedInstanceState);
getApplication().setTheme(R.style.AppTheme_NoActionBar);
setTheme(R.style.AppTheme_NoActionBar);
setContentView(R.layout.bridge_layout_main);
try {
setContentView(R.layout.bridge_layout_main);
} catch (Exception ex) {
setContentView(R.layout.no_webview);
return;
}

PluginManager loader = new PluginManager(getAssets());

try {
Expand Down Expand Up @@ -67,8 +73,10 @@ public void onSaveInstanceState(Bundle outState) {
public void onStart() {
super.onStart();
activityDepth++;
this.bridge.onStart();
Logger.debug("App started");
if (this.bridge != null) {
this.bridge.onStart();
Logger.debug("App started");
}
}

@Override
Expand All @@ -81,36 +89,43 @@ public void onRestart() {
@Override
public void onResume() {
super.onResume();
bridge.getApp().fireStatusChange(true);
this.bridge.onResume();
Logger.debug("App resumed");
if (bridge != null) {
bridge.getApp().fireStatusChange(true);
this.bridge.onResume();
Logger.debug("App resumed");
}
}

@Override
public void onPause() {
super.onPause();
this.bridge.onPause();
Logger.debug("App paused");
if (bridge != null) {
this.bridge.onPause();
Logger.debug("App paused");
}
}

@Override
public void onStop() {
super.onStop();

activityDepth = Math.max(0, activityDepth - 1);
if (activityDepth == 0) {
bridge.getApp().fireStatusChange(false);
if (bridge != null) {
activityDepth = Math.max(0, activityDepth - 1);
if (activityDepth == 0) {
bridge.getApp().fireStatusChange(false);
}

this.bridge.onStop();
Logger.debug("App stopped");
}

this.bridge.onStop();
Logger.debug("App stopped");
}

@Override
public void onDestroy() {
super.onDestroy();
this.bridge.onDestroy();
Logger.debug("App destroyed");
if (this.bridge != null) {
this.bridge.onDestroy();
Logger.debug("App destroyed");
}
}

@Override
Expand Down
14 changes: 14 additions & 0 deletions android/capacitor/src/main/res/layout/no_webview.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">

<TextView
android:id="@+id/textView"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:text="@string/no_webview_text"
android:gravity="center"
android:textSize="48sp" />
</LinearLayout>
1 change: 1 addition & 0 deletions android/capacitor/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
<resources>
<string name="no_webview_text">This app requires a WebView to work</string>
</resources>

0 comments on commit 87c399a

Please sign in to comment.