|
@@ -3,48 +3,29 @@ package com.reactnativenavigation.layout.impl;
|
3
|
3
|
import android.app.Activity;
|
4
|
4
|
import android.os.Bundle;
|
5
|
5
|
import android.view.View;
|
6
|
|
-import android.widget.FrameLayout;
|
7
|
6
|
|
8
|
7
|
import com.facebook.react.ReactInstanceManager;
|
9
|
8
|
import com.facebook.react.ReactRootView;
|
10
|
|
-import com.reactnativenavigation.layout.Layout;
|
11
|
9
|
import com.reactnativenavigation.react.NavigationEvent;
|
12
|
|
-import com.reactnativenavigation.utils.CompatUtils;
|
|
10
|
+import com.reactnativenavigation.viewcontrollers.ViewController;
|
13
|
11
|
|
14
|
|
-public class RootLayout implements Layout, View.OnAttachStateChangeListener {
|
|
12
|
+public class RootLayout extends ViewController implements View.OnAttachStateChangeListener {
|
15
|
13
|
|
16
|
14
|
private final String id;
|
17
|
15
|
private final String name;
|
18
|
|
- private final FrameLayout view;
|
19
|
|
- private final ReactRootView reactRootView;
|
20
|
16
|
private final ReactInstanceManager reactInstanceManager;
|
21
|
|
- private StackLayout parentStackLayout;
|
22
|
17
|
|
23
|
|
- public RootLayout(Activity activity, String id, String name, final ReactInstanceManager reactInstanceManager) {
|
|
18
|
+ public RootLayout(final Activity activity, final String id, final String name, final ReactInstanceManager reactInstanceManager) {
|
|
19
|
+ super(activity);
|
24
|
20
|
this.id = id;
|
25
|
21
|
this.name = name;
|
26
|
22
|
this.reactInstanceManager = reactInstanceManager;
|
27
|
|
- reactRootView = new ReactRootView(activity);
|
28
|
|
- reactRootView.addOnAttachStateChangeListener(this);
|
29
|
|
- Bundle opts = new Bundle();
|
30
|
|
- opts.putString("id", this.id);
|
31
|
|
- reactRootView.startReactApplication(this.reactInstanceManager, this.name, opts);
|
32
|
|
- reactRootView.setEventListener(new ReactRootView.ReactRootViewEventListener() {
|
33
|
|
- @Override
|
34
|
|
- public void onAttachedToReactInstance(final ReactRootView reactRootView) {
|
35
|
|
- reactRootView.setEventListener(null);
|
36
|
|
- onStart();
|
37
|
|
- }
|
38
|
|
- });
|
39
|
|
- view = new FrameLayout(activity);
|
40
|
|
- view.addView(reactRootView);
|
41
|
|
- view.setId(CompatUtils.generateViewId());
|
42
|
23
|
}
|
43
|
24
|
|
44
|
|
- @Override
|
45
|
|
- public void destroy() {
|
46
|
|
- reactRootView.unmountReactApplication();
|
47
|
|
- }
|
|
25
|
+// @Override
|
|
26
|
+// public void destroy() {
|
|
27
|
+// reactRootView.unmountReactApplication();
|
|
28
|
+// }
|
48
|
29
|
|
49
|
30
|
@Override
|
50
|
31
|
public void onViewAttachedToWindow(final View v) {
|
|
@@ -56,11 +37,6 @@ public class RootLayout implements Layout, View.OnAttachStateChangeListener {
|
56
|
37
|
onStop();
|
57
|
38
|
}
|
58
|
39
|
|
59
|
|
- @Override
|
60
|
|
- public View getView() {
|
61
|
|
- return view;
|
62
|
|
- }
|
63
|
|
-
|
64
|
40
|
private void onStart() {
|
65
|
41
|
new NavigationEvent(reactInstanceManager.getCurrentReactContext()).containerStart(id);
|
66
|
42
|
}
|
|
@@ -69,12 +45,20 @@ public class RootLayout implements Layout, View.OnAttachStateChangeListener {
|
69
|
45
|
new NavigationEvent(reactInstanceManager.getCurrentReactContext()).containerStop(id);
|
70
|
46
|
}
|
71
|
47
|
|
72
|
|
- public void setParentStackLayout(final StackLayout parentStackLayout) {
|
73
|
|
- this.parentStackLayout = parentStackLayout;
|
74
|
|
- }
|
75
|
|
-
|
76
|
48
|
@Override
|
77
|
|
- public StackLayout getParentStackLayout() {
|
78
|
|
- return parentStackLayout;
|
|
49
|
+ protected View onCreateView() {
|
|
50
|
+ ReactRootView reactRootView = new ReactRootView(getActivity());
|
|
51
|
+ reactRootView.addOnAttachStateChangeListener(this);
|
|
52
|
+ Bundle opts = new Bundle();
|
|
53
|
+ opts.putString("id", this.id);
|
|
54
|
+ reactRootView.startReactApplication(this.reactInstanceManager, this.name, opts);
|
|
55
|
+ reactRootView.setEventListener(new ReactRootView.ReactRootViewEventListener() {
|
|
56
|
+ @Override
|
|
57
|
+ public void onAttachedToReactInstance(final ReactRootView reactRootView) {
|
|
58
|
+ reactRootView.setEventListener(null);
|
|
59
|
+ onStart();
|
|
60
|
+ }
|
|
61
|
+ });
|
|
62
|
+ return reactRootView;
|
79
|
63
|
}
|
80
|
64
|
}
|