|
@@ -22,29 +22,39 @@ public class Container extends FrameLayout {
|
22
|
22
|
this.id = id;
|
23
|
23
|
this.name = name;
|
24
|
24
|
addView(createReactRootView());
|
25
|
|
-
|
26
|
25
|
}
|
27
|
26
|
|
28
|
27
|
private View createReactRootView() {
|
29
|
|
- ReactRootView rootView = new ReactRootView(getContext());
|
|
28
|
+ final ReactRootView rootView = new ReactRootView(getContext());
|
30
|
29
|
Bundle opts = new Bundle();
|
31
|
30
|
opts.putString("id", id);
|
32
|
31
|
rootView.startReactApplication(reactNativeHost.getReactInstanceManager(), name, opts);
|
|
32
|
+ rootView.setEventListener(new ReactRootView.ReactRootViewEventListener() {
|
|
33
|
+ @Override
|
|
34
|
+ public void onAttachedToReactInstance(final ReactRootView reactRootView) {
|
|
35
|
+ rootView.setEventListener(null);
|
|
36
|
+ onStart();
|
|
37
|
+ }
|
|
38
|
+ });
|
33
|
39
|
return rootView;
|
34
|
40
|
}
|
35
|
41
|
|
36
|
|
- // @Override
|
37
|
|
-// protected void onAttachedToWindow() {
|
38
|
|
-// super.onAttachedToWindow();
|
39
|
|
-// NavigationEventEmitter.emit(NavigationApplication.instance.getReactNativeHost().getReactInstanceManager().getCurrentReactContext())
|
40
|
|
-// .containerStart(id);
|
41
|
|
-// }
|
42
|
|
-
|
43
|
42
|
@Override
|
44
|
43
|
protected void onDetachedFromWindow() {
|
45
|
44
|
super.onDetachedFromWindow();
|
46
|
|
- //TODO this is wrong
|
47
|
|
- ReactContext reactContext = ((NavigationApplication) getContext().getApplicationContext()).getReactNativeHost().getReactInstanceManager().getCurrentReactContext();
|
48
|
|
- new NavigationEventEmitter(reactContext).containerStart(id);
|
|
45
|
+ onStop();
|
|
46
|
+ }
|
|
47
|
+
|
|
48
|
+ private void onStart() {
|
|
49
|
+ new NavigationEventEmitter(reactContext()).containerStart(id);
|
|
50
|
+ }
|
|
51
|
+
|
|
52
|
+ private void onStop() {
|
|
53
|
+ new NavigationEventEmitter(reactContext()).containerStop(id);
|
|
54
|
+ }
|
|
55
|
+
|
|
56
|
+ private ReactContext reactContext() {
|
|
57
|
+ //TODO this is wrong, we should inject reactContext somehow
|
|
58
|
+ return ((NavigationApplication) getContext().getApplicationContext()).getReactNativeHost().getReactInstanceManager().getCurrentReactContext();
|
49
|
59
|
}
|
50
|
60
|
}
|