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

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

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
 import com.facebook.react.ReactInstanceManager;
6
 import com.facebook.react.ReactInstanceManager;
7
 import com.facebook.react.ReactNativeHost;
7
 import com.facebook.react.ReactNativeHost;
8
 import com.facebook.react.ReactPackage;
8
 import com.facebook.react.ReactPackage;
9
+import com.facebook.react.ReactRootView;
9
 import com.facebook.react.bridge.ReactContext;
10
 import com.facebook.react.bridge.ReactContext;
10
 import com.facebook.react.modules.core.DefaultHardwareBackBtnHandler;
11
 import com.facebook.react.modules.core.DefaultHardwareBackBtnHandler;
11
 import com.facebook.react.shell.MainReactPackage;
12
 import com.facebook.react.shell.MainReactPackage;
18
 import java.util.List;
19
 import java.util.List;
19
 
20
 
20
 public class NavigationActivity extends AppCompatActivity implements DefaultHardwareBackBtnHandler {
21
 public class NavigationActivity extends AppCompatActivity implements DefaultHardwareBackBtnHandler {
21
-
22
+    public static NavigationActivity instance;
22
     private ReactNativeHost host;
23
     private ReactNativeHost host;
23
 
24
 
24
     @Override
25
     @Override
25
     public void onCreate(Bundle savedInstanceState) {
26
     public void onCreate(Bundle savedInstanceState) {
26
         super.onCreate(savedInstanceState);
27
         super.onCreate(savedInstanceState);
28
+        instance = this;
27
         setContentView(R.layout.splash);
29
         setContentView(R.layout.splash);
28
         host = new ReactNativeHost(getApplication()) {
30
         host = new ReactNativeHost(getApplication()) {
29
             @Override
31
             @Override
52
             }
54
             }
53
         });
55
         });
54
         host.getReactInstanceManager().createReactContextInBackground();
56
         host.getReactInstanceManager().createReactContextInBackground();
55
-
56
-
57
     }
57
     }
58
 
58
 
59
     @Override
59
     @Override
62
         host.getReactInstanceManager().onHostResume(this, this);
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
     @Override
78
     @Override
66
     public void invokeDefaultOnBackPressed() {
79
     public void invokeDefaultOnBackPressed() {
67
         onBackPressed();
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

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
 package com.reactnativenavigation.react;
1
 package com.reactnativenavigation.react;
2
 
2
 
3
+import android.os.Bundle;
4
+
3
 import com.facebook.react.bridge.ReactApplicationContext;
5
 import com.facebook.react.bridge.ReactApplicationContext;
4
 import com.facebook.react.bridge.ReactContextBaseJavaModule;
6
 import com.facebook.react.bridge.ReactContextBaseJavaModule;
5
 import com.facebook.react.bridge.ReactMethod;
7
 import com.facebook.react.bridge.ReactMethod;
6
 import com.facebook.react.bridge.ReadableMap;
8
 import com.facebook.react.bridge.ReadableMap;
9
+import com.reactnativenavigation.controllers.NavigationActivity;
7
 
10
 
8
 public class NavigationModule extends ReactContextBaseJavaModule {
11
 public class NavigationModule extends ReactContextBaseJavaModule {
9
     public static final String NAME = "RNNBridgeModule";
12
     public static final String NAME = "RNNBridgeModule";
18
     }
21
     }
19
 
22
 
20
     @ReactMethod
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

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
   }
7
 
7
 
8
   setRoot(layoutTree) {
8
   setRoot(layoutTree) {
9
+    console.log(layoutTree);
9
     this.nativeCommandsModule.setRoot(layoutTree);
10
     this.nativeCommandsModule.setRoot(layoutTree);
10
     return Promise.resolve(layoutTree);
11
     return Promise.resolve(layoutTree);
11
   }
12
   }

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

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