Browse Source

logs for debugging double activity bug

Guy Carmeli 9 years ago
parent
commit
02e89d947c

+ 1
- 2
android/app/src/main/java/com/reactnativenavigation/activities/BaseReactActivity.java View File

10
 import android.util.Log;
10
 import android.util.Log;
11
 import android.view.KeyEvent;
11
 import android.view.KeyEvent;
12
 import android.view.Menu;
12
 import android.view.Menu;
13
-import android.view.MenuItem;
14
 import android.widget.EditText;
13
 import android.widget.EditText;
15
 import android.widget.Toast;
14
 import android.widget.Toast;
16
 
15
 
140
     protected ReactInstanceManager getReactInstanceManager() {
139
     protected ReactInstanceManager getReactInstanceManager() {
141
         RctManager rctManager = RctManager.getInstance();
140
         RctManager rctManager = RctManager.getInstance();
142
         if (!rctManager.isInitialized()) {
141
         if (!rctManager.isInitialized()) {
143
-            rctManager.init(this, getMainComponentName(), getPackages());
142
+            rctManager.init(getApplicationContext(), getMainComponentName(), getPackages());
144
         }
143
         }
145
         return rctManager.getReactInstanceManager();
144
         return rctManager.getReactInstanceManager();
146
     }
145
     }

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

1
 package com.reactnativenavigation.activities;
1
 package com.reactnativenavigation.activities;
2
 
2
 
3
+import android.os.Bundle;
3
 import android.support.v7.widget.Toolbar;
4
 import android.support.v7.widget.Toolbar;
5
+import android.util.Log;
4
 import android.view.View;
6
 import android.view.View;
5
 import android.widget.FrameLayout;
7
 import android.widget.FrameLayout;
6
 
8
 
19
     private Toolbar mToolbar;
21
     private Toolbar mToolbar;
20
     private FrameLayout mContentFrame;
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
     @Override
30
     @Override
23
     protected void handleOnCreate() {
31
     protected void handleOnCreate() {
24
         mReactInstanceManager = RctManager.getInstance().getReactInstanceManager();
32
         mReactInstanceManager = RctManager.getInstance().getReactInstanceManager();
40
         View view = new RctView(this, mReactInstanceManager, screen);
48
         View view = new RctView(this, mReactInstanceManager, screen);
41
         mContentFrame.addView(view);
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 View File

1
 package com.reactnativenavigation.activities;
1
 package com.reactnativenavigation.activities;
2
 
2
 
3
+import android.os.Bundle;
3
 import android.support.design.widget.TabLayout;
4
 import android.support.design.widget.TabLayout;
4
 import android.support.v4.view.ViewPager;
5
 import android.support.v4.view.ViewPager;
6
+import android.util.Log;
5
 import android.view.Menu;
7
 import android.view.Menu;
6
 
8
 
7
 import com.reactnativenavigation.R;
9
 import com.reactnativenavigation.R;
24
 
26
 
25
     private ArrayList<Screen> mScreens;
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
     @Override
35
     @Override
28
     protected void handleOnCreate() {
36
     protected void handleOnCreate() {
29
         mReactInstanceManager = RctManager.getInstance().getReactInstanceManager();
37
         mReactInstanceManager = RctManager.getInstance().getReactInstanceManager();
52
         adapter.notifyDataSetChanged();
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
     @Override
69
     @Override
56
     public boolean onCreateOptionsMenu(Menu menu) {
70
     public boolean onCreateOptionsMenu(Menu menu) {
57
         boolean ret = super.onCreateOptionsMenu(menu);
71
         boolean ret = super.onCreateOptionsMenu(menu);

+ 0
- 2
android/app/src/main/java/com/reactnativenavigation/views/RctView.java View File

29
         root.startReactApplication(rctInstanceManager, componentName, passProps);
29
         root.startReactApplication(rctInstanceManager, componentName, passProps);
30
 
30
 
31
         addView(root);
31
         addView(root);
32
-
33
-        rctInstanceManager.onResume(ctx, ctx);
34
     }
32
     }
35
 }
33
 }
36
 
34
 

+ 15
- 8
example-redux/src/app.js View File

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

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

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