Skip to content

Commit

Permalink
Fix issue with in-app browser closing on app re-open (#28)
Browse files Browse the repository at this point in the history
  • Loading branch information
mineiwik authored Nov 27, 2024
1 parent 0af012f commit 5dde0f4
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 2 deletions.
6 changes: 5 additions & 1 deletion android/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,13 @@
android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|screenSize|smallestScreenSize|uiMode"
android:exported="true"
android:label="@string/app_name"
android:launchMode="singleTask"
android:launchMode="standard"
android:screenOrientation="portrait"
android:windowSoftInputMode="adjustResize">
</activity>
<activity
android:name=".LaunchActivity"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
Expand Down
19 changes: 19 additions & 0 deletions android/app/src/main/java/io/netbird/client/LaunchActivity.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package io.netbird.client;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;

public class LaunchActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
MainApplication application = (MainApplication) getApplication();
// check that MainActivity is not started yet
if (!application.isActivityInBackStack(MainActivity.class)) {
Intent intent = new Intent(this, MainActivity.class);
startActivity(intent);
}
finish();
}
}
10 changes: 10 additions & 0 deletions android/app/src/main/java/io/netbird/client/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ protected void onCreate(Bundle savedInstanceState) {
SplashScreen.show(this);
MainApplication application = (MainApplication) getApplication();

application.addActivityToStack(this.getClass());

sendEventActionSharedPref = getSharedPreferences(SEND_EVENT_ACTION, Context.MODE_PRIVATE);
sendEventToReactMessageKey = sendEventActionSharedPref.getString(MESSAGE_KEY, "");

Expand All @@ -75,4 +77,12 @@ protected void onCreate(Bundle savedInstanceState) {
}
});
}

@Override
protected void onDestroy() {
super.onDestroy();
MainApplication application = (MainApplication) getApplication();

application.removeActivityFromStack(this.getClass());
}
}
15 changes: 15 additions & 0 deletions android/app/src/main/java/io/netbird/client/MainApplication.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,28 @@
import com.facebook.react.defaults.DefaultReactNativeHost;
import com.facebook.soloader.SoLoader;

import java.util.ArrayList;
import java.util.List;

import io.netbird.client.tool.NetworkChangeNotifier;

public class MainApplication extends Application implements ReactApplication {
private final NotificationReceiver notificationReceiver = new NotificationReceiver();

private ArrayList<Class> runningActivities = new ArrayList<>();

public void addActivityToStack (Class cls) {
if (!runningActivities.contains(cls)) runningActivities.add(cls);
}

public void removeActivityFromStack (Class cls) {
if (runningActivities.contains(cls)) runningActivities.remove(cls);
}

public boolean isActivityInBackStack (Class cls) {
return runningActivities.contains(cls);
}

private final ReactNativeHost mReactNativeHost =
new DefaultReactNativeHost(this) {
@Override
Expand Down
2 changes: 1 addition & 1 deletion src/components/InAppBrowser/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ export const openLink = async (url: string, animated = true) => {
},
hasBackButton: true,
browserPackage: undefined,
showInRecents: false,
showInRecents: true,
includeReferrer: false,
});
} else {
Expand Down

0 comments on commit 5dde0f4

Please sign in to comment.