Daniel Zlotin 7 年之前
父節點
當前提交
30f84b8dc2

+ 4
- 0
AndroidE2E/app/src/androidTest/java/com/reactnativenavigation/e2e/androide2e/TopLevelApiTest.java 查看文件

@@ -43,5 +43,9 @@ public class TopLevelApiTest extends BaseTest {
43 43
 		elementByText("onStart");
44 44
 		device().pressBack();
45 45
 		assertExists(By.text("componentWillUnmount"));
46
+		elementByText("OK").click();
47
+		assertExists(By.text("onStop"));
48
+		elementByText("OK").click();
49
+		assertMainShown();
46 50
 	}
47 51
 }

+ 1
- 6
lib/android/app/src/main/java/com/reactnativenavigation/NavigationApplication.java 查看文件

@@ -3,10 +3,8 @@ package com.reactnativenavigation;
3 3
 import android.app.Application;
4 4
 
5 5
 import com.facebook.react.ReactApplication;
6
-import com.facebook.react.ReactInstanceManager;
7 6
 import com.facebook.react.ReactNativeHost;
8 7
 import com.reactnativenavigation.controllers.ActivityLifecycleDelegate;
9
-import com.reactnativenavigation.react.DevPermissionRequest;
10 8
 import com.reactnativenavigation.react.NavigationReactNativeHost;
11 9
 
12 10
 public abstract class NavigationApplication extends Application implements ReactApplication {
@@ -18,10 +16,7 @@ public abstract class NavigationApplication extends Application implements React
18 16
 	public void onCreate() {
19 17
 		super.onCreate();
20 18
 		reactNativeHost = new NavigationReactNativeHost(this, isDebug());
21
-
22
-		ReactInstanceManager reactInstanceManager = reactNativeHost.getReactInstanceManager();
23
-		DevPermissionRequest devPermissionRequest = new DevPermissionRequest(this, isDebug());
24
-		activityLifecycle = new ActivityLifecycleDelegate(reactInstanceManager, devPermissionRequest);
19
+		activityLifecycle = new ActivityLifecycleDelegate(reactNativeHost.getReactInstanceManager(), isDebug());
25 20
 	}
26 21
 
27 22
 	@Override

+ 4
- 4
lib/android/app/src/main/java/com/reactnativenavigation/controllers/ActivityLifecycleDelegate.java 查看文件

@@ -15,9 +15,9 @@ public class ActivityLifecycleDelegate {
15 15
 	private final DevPermissionRequest devPermissionRequest;
16 16
 	private final AtomicBoolean appLaunchEmitted = new AtomicBoolean(false);
17 17
 
18
-	public ActivityLifecycleDelegate(ReactInstanceManager reactInstanceManager, DevPermissionRequest devPermissionRequest) {
18
+	public ActivityLifecycleDelegate(ReactInstanceManager reactInstanceManager, boolean isDebug) {
19 19
 		this.reactInstanceManager = reactInstanceManager;
20
-		this.devPermissionRequest = devPermissionRequest;
20
+		this.devPermissionRequest = new DevPermissionRequest(isDebug);
21 21
 	}
22 22
 
23 23
 	public void onActivityCreated(NavigationActivity activity) {
@@ -25,8 +25,8 @@ public class ActivityLifecycleDelegate {
25 25
 	}
26 26
 
27 27
 	public void onActivityResumed(NavigationActivity activity) {
28
-		if (devPermissionRequest.shouldAskPermission()) {
29
-			devPermissionRequest.askPermission();
28
+		if (devPermissionRequest.shouldAskPermission(activity)) {
29
+			devPermissionRequest.askPermission(activity);
30 30
 		} else {
31 31
 			reactInstanceManager.onHostResume(activity, activity);
32 32
 			prepareReactApp();

+ 8
- 10
lib/android/app/src/main/java/com/reactnativenavigation/react/DevPermissionRequest.java 查看文件

@@ -1,7 +1,7 @@
1 1
 package com.reactnativenavigation.react;
2 2
 
3 3
 import android.annotation.TargetApi;
4
-import android.app.Application;
4
+import android.app.Activity;
5 5
 import android.content.Intent;
6 6
 import android.os.Build;
7 7
 import android.provider.Settings;
@@ -12,31 +12,29 @@ import com.facebook.react.common.ReactConstants;
12 12
 
13 13
 public class DevPermissionRequest {
14 14
 
15
-	private final Application application;
16 15
 	private final boolean isDebug;
17 16
 
18
-	public DevPermissionRequest(Application application, boolean isDebug) {
19
-		this.application = application;
17
+	public DevPermissionRequest(boolean isDebug) {
20 18
 		this.isDebug = isDebug;
21 19
 	}
22 20
 
23
-	public boolean shouldAskPermission() {
21
+	public boolean shouldAskPermission(Activity activity) {
24 22
 		return isDebug &&
25 23
 				Build.VERSION.SDK_INT >= 23 &&
26
-				!Settings.canDrawOverlays(application);
24
+				!Settings.canDrawOverlays(activity);
27 25
 	}
28 26
 
29 27
 	@TargetApi(23)
30
-	public void askPermission() {
31
-		if (shouldAskPermission()) {
28
+	public void askPermission(Activity activity) {
29
+		if (shouldAskPermission(activity)) {
32 30
 			Intent serviceIntent = new Intent(Settings.ACTION_MANAGE_OVERLAY_PERMISSION);
33 31
 			serviceIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
34
-			application.startActivity(serviceIntent);
32
+			activity.startActivity(serviceIntent);
35 33
 			String msg = "Overlay permissions needs to be granted in order for react native apps to run in dev mode";
36 34
 			Log.w(ReactConstants.TAG, "======================================\n\n");
37 35
 			Log.w(ReactConstants.TAG, msg);
38 36
 			Log.w(ReactConstants.TAG, "\n\n======================================");
39
-			Toast.makeText(application, msg, Toast.LENGTH_LONG).show();
37
+			Toast.makeText(activity, msg, Toast.LENGTH_LONG).show();
40 38
 		}
41 39
 	}
42 40
 }