Daniel Zlotin 8 yıl önce
ebeveyn
işleme
a109e51b45

+ 4
- 3
android/app/src/main/java/com/reactnativenavigation/layouts/Screen.java Dosyayı Görüntüle

@@ -1,8 +1,9 @@
1 1
 package com.reactnativenavigation.layouts;
2 2
 
3
-/**
4
- * Must extend View
5
- */
3
+import android.view.View;
4
+
6 5
 public interface Screen {
6
+    View asView();
7
+
7 8
     void ensureUnmountOnDetachedFromWindow();
8 9
 }

+ 6
- 0
android/app/src/main/java/com/reactnativenavigation/layouts/ScreenImpl.java Dosyayı Görüntüle

@@ -5,6 +5,7 @@ import android.app.Activity;
5 5
 import android.content.Context;
6 6
 import android.graphics.Color;
7 7
 import android.os.Build;
8
+import android.view.View;
8 9
 import android.view.Window;
9 10
 import android.widget.LinearLayout;
10 11
 
@@ -104,6 +105,11 @@ public class ScreenImpl extends LinearLayout implements Screen, ScrollDirectionL
104 105
         // TODO handle if needed
105 106
     }
106 107
 
108
+    @Override
109
+    public View asView() {
110
+        return this;
111
+    }
112
+
107 113
     @Override
108 114
     public void ensureUnmountOnDetachedFromWindow() {
109 115
         contentView.ensureUnmountOnDetachedFromWindow();

+ 2
- 3
android/app/src/main/java/com/reactnativenavigation/layouts/ScreenStack.java Dosyayı Görüntüle

@@ -2,7 +2,6 @@ package com.reactnativenavigation.layouts;
2 2
 
3 3
 import android.animation.LayoutTransition;
4 4
 import android.content.Context;
5
-import android.view.View;
6 5
 import android.widget.FrameLayout;
7 6
 
8 7
 import com.reactnativenavigation.params.ScreenParams;
@@ -23,14 +22,14 @@ public class ScreenStack extends FrameLayout {
23 22
 
24 23
     public void push(ScreenParams screenParams) {
25 24
         Screen screen = new ScreenImpl(getContext(), screenParams);
26
-        addView((View) screen, new FrameLayout.LayoutParams(MATCH_PARENT, MATCH_PARENT));
25
+        addView(screen.asView(), new FrameLayout.LayoutParams(MATCH_PARENT, MATCH_PARENT));
27 26
         stack.push(screen);
28 27
     }
29 28
 
30 29
     public Screen pop() {
31 30
         Screen popped = stack.pop();
32 31
         popped.ensureUnmountOnDetachedFromWindow();
33
-        removeView((View) popped);
32
+        removeView(popped.asView());
34 33
         return popped;
35 34
     }
36 35
 

+ 2
- 1
android/app/src/main/java/com/reactnativenavigation/layouts/SingleScreenLayout.java Dosyayı Görüntüle

@@ -21,6 +21,7 @@ public class SingleScreenLayout extends FrameLayout implements Layout {
21 21
     private void createStack(Context context) {
22 22
         if (stack != null) {
23 23
             stack.destroy();
24
+            removeView(stack);
24 25
         }
25 26
         stack = new ScreenStack(context, screenParams);
26 27
         addView(stack, new LayoutParams(MATCH_PARENT, MATCH_PARENT));
@@ -63,6 +64,6 @@ public class SingleScreenLayout extends FrameLayout implements Layout {
63 64
 
64 65
     @Override
65 66
     public void newStack(ScreenParams params) {
66
-        stack.destroy();
67
+        createStack(getContext());
67 68
     }
68 69
 }

+ 23
- 0
example-redux/src/screens/PushedScreen.js Dosyayı Görüntüle

@@ -83,6 +83,10 @@ class PushedScreen extends Component {
83 83
           <Text style={styles.button}>Pop to root</Text>
84 84
         </TouchableOpacity>
85 85
 
86
+        <TouchableOpacity onPress={ this.onNewStackPress.bind(this) }>
87
+          <Text style={styles.button}>New Stack</Text>
88
+        </TouchableOpacity>
89
+
86 90
         <TextInput style={{height: 40, borderColor: 'gray', borderWidth: 1}}/>
87 91
 
88 92
         <Text style={{fontWeight: '500'}}>String prop: {this.props.str}</Text>
@@ -151,6 +155,25 @@ class PushedScreen extends Component {
151 155
   onPopToRootPress() {
152 156
     this.props.navigator.popToRoot();
153 157
   }
158
+
159
+  onNewStackPress() {
160
+    this.props.navigator.resetTo({
161
+      title: "NEW STACK",
162
+      screen: "example.PushedScreen",
163
+      passProps: {
164
+        passed: 'This is a prop passed in \'navigator.push()\'!',
165
+        obj: {
166
+          str: 'This is a prop passed in an object!',
167
+          arr: [
168
+            {
169
+              str: 'This is a prop in an object in an array in an object!'
170
+            }
171
+          ]
172
+        },
173
+        num: 1234
174
+      }
175
+    });
176
+  }
154 177
 }
155 178
 
156 179
 const styles = StyleSheet.create({

+ 12
- 7
src/deprecated/platformSpecificDeprecated.android.js Dosyayı Görüntüle

@@ -64,6 +64,18 @@ function navigatorPopToRoot(navigator, params) {
64 64
   newPlatformSpecific.popToRoot(adapted);
65 65
 }
66 66
 
67
+function navigatorResetTo(navigator, params) {
68
+  addNavigatorParams(params, navigator);
69
+  addNavigatorButtons(params);
70
+  addNavigationStyleParams(params);
71
+
72
+  params.screenId = params.screen;
73
+  let adapted = adaptNavigationStyleToScreenStyle(params);
74
+  adapted = adaptNavigationParams(adapted);
75
+
76
+  newPlatformSpecific.newStack(adapted);
77
+}
78
+
67 79
 function adaptNavigationStyleToScreenStyle(screen) {
68 80
   const navigatorStyle = screen.navigatorStyle;
69 81
   if (!navigatorStyle) {
@@ -138,13 +150,6 @@ function navigatorSetButtons(navigator, navigatorEventID, params) {
138 150
   //RctActivity.setNavigatorButtons(params);
139 151
 }
140 152
 
141
-function navigatorResetTo(navigator, params) {
142
-  //addNavigatorParams(params, navigator);
143
-  //addNavigatorButtons(params);
144
-  //addNavigationStyleParams(params);
145
-  //RctActivity.navigatorResetTo(params);
146
-}
147
-
148 153
 function navigatorSetTabBadge(navigator, params) {
149 154
   //RctActivity.setTabBadge({
150 155
   //  tabIndex: params.tabIndex,

+ 6
- 1
src/platformSpecific.android.js Dosyayı Görüntüle

@@ -28,9 +28,14 @@ function popToRoot(screenParams) {
28 28
   NativeModules.NavigationReactModule.popToRoot(screenParams);
29 29
 }
30 30
 
31
+function newStack(screenParams) {
32
+  NativeModules.NavigationReactModule.newStack(screenParams);
33
+}
34
+
31 35
 module.exports = {
32 36
   startApp,
33 37
   push,
34 38
   pop,
35
-  popToRoot
39
+  popToRoot,
40
+  newStack
36 41
 };