Browse Source

It shows welcome screen

Guy Carmeli 8 years ago
parent
commit
7926633fc5

+ 1
- 1
android/app/src/main/AndroidManifest.xml View File

@@ -2,7 +2,7 @@
2 2
     package="com.reactnativenavigation">
3 3
 
4 4
     <application>
5
-        <!--<activity android:name=".controllers.NavigationActivity" />-->
5
+        <activity android:name=".controllers.NavigationActivity"/>
6 6
         <!--<activity-->
7 7
             <!--android:name=".controllers.PortraitNavigationActivity"-->
8 8
             <!--android:screenOrientation="portrait" />-->

+ 5
- 0
android/app/src/main/java/com/reactnativenavigation/container/Container.java View File

@@ -0,0 +1,5 @@
1
+package com.reactnativenavigation.container;
2
+
3
+public class Container {
4
+
5
+}

+ 22
- 3
android/app/src/main/java/com/reactnativenavigation/controllers/NavigationActivity.java View File

@@ -6,6 +6,7 @@ import android.support.v7.app.AppCompatActivity;
6 6
 import com.facebook.react.ReactInstanceManager;
7 7
 import com.facebook.react.ReactNativeHost;
8 8
 import com.facebook.react.ReactPackage;
9
+import com.facebook.react.ReactRootView;
9 10
 import com.facebook.react.bridge.ReactContext;
10 11
 import com.facebook.react.modules.core.DefaultHardwareBackBtnHandler;
11 12
 import com.facebook.react.shell.MainReactPackage;
@@ -18,12 +19,13 @@ import java.util.Arrays;
18 19
 import java.util.List;
19 20
 
20 21
 public class NavigationActivity extends AppCompatActivity implements DefaultHardwareBackBtnHandler {
21
-
22
+    public static NavigationActivity instance;
22 23
     private ReactNativeHost host;
23 24
 
24 25
     @Override
25 26
     public void onCreate(Bundle savedInstanceState) {
26 27
         super.onCreate(savedInstanceState);
28
+        instance = this;
27 29
         setContentView(R.layout.splash);
28 30
         host = new ReactNativeHost(getApplication()) {
29 31
             @Override
@@ -52,8 +54,6 @@ public class NavigationActivity extends AppCompatActivity implements DefaultHard
52 54
             }
53 55
         });
54 56
         host.getReactInstanceManager().createReactContextInBackground();
55
-
56
-
57 57
     }
58 58
 
59 59
     @Override
@@ -62,8 +62,27 @@ public class NavigationActivity extends AppCompatActivity implements DefaultHard
62 62
         host.getReactInstanceManager().onHostResume(this, this);
63 63
     }
64 64
 
65
+    @Override
66
+    protected void onPause() {
67
+        super.onPause();
68
+        host.getReactInstanceManager().onHostPause(this);
69
+    }
70
+
71
+    @Override
72
+    protected void onDestroy() {
73
+        super.onDestroy();
74
+        instance = null;
75
+        host.getReactInstanceManager().onHostDestroy(this);
76
+    }
77
+
65 78
     @Override
66 79
     public void invokeDefaultOnBackPressed() {
67 80
         onBackPressed();
68 81
     }
82
+
83
+    public void setRoot(String name, Bundle args) {
84
+        ReactRootView v = new ReactRootView(getApplicationContext());
85
+        setContentView(v);
86
+        v.startReactApplication(host.getReactInstanceManager(), name, args);
87
+    }
69 88
 }

+ 12
- 0
android/app/src/main/java/com/reactnativenavigation/layout/Layout.java View File

@@ -0,0 +1,12 @@
1
+package com.reactnativenavigation.layout;
2
+
3
+import android.content.Context;
4
+import android.graphics.Color;
5
+import android.widget.FrameLayout;
6
+
7
+public class Layout extends FrameLayout {
8
+    public Layout(Context context) {
9
+        super(context);
10
+        setBackgroundColor(Color.RED);
11
+    }
12
+}

+ 12
- 2
android/app/src/main/java/com/reactnativenavigation/react/NavigationModule.java View File

@@ -1,9 +1,12 @@
1 1
 package com.reactnativenavigation.react;
2 2
 
3
+import android.os.Bundle;
4
+
3 5
 import com.facebook.react.bridge.ReactApplicationContext;
4 6
 import com.facebook.react.bridge.ReactContextBaseJavaModule;
5 7
 import com.facebook.react.bridge.ReactMethod;
6 8
 import com.facebook.react.bridge.ReadableMap;
9
+import com.reactnativenavigation.controllers.NavigationActivity;
7 10
 
8 11
 public class NavigationModule extends ReactContextBaseJavaModule {
9 12
     public static final String NAME = "RNNBridgeModule";
@@ -18,7 +21,14 @@ public class NavigationModule extends ReactContextBaseJavaModule {
18 21
     }
19 22
 
20 23
     @ReactMethod
21
-    public void setRoot(ReadableMap layoutTree) {
22
-        
24
+    public void setRoot(final ReadableMap layoutTree) {
25
+        NavigationActivity.instance.runOnUiThread(new Runnable() {
26
+            @Override
27
+            public void run() {
28
+                Bundle args = new Bundle();
29
+                args.putString("id", layoutTree.getArray("children").getMap(0).getString("id"));
30
+                NavigationActivity.instance.setRoot(layoutTree.getArray("children").getMap(0).getMap("data").getString("name"), args);
31
+            }
32
+        });
23 33
     }
24 34
 }

+ 11
- 0
android/app/src/main/res/layout/new_root.xml View File

@@ -0,0 +1,11 @@
1
+<?xml version="1.0" encoding="utf-8"?>
2
+<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
3
+              android:layout_width="match_parent"
4
+              android:layout_height="match_parent"
5
+              android:orientation="vertical">
6
+    <TextView
7
+        android:layout_width="wrap_content"
8
+        android:layout_height="wrap_content"
9
+        android:layout_centerInParent="true"
10
+        android:text="new root :)"/>
11
+</RelativeLayout>

+ 1
- 0
src/adapters/NativeCommandsSender.js View File

@@ -6,6 +6,7 @@ export default class NativeCommandsSender {
6 6
   }
7 7
 
8 8
   setRoot(layoutTree) {
9
+    console.log(layoutTree);
9 10
     this.nativeCommandsModule.setRoot(layoutTree);
10 11
     return Promise.resolve(layoutTree);
11 12
   }

+ 2
- 0
src/commands/AppCommands.js View File

@@ -8,9 +8,11 @@ export default class AppCommands {
8 8
   }
9 9
 
10 10
   setRoot(simpleApi) {
11
+    console.log('AppCommands', 'setRoot');
11 12
     const input = _.cloneDeep(simpleApi);
12 13
     const layout = this.layoutTreeParser.parseFromSimpleJSON(input);
13 14
     this.layoutTreeCrawler.crawl(layout);
15
+    console.log('layout: ', JSON.stringify(layout));
14 16
     return this.nativeCommandsSender.setRoot(layout);
15 17
   }
16 18
 }