Daniel Zlotin преди 8 години
родител
ревизия
dda074cd5a

+ 1
- 4
lib/android/app/src/main/java/com/reactnativenavigation/NavigationActivity.java Целия файл

16
 		super.onCreate(savedInstanceState);
16
 		super.onCreate(savedInstanceState);
17
 		app().getReactGateway().onActivityCreated(this);
17
 		app().getReactGateway().onActivityCreated(this);
18
 		navigator = new Navigator(this);
18
 		navigator = new Navigator(this);
19
-		navigator.onActivityCreated();
19
+		setContentView(navigator.getView());
20
 	}
20
 	}
21
 
21
 
22
 	@Override
22
 	@Override
23
 	protected void onResume() {
23
 	protected void onResume() {
24
 		super.onResume();
24
 		super.onResume();
25
 		app().getReactGateway().onActivityResumed(this);
25
 		app().getReactGateway().onActivityResumed(this);
26
-		navigator.onActivityResumed();
27
 	}
26
 	}
28
 
27
 
29
 	@Override
28
 	@Override
30
 	protected void onPause() {
29
 	protected void onPause() {
31
 		super.onPause();
30
 		super.onPause();
32
 		app().getReactGateway().onActivityPaused(this);
31
 		app().getReactGateway().onActivityPaused(this);
33
-		navigator.onActivityPaused();
34
 	}
32
 	}
35
 
33
 
36
 	@Override
34
 	@Override
37
 	protected void onDestroy() {
35
 	protected void onDestroy() {
38
 		super.onDestroy();
36
 		super.onDestroy();
39
 		app().getReactGateway().onActivityDestroyed(this);
37
 		app().getReactGateway().onActivityDestroyed(this);
40
-		navigator.onActivityDestroyed();
41
 	}
38
 	}
42
 
39
 
43
 	@Override
40
 	@Override

+ 2
- 2
lib/android/app/src/main/java/com/reactnativenavigation/react/JsDevReloadHandler.java Целия файл

23
 		}
23
 		}
24
 
24
 
25
 		if (keyCode == KeyEvent.KEYCODE_R) {
25
 		if (keyCode == KeyEvent.KEYCODE_R) {
26
-			if (moreThan500MillisSinceLastR()) {
26
+			if (lessThan500MillisSinceLastR()) {
27
 				reactInstanceManager.getDevSupportManager().handleReloadJS();
27
 				reactInstanceManager.getDevSupportManager().handleReloadJS();
28
 				return true;
28
 				return true;
29
 			}
29
 			}
32
 		return false;
32
 		return false;
33
 	}
33
 	}
34
 
34
 
35
-	private boolean moreThan500MillisSinceLastR() {
35
+	private boolean lessThan500MillisSinceLastR() {
36
 		return firstRTimestamp != 0 && System.currentTimeMillis() - firstRTimestamp < 500;
36
 		return firstRTimestamp != 0 && System.currentTimeMillis() - firstRTimestamp < 500;
37
 	}
37
 	}
38
 }
38
 }

+ 14
- 0
lib/android/app/src/main/java/com/reactnativenavigation/react/NavigationReactNativeHost.java Целия файл

4
 
4
 
5
 import com.facebook.react.ReactNativeHost;
5
 import com.facebook.react.ReactNativeHost;
6
 import com.facebook.react.ReactPackage;
6
 import com.facebook.react.ReactPackage;
7
+import com.facebook.react.devsupport.RedBoxHandler;
7
 import com.facebook.react.shell.MainReactPackage;
8
 import com.facebook.react.shell.MainReactPackage;
8
 
9
 
9
 import java.util.Arrays;
10
 import java.util.Arrays;
10
 import java.util.List;
11
 import java.util.List;
11
 
12
 
