Daniel Zlotin 8 år sedan
förälder
incheckning
65fe5346ce

+ 1
- 0
android/app/src/main/java/com/reactnativenavigation/bridge/NavigationReactModule.java Visa fil

86
 
86
 
87
     @ReactMethod
87
     @ReactMethod
88
     public void newStack(final ReadableMap params) {
88
     public void newStack(final ReadableMap params) {
89
+        NavigationCommandsHandler.newStack(BundleConverter.toBundle(params));
89
     }
90
     }
90
 
91
 
91
     @ReactMethod
92
     @ReactMethod

+ 4
- 0
android/app/src/main/java/com/reactnativenavigation/controllers/NavigationActivity.java Visa fil

117
     void popToRoot(ScreenParams params) {
117
     void popToRoot(ScreenParams params) {
118
         layout.popToRoot(params);
118
         layout.popToRoot(params);
119
     }
119
     }
120
+
121
+    void newStack(ScreenParams params) {
122
+        layout.newStack(params);
123
+    }
120
 }
124
 }

+ 15
- 0
android/app/src/main/java/com/reactnativenavigation/controllers/NavigationCommandsHandler.java Visa fil

73
             }
73
             }
74
         });
74
         });
75
     }
75
     }
76
+
77
+    public static void newStack(Bundle screenParams) {
78
+        final NavigationActivity currentActivity = NavigationActivity.currentActivity;
79
+        if (currentActivity == null) {
80
+            return;
81
+        }
82
+
83
+        final ScreenParams params = ScreenParamsParser.parse(screenParams);
84
+        NavigationApplication.instance.runOnMainThread(new Runnable() {
85
+            @Override
86
+            public void run() {
87
+                currentActivity.newStack(params);
88
+            }
89
+        });
90
+    }
76
 }
91
 }

+ 2
- 0
android/app/src/main/java/com/reactnativenavigation/layouts/Layout.java Visa fil

14
     void pop(ScreenParams params);
14
     void pop(ScreenParams params);
15
 
15
 
16
     void popToRoot(ScreenParams params);
16
     void popToRoot(ScreenParams params);
17
+
18
+    void newStack(ScreenParams params);
17
 }
19
 }

+ 4
- 1
android/app/src/main/java/com/reactnativenavigation/layouts/Screen.java Visa fil

1
 package com.reactnativenavigation.layouts;
1
 package com.reactnativenavigation.layouts;
2
 
2
 
3
+/**
4
+ * Must extend View
5
+ */
3
 public interface Screen {
6
 public interface Screen {
4
-    void removeAllReactViews();
7
+    void ensureUnmountOnDetachedFromWindow();
5
 }
8
 }

+ 2
- 2
android/app/src/main/java/com/reactnativenavigation/layouts/ScreenImpl.java Visa fil

105
     }
105
     }
106
 
106
 
107
     @Override
107
     @Override
108
-    public void removeAllReactViews() {
109
-        contentView.removeFromParentAndUnmount();
108
+    public void ensureUnmountOnDetachedFromWindow() {
109
+        contentView.ensureUnmountOnDetachedFromWindow();
110
     }
110
     }
111
 }
111
 }

+ 2
- 3
android/app/src/main/java/com/reactnativenavigation/layouts/ScreenStack.java Visa fil

29
 
29
 
30
     public Screen pop() {
30
     public Screen pop() {
31
         Screen popped = stack.pop();
31
         Screen popped = stack.pop();
32
+        popped.ensureUnmountOnDetachedFromWindow();
32
         removeView((View) popped);
33
         removeView((View) popped);
33
         return popped;
34
         return popped;
34
     }
35
     }
41
 
42
 
42
     public void destroy() {
43
     public void destroy() {
43
         while (!isEmpty()) {
44
         while (!isEmpty()) {
44
-            Screen screen = pop();
45
-            screen.removeAllReactViews();
45
+            pop();
46
         }
46
         }
47
-        removeAllViews();
48
     }
47
     }
49
 
48
 
