Daniel Zlotin 7 лет назад
Родитель
Сommit
c7c4507639

+ 5
- 0
lib/android/app/src/main/java/com/reactnativenavigation/NavigationActivity.java Просмотреть файл

@@ -4,6 +4,7 @@ import android.os.Bundle;
4 4
 import android.support.annotation.Nullable;
5 5
 import android.support.v7.app.AppCompatActivity;
6 6
 import android.view.KeyEvent;
7
+import android.widget.Toast;
7 8
 
8 9
 import com.facebook.react.modules.core.DefaultHardwareBackBtnHandler;
9 10
 import com.reactnativenavigation.viewcontrollers.Navigator;
@@ -61,4 +62,8 @@ public class NavigationActivity extends AppCompatActivity implements DefaultHard
61 62
 	public Navigator getNavigator() {
62 63
 		return navigator;
63 64
 	}
65
+
66
+	public void toast(final String text) {
67
+		Toast.makeText(this, text, Toast.LENGTH_LONG).show();
68
+	}
64 69
 }

+ 0
- 3
lib/android/app/src/main/java/com/reactnativenavigation/NavigationApplication.java Просмотреть файл

@@ -1,7 +1,6 @@
1 1
 package com.reactnativenavigation;
2 2
 
3 3
 import android.app.Application;
4
-import android.content.Context;
5 4
 
6 5
 import com.facebook.react.ReactApplication;
7 6
 import com.facebook.react.ReactNativeHost;
@@ -9,13 +8,11 @@ import com.reactnativenavigation.react.ReactGateway;
9 8
 
10 9
 public abstract class NavigationApplication extends Application implements ReactApplication {
11 10
 
12
-	public static Context context;
13 11
 	private ReactGateway reactGateway;
14 12
 
15 13
 	@Override
16 14
 	public void onCreate() {
17 15
 		super.onCreate();
18
-		context = this;
19 16
 		reactGateway = new ReactGateway(this, isDebug());
20 17
 	}
21 18
 

+ 12
- 10
lib/android/app/src/main/java/com/reactnativenavigation/react/NavigationReactInitializer.java Просмотреть файл

@@ -4,7 +4,6 @@ import com.facebook.react.ReactInstanceManager;
4 4
 import com.facebook.react.bridge.ReactContext;
5 5
 import com.facebook.react.devsupport.interfaces.PackagerStatusCallback;
6 6
 import com.reactnativenavigation.NavigationActivity;
7
-import com.reactnativenavigation.utils.Toaster;
8 7
 import com.reactnativenavigation.utils.UiThread;
9 8
 
10 9
 public class NavigationReactInitializer implements ReactInstanceManager.ReactInstanceEventListener {
@@ -13,7 +12,6 @@ public class NavigationReactInitializer implements ReactInstanceManager.ReactIns
13 12
 	private final DevPermissionRequest devPermissionRequest;
14 13
 	private final boolean isDebug;
15 14
 	private boolean waitingForAppLaunchEvent = true;
16
-	private boolean isPackagerRunning = false;
17 15
 
18 16
 	public NavigationReactInitializer(ReactInstanceManager reactInstanceManager, boolean isDebug) {
19 17
 		this.reactInstanceManager = reactInstanceManager;
@@ -30,7 +28,7 @@ public class NavigationReactInitializer implements ReactInstanceManager.ReactIns
30 28
 			devPermissionRequest.askPermission(activity);
31 29
 		} else {
32 30
 			reactInstanceManager.onHostResume(activity, activity);
33
-			prepareReactApp();
31
+			checkBundleThenPrepareReact(activity);
34 32
 		}
35 33
 	}
36 34
 
@@ -47,26 +45,30 @@ public class NavigationReactInitializer implements ReactInstanceManager.ReactIns
47 45
 		}
48 46
 	}
49 47
 
50
-	private void prepareReactApp() {
51
-		if (isDebug && !isPackagerRunning) {
48
+	private void checkBundleThenPrepareReact(final NavigationActivity activity) {
49
+		if (isDebug) {
52 50
 			reactInstanceManager.getDevSupportManager().isPackagerRunning(new PackagerStatusCallback() {
53 51
 				@Override
54 52
 				public void onPackagerStatusFetched(final boolean packagerIsRunning) {
55 53
 					UiThread.post(new Runnable() {
56 54
 						@Override
57 55
 						public void run() {
58
-							isPackagerRunning = packagerIsRunning;
59
-							if (!isPackagerRunning) {
60
-								Toaster.toast("Packager is not running!");
56
+							if (!packagerIsRunning) {
57
+								activity.toast("Packager is not running!");
58
+								activity.finish();
61 59
 							} else {
62
-								prepareReactApp();
60
+								prepareReactAppWithWorkingBundle();
63 61
 							}
64 62
 						}
65 63
 					});
66 64
 				}
67 65
 			});
68
-			return;
66
+		} else {
67
+			prepareReactAppWithWorkingBundle();
69 68
 		}
69
+	}
70
+
71
+	private void prepareReactAppWithWorkingBundle() {
70 72
 		reactInstanceManager.addReactInstanceEventListener(this);
71 73
 		if (shouldCreateContext()) {
72 74
 			reactInstanceManager.createReactContextInBackground();

+ 0
- 11
lib/android/app/src/main/java/com/reactnativenavigation/utils/Toaster.java Просмотреть файл

@@ -1,11 +0,0 @@
1
-package com.reactnativenavigation.utils;
2
-
3
-import android.widget.Toast;
4
-
5
-import com.reactnativenavigation.NavigationApplication;
6
-
7
-public class Toaster {
8
-	public static void toast(String text) {
9
-		Toast.makeText(NavigationApplication.context, text, Toast.LENGTH_LONG).show();
10
-	}
11
-}