13
+import javax.annotation.Nullable;
14
+
12
 public class NavigationReactNativeHost extends ReactNativeHost {
15
 public class NavigationReactNativeHost extends ReactNativeHost {
13
 
16
 
14
 	private final boolean isDebug;
17
 	private final boolean isDebug;
18
 		this.isDebug = isDebug;
21
 		this.isDebug = isDebug;
19
 	}
22
 	}
20
 
23
 
24
+	@Override
25
+	public String getJSMainModuleName() {
26
+		return super.getJSMainModuleName();
27
+	}
28
+
29
+	@Nullable
30
+	@Override
31
+	public RedBoxHandler getRedBoxHandler() {
32
+		return super.getRedBoxHandler();
33
+	}
34
+
21
 	@Override
35
 	@Override
22
 	public boolean getUseDeveloperSupport() {
36
 	public boolean getUseDeveloperSupport() {
23
 		return isDebug;
37
 		return isDebug;

+ 27
- 0
lib/android/app/src/main/java/com/reactnativenavigation/react/ReactGateway.java Целия файл

1
 package com.reactnativenavigation.react;
1
 package com.reactnativenavigation.react;
2
 
2
 
3
+import com.facebook.react.devsupport.DevSupportManager;
4
+import com.facebook.react.devsupport.DevSupportManagerImpl;
5
+import com.facebook.react.devsupport.ReactInstanceDevCommandsHandler;
6
+import com.facebook.react.devsupport.RedBoxHandler;
3
 import com.reactnativenavigation.NavigationActivity;
7
 import com.reactnativenavigation.NavigationActivity;
4
 import com.reactnativenavigation.NavigationApplication;
8
 import com.reactnativenavigation.NavigationApplication;
9
+import com.reactnativenavigation.utils.ReflectionUtils;
5
 
10
 
6
 public class ReactGateway {
11
 public class ReactGateway {
12
+
13
+	public interface JsReloadListener {
14
+		void onJsReload();
15
+	}
16
+
7
 	private final NavigationReactNativeHost reactNativeHost;
17
 	private final NavigationReactNativeHost reactNativeHost;
8
 	private final NavigationReactInitializer initializer;
18
 	private final NavigationReactInitializer initializer;
9
 	private final JsDevReloadHandler jsDevReloadHandler;
19
 	private final JsDevReloadHandler jsDevReloadHandler;
10
 
20
 
11
 	public ReactGateway(final NavigationApplication application, final boolean isDebug) {
21
 	public ReactGateway(final NavigationApplication application, final boolean isDebug) {
12
 		reactNativeHost = new NavigationReactNativeHost(application, isDebug);
22
 		reactNativeHost = new NavigationReactNativeHost(application, isDebug);
23
+
24
+		DevSupportManager devSupportManager = reactNativeHost.getReactInstanceManager().getDevSupportManager();
25
+		ReactInstanceDevCommandsHandler reactInstanceCommandsHandler = (ReactInstanceDevCommandsHandler) ReflectionUtils.getDeclaredField(devSupportManager, "mReactInstanceCommandsHandler");
26
+		String packagerPathForJsBundle = reactNativeHost.getJSMainModuleName();
27
+		boolean enableOnCreate = reactNativeHost.getUseDeveloperSupport();
28
+		RedBoxHandler redBoxHandler = reactNativeHost.getRedBoxHandler();
29
+		DevSupportManagerImpl proxy = new DevSupportManagerImpl(application, reactInstanceCommandsHandler, packagerPathForJsBundle, enableOnCreate, redBoxHandler) {
30
+			@Override
31
+			public void handleReloadJS() {
32
+				super.handleReloadJS();
33
+				// onJsReload
34
+//				ReactContext currentReactContext = reactNativeHost.getReactInstanceManager().getCurrentReactContext();
35
+//				((NavigationActivity) currentReactContext.getCurrentActivity()).getNavigator().onDestroy();
36
+			}
37
+		};
38
+		ReflectionUtils.setField(reactNativeHost.getReactInstanceManager(), "mDevSupportManager", proxy);
39
+
13
 		initializer = new NavigationReactInitializer(reactNativeHost.getReactInstanceManager(), isDebug);
40
 		initializer = new NavigationReactInitializer(reactNativeHost.getReactInstanceManager(), isDebug);
14
 		jsDevReloadHandler = new JsDevReloadHandler(reactNativeHost.getReactInstanceManager());
41
 		jsDevReloadHandler = new JsDevReloadHandler(reactNativeHost.getReactInstanceManager());
15
 	}
42
 	}

+ 0
- 24
lib/android/app/src/main/java/com/reactnativenavigation/viewcontrollers/Navigator.java Целия файл

13
 public class Navigator extends ParentController {
13
 public class Navigator extends ParentController {
14
 
14
 
15
 	private ViewController root;
15
 	private ViewController root;
16
-	private boolean activityResumed = false;
17
 
16
 
18
 	public Navigator(final Activity activity) {
17
 	public Navigator(final Activity activity) {
19
 		super(activity, "navigator" + CompatUtils.generateViewId());
18
 		super(activity, "navigator" + CompatUtils.generateViewId());
30
 		return root == null ? Collections.<ViewController>emptyList() : Collections.singletonList(root);
29
 		return root == null ? Collections.<ViewController>emptyList() : Collections.singletonList(root);
31
 	}
30
 	}
32
 
31
 
33
-	/*
34
-	 * Activity lifecycle
35
-	 */
36
-
37
-	public boolean isActivityResumed() {
38
-		return activityResumed;
39
-	}
40
-
41
-	public void onActivityCreated() {
42
-		getActivity().setContentView(getView());
43
-	}
44
-
45
-	public void onActivityResumed() {
46
-		activityResumed = true;
47
-	}
48
-
49
-	public void onActivityPaused() {
50
-		activityResumed = false;
51
-	}
52
-
53
-	public void onActivityDestroyed() {
54
-	}
55
-
56
 	@Override
32
 	@Override
57
 	public boolean handleBack() {
33
 	public boolean handleBack() {
58
 		return root != null && root.handleBack();
34
 		return root != null && root.handleBack();

+ 0
- 20
lib/android/app/src/test/java/com/reactnativenavigation/viewcontrollers/NavigatorTest.java Целия файл

10
 import com.reactnativenavigation.utils.CompatUtils;
10
 import com.reactnativenavigation.utils.CompatUtils;
11
 
11
 
12
 import org.junit.Test;
12
 import org.junit.Test;
13
-import org.robolectric.Shadows;
14
 
13
 
15
 import java.util.Arrays;
14
 import java.util.Arrays;
16
 
15
 
41
 		child5 = new SimpleViewController(activity, "child5");
40
 		child5 = new SimpleViewController(activity, "child5");
42
 	}
41
 	}
43
 
42
 
44
-
45
-	@Test
46
-	public void isActivityResumed() throws Exception {
47
-		assertThat(uut.isActivityResumed()).isFalse();
48
-		uut.onActivityCreated();
49
-		assertThat(uut.isActivityResumed()).isFalse();
50
-		uut.onActivityResumed();
51
-		assertThat(uut.isActivityResumed()).isTrue();
52
-		uut.onActivityPaused();
53
-		assertThat(uut.isActivityResumed()).isFalse();
54
-	}
55
-
56
-	@Test
57
-	public void setsItselfAsContentView() throws Exception {
58
-		assertThat(Shadows.shadowOf(activity).getContentView()).isNull();
59
-		uut.onActivityCreated();
60
-		assertThat(Shadows.shadowOf(activity).getContentView()).isNotNull().isEqualTo(uut.getView());
61
-	}
62
-
63
 	@Test
43
 	@Test
64
 	public void setRoot_AddsChildControllerView() throws Exception {
44
 	public void setRoot_AddsChildControllerView() throws Exception {
65
 		assertThat(uut.getView().getChildCount()).isZero();
45
 		assertThat(uut.getView().getChildCount()).isZero();