50
     public boolean isEmpty() {
49
     public boolean isEmpty() {

+ 5
- 0
android/app/src/main/java/com/reactnativenavigation/layouts/SingleScreenLayout.java Visa fil

60
     public void popToRoot(ScreenParams params) {
60
     public void popToRoot(ScreenParams params) {
61
         stack.popToRoot();
61
         stack.popToRoot();
62
     }
62
     }
63
+
64
+    @Override
65
+    public void newStack(ScreenParams params) {
66
+        stack.destroy();
67
+    }
63
 }
68
 }

+ 2
- 6
android/app/src/main/java/com/reactnativenavigation/views/ContentView.java Visa fil

2
 
2
 
3
 import android.content.Context;
3
 import android.content.Context;
4
 import android.os.Bundle;
4
 import android.os.Bundle;
5
-import android.view.ViewGroup;
6
 
5
 
7
 import com.facebook.react.ReactInstanceManager;
6
 import com.facebook.react.ReactInstanceManager;
8
 import com.facebook.react.ReactRootView;
7
 import com.facebook.react.ReactRootView;
38
         return navigationParams;
37
         return navigationParams;
39
     }
38
     }
40
 
39
 
41
-    public void removeFromParentWithoutUnmount() {
42
-        // Hack in order to prevent the react view from getting unmounted
40
+    public void preventUnmountOnDetachedFromWindow() {
43
         ReactViewHacks.preventUnmountOnDetachedFromWindow(this);
41
         ReactViewHacks.preventUnmountOnDetachedFromWindow(this);
44
-        ((ViewGroup) getParent()).removeView(this);
45
     }
42
     }
46
 
43
 
47
-    public void removeFromParentAndUnmount() {
44
+    public void ensureUnmountOnDetachedFromWindow() {
48
         ReactViewHacks.ensureUnmountOnDetachedFromWindow(this);
45
         ReactViewHacks.ensureUnmountOnDetachedFromWindow(this);
49
-        ((ViewGroup) getParent()).removeView(this);
50
     }
46
     }
51
 }
47
 }

+ 9
- 4
example-redux/src/screens/PushedScreen.js Visa fil

7
   StyleSheet,
7
   StyleSheet,
8
   TextInput
8
   TextInput
9
 } from 'react-native';
9
 } from 'react-native';
10
-import { connect } from 'react-redux';
10
+import {connect} from 'react-redux';
11
 import * as counterActions from '../reducers/counter/actions';
11
 import * as counterActions from '../reducers/counter/actions';
12
 
12
 
13
 // this is a traditional React component connected to the redux store
13
 // this is a traditional React component connected to the redux store
30
   constructor(props) {
30
   constructor(props) {
31
     super(props);
31
     super(props);
32
     this.bgColor = this.getRandomColor();
32
     this.bgColor = this.getRandomColor();
33
+    console.log(`constructor ${this.bgColor}`);
34
+  }
35
+
36
+  componentWillUnmount() {
37
+    console.log(`componentWillUnmount ${this.bgColor}`);
33
   }
38
   }
34
 
39
 
35
   getRandomColor() {
40
   getRandomColor() {
36
     var letters = '0123456789ABCDEF'.split('');
41
     var letters = '0123456789ABCDEF'.split('');
37
     var color = '#';
42
     var color = '#';
38
-    for (var i = 0; i < 6; i++ ) {
43
+    for (var i = 0; i < 6; i++) {
39
       color += letters[Math.floor(Math.random() * 16)];
44
       color += letters[Math.floor(Math.random() * 16)];
40
     }
45
     }
41
     return color;
46
     return color;
153
     textAlign: 'center',
158
     textAlign: 'center',
154
     fontSize: 18,
159
     fontSize: 18,
155
     marginBottom: 10,
160
     marginBottom: 10,
156
-    marginTop:10
161
+    marginTop: 10
157
   },
162
   },
158
   button: {
163
   button: {
159
     textAlign: 'center',
164
     textAlign: 'center',
160
     fontSize: 18,
165
     fontSize: 18,
161
     marginBottom: 10,
166
     marginBottom: 10,
162
-    marginTop:10,
167
+    marginTop: 10,
163
     color: 'blue'
168
     color: 'blue'
164
   }
169
   }
165
 });
170
 });