Browse Source

containerOnStop/Start - half way there

Guy Carmeli 7 years ago
parent
commit
9fbc6f30f8

+ 27
- 2
android/app/src/main/java/com/reactnativenavigation/layout/Container.java View File

1
 package com.reactnativenavigation.layout;
1
 package com.reactnativenavigation.layout;
2
 
2
 
3
 import android.content.Context;
3
 import android.content.Context;
4
+import android.util.Log;
4
 import android.widget.FrameLayout;
5
 import android.widget.FrameLayout;
5
 
6
 
7
+import com.reactnativenavigation.NavigationApplication;
8
+import com.reactnativenavigation.react.NavigationEventEmitter;
9
+
6
 public class Container extends FrameLayout {
10
 public class Container extends FrameLayout {
7
-	public Container(Context context, LayoutFactory.ReactRootViewCreator reactRootViewCreator, String id, String name) {
11
+    private static final String TAG = "Container";
12
+    private String id;
13
+
14
+    public Container(Context context, LayoutFactory.ReactRootViewCreator reactRootViewCreator, String id, String name) {
8
 		super(context);
15
 		super(context);
9
-		addView(reactRootViewCreator.create(id, name));
16
+        this.id = id;
17
+        addView(reactRootViewCreator.create(id, name));
18
+
10
 	}
19
 	}
20
+
21
+//    @Override
22
+//    protected void onAttachedToWindow() {
23
+//        Log.d(TAG, "onAttachedToWindow: " + id);
24
+//        super.onAttachedToWindow();
25
+//        NavigationEventEmitter.emit(NavigationApplication.instance.getReactNativeHost().getReactInstanceManager().getCurrentReactContext())
26
+//                .containerStart(id);
27
+//    }
28
+
29
+    @Override
30
+    protected void onDetachedFromWindow() {
31
+        Log.d(TAG, "onDetachedFromWindow: " + id);
32
+        super.onDetachedFromWindow();
33
+        NavigationEventEmitter.emit(NavigationApplication.instance.getReactNativeHost().getReactInstanceManager().getCurrentReactContext())
34
+                .containerStop(id);
35
+    }
11
 }
36
 }

+ 27
- 6
android/app/src/main/java/com/reactnativenavigation/react/NavigationEventEmitter.java View File

7
 import static com.facebook.react.modules.core.DeviceEventManagerModule.RCTDeviceEventEmitter;
7
 import static com.facebook.react.modules.core.DeviceEventManagerModule.RCTDeviceEventEmitter;
8
 
8
 
9
 public class NavigationEventEmitter {
9
 public class NavigationEventEmitter {
10
-	private static String onAppLaunched = "RNN.appLaunched";
11
-	private static String containerStart = "RNN.containerStart";
12
-	private static String containerStop = "RNN.containerStop";
10
+	private static final String onAppLaunched = "RNN.appLaunched";
11
+	private static final String containerStart = "RNN.containerStart";
12
+	private static final String containerStop = "RNN.containerStop";
13
 
13
 
14
 	public static NavigationEventEmitter emit(ReactContext context) {
14
 	public static NavigationEventEmitter emit(ReactContext context) {
15
 		return new NavigationEventEmitter(context);
15
 		return new NavigationEventEmitter(context);
26
 	}
26
 	}
27
 
27
 
28
 	private void emit(String eventName) {
28
 	private void emit(String eventName) {
29
-		WritableMap data = Arguments.createMap();
30
-		emitter.emit(eventName, data);
31
-	}
29
+        emit(eventName, Arguments.createMap());
30
+    }
31
+
32
+    private void emit(String eventName, WritableMap data) {
33
+        emitter.emit(eventName, data);
34
+    }
35
+
36
+    private void emit(String eventName, String param) {
37
+        emitter.emit(eventName, param);
38
+    }
39
+
40
+    public void containerStop(String id) {
41
+        WritableMap data = Arguments.createMap();
42
+        data.putString("id", id);
43
+//        emit(containerStop, data);
44
+        emit(containerStop, id);
45
+    }
46
+
47
+    public void containerStart(String id) {
48
+        WritableMap data = Arguments.createMap();
49
+        data.putString("id", id);
50
+//        emit(containerStart, data);
51
+        emit(containerStart, id);
52
+    }
32
 }
53
 }