Procházet zdrojové kódy

Stop using dummy component to trigger JS execution + RootActivity clean up

Guy Carmeli před 8 roky
rodič
revize
669682b5ba

+ 2
- 2
android/app/src/main/AndroidManifest.xml Zobrazit soubor

@@ -2,8 +2,8 @@
2 2
     package="com.reactnativenavigation">
3 3
 
4 4
     <application>
5
-      <activity android:name="com.reactnativenavigation.activities.TabActivity" />
6
-      <activity android:name="com.reactnativenavigation.activities.SingleScreenActivity" />
5
+        <activity android:name="com.reactnativenavigation.activities.TabActivity" />
6
+        <activity android:name="com.reactnativenavigation.activities.SingleScreenActivity" />
7 7
     </application>
8 8
 
9 9
 </manifest>

+ 11
- 43
android/app/src/main/java/com/reactnativenavigation/activities/RootActivity.java Zobrazit soubor

@@ -1,53 +1,22 @@
1 1
 package com.reactnativenavigation.activities;
2 2
 
3
-import com.facebook.react.BuildConfig;
4
-import com.facebook.react.ReactInstanceManager;
5 3
 import com.facebook.react.ReactRootView;
6
-import com.reactnativenavigation.R;
7
-import com.reactnativenavigation.core.RctManager;
8 4
 import com.reactnativenavigation.core.objects.Screen;
9 5
 
10 6
 /**
7
+ * This activity is used to start the JS execution where we load our actual app/screens (index.android.js)
8
+ * Triggering react context initialization execute global code before any {@link ReactRootView}
9
+ * are displayed.
10
+ * <p>Only your MainActivity or activities with {@code action.MAIN} and {@code category.LAUNCHER}
11
+ * should extend this activity.
11 12
  * Created by guyc on 13/04/16.
12 13
  */
13 14
 public class RootActivity extends BaseReactActivity {
14 15
 
15
-    /**
16
-     * Returns the name of the main component registered from JavaScript.
17
-     * This is used to schedule rendering of the component.
18
-     */
19 16
     @Override
20
-    protected String getMainComponentName() {
21
-        return "RootComponent";
22
-    }
23
-
24
-    @Override
25
-    protected ReactRootView createRootView() {
26
-        ReactRootView rootView = super.createRootView();
27
-        rootView.setId(R.id.react_root_view);
28
-        return rootView;
29
-    }
30
-
31
-    /**
32
-     * Returns whether dev mode should be enabled.
33
-     * This enables e.g. the dev menu.
34
-     */
35
-    @Override
36
-    protected boolean getUseDeveloperSupport() {
37
-        return BuildConfig.DEBUG;
38
-    }
39
-
40
-    @Override
41
-    protected ReactInstanceManager createReactInstanceManager() {
42
-        return getReactInstanceManager();
43
-    }
44
-
45
-    protected ReactInstanceManager getReactInstanceManager() {
46
-        RctManager rctManager = RctManager.getInstance();
47
-        if (!rctManager.isInitialized()) {
48
-            rctManager.init(this, getMainComponentName(), getPackages());
49
-        }
50
-        return rctManager.getReactInstanceManager();
17
+    protected void handleOnCreate() {
18
+        // Trigger react context initialization, global javascript code will now execute
19
+        getReactInstanceManager().createReactContextInBackground();
51 20
     }
52 21
 
53 22
     @Override
@@ -56,25 +25,24 @@ public class RootActivity extends BaseReactActivity {
56 25
         finish();
57 26
     }
58 27
 
28
+     // No need to implement stack interface since this activity is only used to start other
29
+    // activities such as TabActivity or SingleScreenActivity.
30
+    @Override
59 31
     public void push(Screen screen) {
60
-        //TODO
61 32
     }
62 33
 
63 34
     @Override
64 35
     public Screen pop(String navID) {
65 36
         return null;
66
-        //TODO
67 37
     }
68 38
 
69 39
     @Override
70 40
     public String getActiveNavigatorID() {
71 41
         return null;
72
-        //TODO
73 42
     }
74 43
 
75 44
     @Override
76 45
     public int getScreenStackSize() {
77 46
         return 0;
78
-        //TODO
79 47
     }
80 48
 }

+ 0
- 12
src/platformSpecific.android.js Zobrazit soubor

@@ -12,18 +12,6 @@ import {
12 12
 
13 13
 var resolveAssetSource = require('resolveAssetSource');
14 14
 
15
-AppRegistry.registerComponent('RootComponent', () => RootComponent);
16
-
17
-export default class RootComponent extends React.Component {
18
-  constructor(props) {
19
-    super(props);
20
-  }
21
-
22
-  render() {
23
-    return null;
24
-  }
25
-}
26
-
27 15
 function startSingleScreenApp(params) {
28 16
   let screen = params.screen;
29 17
   if (!screen.screen) {