Bladeren bron

Emit appLaunchedEvent and call setRoot

Guy Carmeli 8 jaren geleden
bovenliggende
commit
28ab2c2c60

+ 11
- 0
android/app/src/main/java/com/reactnativenavigation/controllers/NavigationActivity.java Bestand weergeven

@@ -3,11 +3,14 @@ package com.reactnativenavigation.controllers;
3 3
 import android.os.Bundle;
4 4
 import android.support.v7.app.AppCompatActivity;
5 5
 
6
+import com.facebook.react.ReactInstanceManager;
6 7
 import com.facebook.react.ReactNativeHost;
7 8
 import com.facebook.react.ReactPackage;
9
+import com.facebook.react.bridge.ReactContext;
8 10
 import com.facebook.react.modules.core.DefaultHardwareBackBtnHandler;
9 11
 import com.facebook.react.shell.MainReactPackage;
10 12
 import com.reactnativenavigation.R;
13
+import com.reactnativenavigation.react.NavigationEventEmitter;
11 14
 import com.reactnativenavigation.react.NavigationPackage;
12 15
 import com.reactnativenavigation.react.ReactDevPermission;
13 16
 
@@ -42,7 +45,15 @@ public class NavigationActivity extends AppCompatActivity implements DefaultHard
42 45
             return;
43 46
         }
44 47
 
48
+        host.getReactInstanceManager().addReactInstanceEventListener(new ReactInstanceManager.ReactInstanceEventListener() {
49
+            @Override
50
+            public void onReactContextInitialized(ReactContext context) {
51
+                new NavigationEventEmitter(context).emitAppLaunched();
52
+            }
53
+        });
45 54
         host.getReactInstanceManager().createReactContextInBackground();
55
+
56
+
46 57
     }
47 58
 
48 59
     @Override

+ 9
- 0
android/app/src/main/java/com/reactnativenavigation/controllers/NavigationApplication.java Bestand weergeven

@@ -2,14 +2,23 @@ package com.reactnativenavigation.controllers;
2 2
 
3 3
 import android.app.Application;
4 4
 
5
+import com.facebook.react.bridge.ReactContext;
6
+import com.reactnativenavigation.react.NavigationEventEmitter;
7
+
5 8
 public abstract class NavigationApplication extends Application {
6 9
     public static NavigationApplication instance;
10
+    public NavigationEventEmitter eventEmitter;
7 11
 
8 12
     @Override
9 13
     public void onCreate() {
10 14
         super.onCreate();
11 15
         instance = this;
16
+
12 17
     }
13 18
 
14 19
     public abstract boolean isDebug();
20
+
21
+    public void onReactContextInitialized(ReactContext context) {
22
+        eventEmitter = new NavigationEventEmitter(context);
23
+    }
15 24
 }

+ 24
- 0
android/app/src/main/java/com/reactnativenavigation/react/NavigationEventEmitter.java Bestand weergeven

@@ -0,0 +1,24 @@
1
+package com.reactnativenavigation.react;
2
+
3
+import com.facebook.react.bridge.Arguments;
4
+import com.facebook.react.bridge.ReactContext;
5
+import com.facebook.react.bridge.WritableMap;
6
+import com.facebook.react.modules.core.DeviceEventManagerModule;
7
+
8
+public class NavigationEventEmitter {
9
+
10
+    private final DeviceEventManagerModule.RCTDeviceEventEmitter emitter;
11
+
12
+    public NavigationEventEmitter(ReactContext reactContext) {
13
+        this.emitter = reactContext.getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter.class);
14
+    }
15
+
16
+    public void emitAppLaunched() {
17
+        emit("RNN.appLaunched");
18
+    }
19
+
20
+    private void emit(String eventName) {
21
+        WritableMap data = Arguments.createMap();
22
+        emitter.emit(eventName, data);
23
+    }
24
+}

+ 8
- 1
android/app/src/main/java/com/reactnativenavigation/react/NavigationModule.java Bestand weergeven

@@ -2,9 +2,11 @@ package com.reactnativenavigation.react;
2 2
 
3 3
 import com.facebook.react.bridge.ReactApplicationContext;
4 4
 import com.facebook.react.bridge.ReactContextBaseJavaModule;
5
+import com.facebook.react.bridge.ReactMethod;
6
+import com.facebook.react.bridge.ReadableMap;
5 7
 
6 8
 public class NavigationModule extends ReactContextBaseJavaModule {
7
-    public static final String NAME = "NavigationModule";
9
+    public static final String NAME = "RNNBridgeModule";
8 10
 
9 11
     public NavigationModule(ReactApplicationContext reactContext) {
10 12
         super(reactContext);
@@ -14,4 +16,9 @@ public class NavigationModule extends ReactContextBaseJavaModule {
14 16
     public String getName() {
15 17
         return NAME;
16 18
     }
19
+
20
+    @ReactMethod
21
+    public void setRoot(ReadableMap layoutTree) {
22
+        
23
+    }
17 24
 }