Browse Source

Don't register App in AppRegistry.

Guy Carmeli 8 years ago
parent
commit
9443f231e4

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

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

android/app/src/main/java/com/reactnativenavigation/activities/RctActivity.java → android/app/src/main/java/com/reactnativenavigation/activities/RootActivity.java View File

@@ -1,42 +1,23 @@
1 1
 package com.reactnativenavigation.activities;
2 2
 
3
-import android.content.Intent;
4
-import android.os.Bundle;
5
-
3
+import com.facebook.react.BuildConfig;
6 4
 import com.facebook.react.ReactInstanceManager;
7 5
 import com.facebook.react.ReactRootView;
8 6
 import com.reactnativenavigation.R;
9 7
 import com.reactnativenavigation.core.RctManager;
10 8
 
11 9
 /**
12
- *
13
- * Created by guyc on 10/03/16.
10
+ * Created by guyc on 13/04/16.
14 11
  */
15
-public class RctActivity extends BaseReactActivity {
16
-    public static final String EXTRA_COMPONENT_NAME = "componentName";
17
-    private static final String TAG = "RctActivity";
18
-
19
-    private String mComponentName = "";
20
-
21
-    public void setComponentName(String componentName) {
22
-        mComponentName = componentName;
23
-    }
24
-
25
-    @Override
26
-    public void onCreate(Bundle savedInstanceState) {
27
-        if (mComponentName == null) {
28
-            Intent intent = getIntent();
29
-            assert intent != null;
30
-            mComponentName = intent.getStringExtra(EXTRA_COMPONENT_NAME);
31
-            assert mComponentName != null;
32
-        }
33
-
34
-        super.onCreate(savedInstanceState);
35
-    }
12
+public class RootActivity extends BaseReactActivity {
36 13
 
14
+    /**
15
+     * Returns the name of the main component registered from JavaScript.
16
+     * This is used to schedule rendering of the component.
17
+     */
37 18
     @Override
38 19
     protected String getMainComponentName() {
39
-        return mComponentName;
20
+        return "RootComponent";
40 21
     }
41 22
 
42 23
     @Override
@@ -52,7 +33,7 @@ public class RctActivity extends BaseReactActivity {
52 33
      */
53 34
     @Override
54 35
     protected boolean getUseDeveloperSupport() {
55
-        return false;
36
+        return BuildConfig.DEBUG;
56 37
     }
57 38
 
58 39
     @Override
@@ -63,8 +44,14 @@ public class RctActivity extends BaseReactActivity {
63 44
     protected ReactInstanceManager getReactInstanceManager() {
64 45
         RctManager rctManager = RctManager.getInstance();
65 46
         if (!rctManager.isInitialized()) {
66
-            rctManager.init(this, mComponentName, getPackages());
47
+            rctManager.init(this, getMainComponentName(), getPackages());
67 48
         }
68 49
         return rctManager.getReactInstanceManager();
69 50
     }
51
+
52
+    @Override
53
+    protected void onPause() {
54
+        super.onPause();
55
+        finish();
56
+    }
70 57
 }

+ 0
- 14
android/app/src/main/java/com/reactnativenavigation/activities/SingleScreenActivity.java View File

@@ -1,8 +1,6 @@
1 1
 package com.reactnativenavigation.activities;
2 2
 
3
-import android.os.Bundle;
4 3
 import android.support.v7.widget.Toolbar;
5
-import android.util.Log;
6 4
 import android.view.View;
7 5
 import android.widget.FrameLayout;
8 6
 
@@ -21,12 +19,6 @@ public class SingleScreenActivity extends BaseReactActivity {
21 19
     private Toolbar mToolbar;
22 20
     private FrameLayout mContentFrame;
23 21
 
24
-    @Override
25
-    protected void onCreate(Bundle savedInstanceState) {
26
-        super.onCreate(savedInstanceState);
27
-        Log.i("GUY", "onCreate SingleScreenActivity");
28
-    }
29
-
30 22
     @Override
31 23
     protected void handleOnCreate() {
32 24
         mReactInstanceManager = RctManager.getInstance().getReactInstanceManager();
@@ -48,10 +40,4 @@ public class SingleScreenActivity extends BaseReactActivity {
48 40
         View view = new RctView(this, mReactInstanceManager, screen);
49 41
         mContentFrame.addView(view);
50 42
     }
51
-
52
-    @Override
53
-    protected void onResume() {
54
-        super.onResume();
55
-        Log.i("GUY", "onResume SingleScreenActivity");
56
-    }
57 43
 }

+ 0
- 14
android/app/src/main/java/com/reactnativenavigation/activities/TabActivity.java View File

@@ -1,9 +1,7 @@
1 1
 package com.reactnativenavigation.activities;
2 2
 
3
-import android.os.Bundle;
4 3
 import android.support.design.widget.TabLayout;
5 4
 import android.support.v4.view.ViewPager;
6
-import android.util.Log;
7 5
 import android.view.Menu;
8 6
 
9 7
 import com.reactnativenavigation.R;
@@ -26,12 +24,6 @@ public class TabActivity extends BaseReactActivity {
26 24
 
27 25
     private ArrayList<Screen> mScreens;
28 26
 
29
-    @Override
30
-    protected void onCreate(Bundle savedInstanceState) {
31
-        super.onCreate(savedInstanceState);
32
-        Log.d("GUY", "onCreate TabActivity");
33
-    }
34
-
35 27
     @Override
36 28
     protected void handleOnCreate() {
37 29
         mReactInstanceManager = RctManager.getInstance().getReactInstanceManager();
@@ -60,12 +52,6 @@ public class TabActivity extends BaseReactActivity {
60 52
         adapter.notifyDataSetChanged();
61 53
     }
62 54
 
63
-    @Override
64
-    protected void onResume() {
65
-        super.onResume();
66
-        Log.d("GUY", "onResume TabActivity");
67
-    }
68
-
69 55
     @Override
70 56
     public boolean onCreateOptionsMenu(Menu menu) {
71 57
         boolean ret = super.onCreateOptionsMenu(menu);

+ 0
- 11
android/app/src/main/java/com/reactnativenavigation/modules/RctActivityModule.java View File

@@ -9,7 +9,6 @@ import com.facebook.react.bridge.ReactContextBaseJavaModule;
9 9
 import com.facebook.react.bridge.ReactMethod;
10 10
 import com.facebook.react.bridge.ReadableArray;
11 11
 import com.facebook.react.bridge.ReadableMap;
12
-import com.reactnativenavigation.activities.RctActivity;
13 12
 import com.reactnativenavigation.activities.SingleScreenActivity;
14 13
 import com.reactnativenavigation.activities.TabActivity;
15 14
 import com.reactnativenavigation.core.objects.Screen;
@@ -32,16 +31,6 @@ public class RctActivityModule extends ReactContextBaseJavaModule {
32 31
         return REACT_CLASS;
33 32
     }
34 33
 
35
-    @ReactMethod
36
-    public void startActivity(String componentName) {
37
-        Activity context = ContextProvider.getActivityContext();
38
-        if (context != null && !context.isFinishing()) {
39
-            Intent rctActivityIntent = new Intent(context, RctActivity.class);
40
-            rctActivityIntent.putExtra(RctActivity.EXTRA_COMPONENT_NAME, componentName);
41
-            context.startActivity(rctActivityIntent);
42
-        }
43
-    }
44
-
45 34
     @ReactMethod
46 35
     public void startTabBasedApp(ReadableArray screens) {
47 36
         Activity context = ContextProvider.getActivityContext();

+ 0
- 37
android/app/src/main/java/com/reactnativenavigation/modules/RctLayoutManager.java View File

@@ -1,37 +0,0 @@
1
-package com.reactnativenavigation.modules;
2
-
3
-import android.app.Activity;
4
-import android.content.Intent;
5
-
6
-import com.facebook.react.bridge.ReactApplicationContext;
7
-import com.facebook.react.bridge.ReactContextBaseJavaModule;
8
-import com.facebook.react.bridge.ReactMethod;
9
-import com.reactnativenavigation.activities.RctActivity;
10
-import com.reactnativenavigation.utils.ContextProvider;
11
-
12
-/**
13
- * Created by guyc on 20/03/16.
14
- */
15
-@Deprecated
16
-public class RctLayoutManager extends ReactContextBaseJavaModule {
17
-    public static final String REACT_CLASS = "RctLayoutManager";
18
-
19
-    public RctLayoutManager(ReactApplicationContext reactContext) {
20
-        super(reactContext);
21
-    }
22
-
23
-    @Override
24
-    public String getName() {
25
-        return REACT_CLASS;
26
-    }
27
-
28
-    @ReactMethod
29
-    public void setLayout(String componentName) {
30
-        Activity context = ContextProvider.getActivityContext();
31
-        if (context != null && !context.isFinishing()) {
32
-            Intent rctActivityIntent = new Intent(context, RctActivity.class);
33
-            rctActivityIntent.putExtra(RctActivity.EXTRA_COMPONENT_NAME, componentName);
34
-            context.startActivity(rctActivityIntent);
35
-        }
36
-    }
37
-}

+ 2
- 16
example-redux/android/app/src/main/java/com/exampleredux/MainActivity.java View File

@@ -1,21 +1,7 @@
1 1
 package com.exampleredux;
2 2
 
3
-import com.reactnativenavigation.activities.RctActivity;
3
+import com.reactnativenavigation.activities.RootActivity;
4 4
 
5
-public class MainActivity extends RctActivity {
5
+public class MainActivity extends RootActivity {
6 6
 
7
-    /**
8
-     * Returns the name of the main component registered from JavaScript.
9
-     * This is used to schedule rendering of the component.
10
-     */
11
-    @Override
12
-    protected String getMainComponentName() {
13
-        return "ExampleRedux";
14
-    }
15
-
16
-    @Override
17
-    protected void onPause() {
18
-        super.onPause();
19
-        finish();
20
-    }
21 7
 }

+ 5
- 23
example-redux/src/app.js View File

@@ -1,7 +1,3 @@
1
-import React, {
2
-  AppRegistry,
3
-  Component
4
-} from 'react-native';
5 1
 import { createStore, applyMiddleware, combineReducers } from 'redux';
6 2
 import { Provider } from 'react-redux';
7 3
 import { Navigation } from 'react-native-navigation';
@@ -18,29 +14,16 @@ const store = createStoreWithMiddleware(reducer);
18 14
 import { registerScreens } from './screens';
19 15
 registerScreens(store, Provider);
20 16
 
21
-AppRegistry.registerComponent('ExampleRedux', () => App);
22
-
23 17
 // notice that this is just a simple class, it's not a React component
24
-export default class App extends React.Component {
25
-  constructor(props) {
26
-    super(props);
27
-    console.log('constructor ' + App.created);
28
-    if (!App.created) {
29
-      console.log('store.subscribe');
30
-      // since react-redux only works on components, we need to subscribe this class manually
31
-      store.subscribe(this.onStoreUpdate.bind(this));
32
-      store.dispatch(appActions.appInitialized());
33
-    }
34
-    App.created = true;
35
-  }
36
-
37
-  render() {
38
-    return null;
18
+export default class App {
19
+  constructor() {
20
+    // since react-redux only works on components, we need to subscribe this class manually
21
+    store.subscribe(this.onStoreUpdate.bind(this));
22
+    store.dispatch(appActions.appInitialized());
39 23
   }
40 24
 
41 25
   onStoreUpdate() {
42 26
     const { root } = store.getState().app;
43
-    console.log('onStoreUpdate ' + root + ' currentRoot ' + this.currentRoot);
44 27
     // handle a root change
45 28
     // if your app doesn't change roots in runtime, you can remove onStoreUpdate() altogether
46 29
     if (this.currentRoot != root) {
@@ -50,7 +33,6 @@ export default class App extends React.Component {
50 33
   }
51 34
 
52 35
   startApp(root) {
53
-    console.log('startApp ' + root);
54 36
     switch (root) {
55 37
       case 'login':
56 38
         Navigation.startSingleScreenApp({

+ 17
- 0
src/platformSpecific.android.js View File

@@ -1,3 +1,8 @@
1
+import React, {
2
+  AppRegistry,
3
+  Component
4
+} from 'react-native';
5
+
1 6
 import Navigation from './Navigation';
2 7
 import utils from './utils';
3 8
 
@@ -7,6 +12,18 @@ import {
7 12
 
8 13
 var resolveAssetSource = require('resolveAssetSource');
9 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
+
10 27
 function startSingleScreenApp(params) {
11 28
   let screen = params.screen;
12 29
   if (!screen.screen) {