Selaa lähdekoodia

logs for debugging double activity bug

Guy Carmeli 9 vuotta sitten
vanhempi
commit
02e89d947c

+ 1
- 2
android/app/src/main/java/com/reactnativenavigation/activities/BaseReactActivity.java Näytä tiedosto

@@ -10,7 +10,6 @@ import android.support.v7.app.AppCompatActivity;
10 10
 import android.util.Log;
11 11
 import android.view.KeyEvent;
12 12
 import android.view.Menu;
13
-import android.view.MenuItem;
14 13
 import android.widget.EditText;
15 14
 import android.widget.Toast;
16 15
 
@@ -140,7 +139,7 @@ public class BaseReactActivity extends AppCompatActivity implements DefaultHardw
140 139
     protected ReactInstanceManager getReactInstanceManager() {
141 140
         RctManager rctManager = RctManager.getInstance();
142 141
         if (!rctManager.isInitialized()) {
143
-            rctManager.init(this, getMainComponentName(), getPackages());
142
+            rctManager.init(getApplicationContext(), getMainComponentName(), getPackages());
144 143
         }
145 144
         return rctManager.getReactInstanceManager();
146 145
     }

+ 14
- 0
android/app/src/main/java/com/reactnativenavigation/activities/SingleScreenActivity.java Näytä tiedosto

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

+ 14
- 0
android/app/src/main/java/com/reactnativenavigation/activities/TabActivity.java Näytä tiedosto

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

+ 0
- 2
android/app/src/main/java/com/reactnativenavigation/views/RctView.java Näytä tiedosto

@@ -29,8 +29,6 @@ public class RctView extends FrameLayout {
29 29
         root.startReactApplication(rctInstanceManager, componentName, passProps);
30 30
 
31 31
         addView(root);
32
-
33
-        rctInstanceManager.onResume(ctx, ctx);
34 32
     }
35 33
 }
36 34
 

+ 15
- 8
example-redux/src/app.js Näytä tiedosto

@@ -1,7 +1,6 @@
1 1
 import React, {
2 2
   AppRegistry,
3
-  Component,
4
-  View
3
+  Component
5 4
 } from 'react-native';
6 5
 import { createStore, applyMiddleware, combineReducers } from 'redux';
7 6
 import { Provider } from 'react-redux';
@@ -18,6 +17,7 @@ const store = createStoreWithMiddleware(reducer);
18 17
 // screen related book keeping
19 18
 import { registerScreens } from './screens';
20 19
 registerScreens(store, Provider);
20
+let unsubscribe;
21 21
 
22 22
 AppRegistry.registerComponent('ExampleRedux', () => App);
23 23
 
@@ -25,28 +25,34 @@ AppRegistry.registerComponent('ExampleRedux', () => App);
25 25
 export default class App extends React.Component {
26 26
   constructor(props) {
27 27
     super(props);
28
+    console.log('constructor');
28 29
     // since react-redux only works on components, we need to subscribe this class manually
29
-    store.subscribe(this.onStoreUpdate.bind(this));
30
+    unsubscribe = store.subscribe(this.onStoreUpdate.bind(this));
30 31
     store.dispatch(appActions.appInitialized());
31 32
   }
32 33
 
33 34
   render() {
34
-    return (
35
-      <View />
36
-    );
35
+    return null;
37 36
   }
38 37
 
39 38
   onStoreUpdate() {
40 39
     const { root } = store.getState().app;
40
+    console.log('onStoreUpdate ' + root + ' currentRoot ' + this.currentRoot);
41 41
     // handle a root change
42 42
     // if your app doesn't change roots in runtime, you can remove onStoreUpdate() altogether
43
-    if (this.currentRoot !== root) {
43
+    if (this.currentRoot != root) {
44 44
       this.currentRoot = root;
45 45
       this.startApp(root);
46
+    } else {
47
+      if (unsubscribe && this.currentRoot) {
48
+        console.log('unsubscribing ' + this.currentRoot);
49
+        unsubscribe();
50
+      }
46 51
     }
47 52
   }
48 53
 
49 54
   startApp(root) {
55
+    console.log('startApp ' + root);
50 56
     switch (root) {
51 57
       case 'login':
52 58
         Navigation.startSingleScreenApp({
@@ -77,7 +83,8 @@ export default class App extends React.Component {
77 83
               navigatorStyle: {}
78 84
             }
79 85
           ],
80
-          animationType: 'slide-down'
86
+          animationType: 'slide-down',
87
+          title: 'Redux Example'
81 88
         });
82 89
         return;
83 90
       default:

+ 0
- 1
src/platformSpecific.android.js Näytä tiedosto

@@ -54,7 +54,6 @@ function addNavigatorButtons(screen) {
54 54
     screen.rightButtons.forEach(function(button) {
55 55
       if (button.icon) {
56 56
         const icon = resolveAssetSource(button.icon);
57
-        console.log('This is an icon:\n' + JSON.stringify(icon));
58 57
         if (icon) {
59 58
           button.icon = icon.uri;
60 59
         }