Daniel Zlotin 8 лет назад
Родитель
Сommit
3911e8cdc3

+ 8
- 8
android/app/src/main/java/com/reactnativenavigation/layouts/BottomTabsLayout.java Просмотреть файл

@@ -29,7 +29,7 @@ public class BottomTabsLayout extends RelativeLayout implements Layout, AHBottom
29 29
         super(activity);
30 30
         this.activity = activity;
31 31
         this.params = params;
32
-        screenStacks = new ScreenStack[(params.tabParams.size())];
32
+        screenStacks = new ScreenStack[params.tabParams.size()];
33 33
         createLayout();
34 34
     }
35 35
 
@@ -65,7 +65,7 @@ public class BottomTabsLayout extends RelativeLayout implements Layout, AHBottom
65 65
     }
66 66
 
67 67
     private void showInitialScreenStack() {
68
-        showStack(screenStacks[0]);
68
+        showStackAndUpdateStyle(screenStacks[0]);
69 69
     }
70 70
 
71 71
     @Override
@@ -86,28 +86,28 @@ public class BottomTabsLayout extends RelativeLayout implements Layout, AHBottom
86 86
     @Override
87 87
     public void setTopBarVisible(String screenInstanceId, boolean hidden, boolean animated) {
88 88
         for (int i = 0; i < bottomTabs.getItemsCount(); i++) {
89
-            screenStacks[i].setTopBarVisible(screenInstanceId, hidden, animated);
89
+            screenStacks[i].setScreenTopBarVisible(screenInstanceId, hidden, animated);
90 90
         }
91 91
     }
92 92
 
93 93
     @Override
94 94
     public void setTitleBarTitle(String screenInstanceId, String title) {
95 95
         for (int i = 0; i < bottomTabs.getItemsCount(); i++) {
96
-            screenStacks[i].setTitleBarTitle(screenInstanceId, title);
96
+            screenStacks[i].setScreenTitleBarTitle(screenInstanceId, title);
97 97
         }
98 98
     }
99 99
 
100 100
     @Override
101 101
     public void setTitleBarRightButtons(String screenInstanceId, String navigatorEventId, List<TitleBarButtonParams> titleBarButtons) {
102 102
         for (int i = 0; i < bottomTabs.getItemsCount(); i++) {
103
-            screenStacks[i].setTitleBarRightButtons(screenInstanceId, navigatorEventId, titleBarButtons);
103
+            screenStacks[i].setScreenTitleBarRightButtons(screenInstanceId, navigatorEventId, titleBarButtons);
104 104
         }
105 105
     }
106 106
 
107 107
     @Override
108 108
     public void setTitleBarLeftButton(String screenInstanceId, String navigatorEventId, TitleBarLeftButtonParams titleBarLeftButtonParams) {
109 109
         for (int i = 0; i < bottomTabs.getItemsCount(); i++) {
110
-            screenStacks[i].setTitleBarLeftButton(screenInstanceId, navigatorEventId, titleBarLeftButtonParams);
110
+            screenStacks[i].setScreenTitleBarLeftButton(screenInstanceId, navigatorEventId, titleBarLeftButtonParams);
111 111
         }
112 112
     }
113 113
 
@@ -149,13 +149,13 @@ public class BottomTabsLayout extends RelativeLayout implements Layout, AHBottom
149 149
         hideCurrentStack();
150 150
 
151 151
         ScreenStack newStack = screenStacks[position];
152
-        showStack(newStack);
152
+        showStackAndUpdateStyle(newStack);
153 153
         currentStackIndex = position;
154 154
 
155 155
         return true;
156 156
     }
157 157
 
158
-    private void showStack(ScreenStack newStack) {
158
+    private void showStackAndUpdateStyle(ScreenStack newStack) {
159 159
         newStack.setVisibility(VISIBLE);
160 160
         bottomTabs.setStyleFromScreen(newStack.getCurrentScreenStyleParams());
161 161
     }

+ 4
- 4
android/app/src/main/java/com/reactnativenavigation/layouts/SingleScreenLayout.java Просмотреть файл

@@ -72,12 +72,12 @@ public class SingleScreenLayout extends FrameLayout implements Layout {
72 72
 
73 73
     @Override
74 74
     public void setTopBarVisible(String screenInstanceID, boolean visible, boolean animate) {
75
-        stack.setTopBarVisible(screenInstanceID, visible, animate);
75
+        stack.setScreenTopBarVisible(screenInstanceID, visible, animate);
76 76
     }
77 77
 
78 78
     @Override
79 79
     public void setTitleBarTitle(String screenInstanceId, String title) {
80
-        stack.setTitleBarTitle(screenInstanceId, title);
80
+        stack.setScreenTitleBarTitle(screenInstanceId, title);
81 81
     }
82 82
 
83 83
     @Override
@@ -88,11 +88,11 @@ public class SingleScreenLayout extends FrameLayout implements Layout {
88 88
     @Override
89 89
     public void setTitleBarRightButtons(String screenInstanceId, String navigatorEventId,
90 90
                                         List<TitleBarButtonParams> titleBarRightButtons) {
91
-        stack.setTitleBarRightButtons(screenInstanceId, navigatorEventId, titleBarRightButtons);
91
+        stack.setScreenTitleBarRightButtons(screenInstanceId, navigatorEventId, titleBarRightButtons);
92 92
     }
93 93
 
94 94
     @Override
95 95
     public void setTitleBarLeftButton(String screenInstanceId, String navigatorEventId, TitleBarLeftButtonParams titleBarLeftButtonParams) {
96
-        stack.setTitleBarLeftButton(screenInstanceId, navigatorEventId, titleBarLeftButtonParams);
96
+        stack.setScreenTitleBarLeftButton(screenInstanceId, navigatorEventId, titleBarLeftButtonParams);
97 97
     }
98 98
 }

+ 39
- 48
android/app/src/main/java/com/reactnativenavigation/screens/ScreenStack.java Просмотреть файл

@@ -8,6 +8,7 @@ import com.reactnativenavigation.params.ScreenParams;
8 8
 import com.reactnativenavigation.params.ScreenStyleParams;
9 9
 import com.reactnativenavigation.params.TitleBarButtonParams;
10 10
 import com.reactnativenavigation.params.TitleBarLeftButtonParams;
11
+import com.reactnativenavigation.utils.Task;
11 12
 import com.reactnativenavigation.views.TitleBarBackButtonListener;
12 13
 
13 14
 import java.util.List;
@@ -17,6 +18,7 @@ import static android.view.ViewGroup.LayoutParams.MATCH_PARENT;
17 18
 
18 19
 // TODO there's really no reason for ScreenStack to extend FrameLayout. All screens can be added to parent.
19 20
 public class ScreenStack extends FrameLayout implements TitleBarBackButtonListener {
21
+
20 22
     private final AppCompatActivity activity;
21 23
     private Stack<Screen> stack = new Stack<>();
22 24
 
@@ -50,7 +52,7 @@ public class ScreenStack extends FrameLayout implements TitleBarBackButtonListen
50 52
 
51 53
     public void pop() {
52 54
         if (!canPop()) {
53
-            throw new RuntimeException("Can't pop ScreenStack of size " + getStackSize());
55
+            return;
54 56
         }
55 57
 
56 58
         Screen toRemove = stack.pop();
@@ -89,46 +91,40 @@ public class ScreenStack extends FrameLayout implements TitleBarBackButtonListen
89 91
         return getStackSize() > 1;
90 92
     }
91 93
 
92
-    public void setTopBarVisible(String screenInstanceId, boolean visible, boolean animate) {
93
-        Screen screen = findScreenByScreenInstanceId(screenInstanceId);
94
-        if (screen != null) {
95
-            screen.setTopBarVisible(visible, animate);
96
-        }
97
-    }
98
-
99
-    public Screen findScreenByScreenInstanceId(String screenInstanceId) {
100
-        if (stack.isEmpty()) {
101
-            return null;
102
-        }
103
-
104
-        for (Screen screen : stack) {
105
-            if (screen.getScreenInstanceId().equals(screenInstanceId)) {
106
-                return screen;
94
+    public void setScreenTopBarVisible(String screenInstanceId, final boolean visible, final boolean animate) {
95
+        performOnScreen(screenInstanceId, new Task<Screen>() {
96
+            @Override
97
+            public void run(Screen param) {
98
+                param.setTopBarVisible(visible, animate);
107 99
             }
108
-        }
109
-
110
-        return null;
100
+        });
111 101
     }
112 102
 
113
-    public void setTitleBarTitle(String screenInstanceId, String title) {
114
-        Screen screen = findScreenByScreenInstanceId(screenInstanceId);
115
-        if (screen != null) {
116
-            screen.setTitleBarTitle(title);
117
-        }
103
+    public void setScreenTitleBarTitle(String screenInstanceId, final String title) {
104
+        performOnScreen(screenInstanceId, new Task<Screen>() {
105
+            @Override
106
+            public void run(Screen param) {
107
+                param.setTitleBarTitle(title);
108
+            }
109
+        });
118 110
     }
119 111
 
120
-    public void setTitleBarRightButtons(String screenInstanceId, String navigatorEventId, List<TitleBarButtonParams> titleBarButtons) {
121
-        Screen screen = findScreenByScreenInstanceId(screenInstanceId);
122
-        if (screen != null) {
123
-            screen.setTitleBarRightButtons(navigatorEventId, titleBarButtons);
124
-        }
112
+    public void setScreenTitleBarRightButtons(String screenInstanceId, final String navigatorEventId, final List<TitleBarButtonParams> titleBarButtons) {
113
+        performOnScreen(screenInstanceId, new Task<Screen>() {
114
+            @Override
115
+            public void run(Screen param) {
116
+                param.setTitleBarRightButtons(navigatorEventId, titleBarButtons);
117
+            }
118
+        });
125 119
     }
126 120
 
127
-    public void setTitleBarLeftButton(String screenInstanceId, String navigatorEventId, TitleBarLeftButtonParams titleBarLeftButtonParams) {
128
-        Screen screen = findScreenByScreenInstanceId(screenInstanceId);
129
-        if (screen != null) {
130
-            screen.setTitleBarLeftButton(navigatorEventId, this, titleBarLeftButtonParams);
131
-        }
121
+    public void setScreenTitleBarLeftButton(String screenInstanceId, final String navigatorEventId, final TitleBarLeftButtonParams titleBarLeftButtonParams) {
122
+        performOnScreen(screenInstanceId, new Task<Screen>() {
123
+            @Override
124
+            public void run(Screen param) {
125
+                param.setTitleBarLeftButton(navigatorEventId, ScreenStack.this, titleBarLeftButtonParams);
126
+            }
127
+        });
132 128
     }
133 129
 
134 130
     @Override
@@ -138,25 +134,20 @@ public class ScreenStack extends FrameLayout implements TitleBarBackButtonListen
138 134
         }
139 135
     }
140 136
 
141
-    public void preventUnmountOnDetachedFromWindow() {
142
-        for (Screen screen : stack) {
143
-            screen.preventUnmountOnDetachedFromWindow();
144
-        }
137
+    public ScreenStyleParams getCurrentScreenStyleParams() {
138
+        return stack.peek().getStyleParams();
145 139
     }
146 140
 
147
-    public void ensureUnmountOnDetachedFromWindow() {
148
-        for (Screen screen : stack) {
149
-            screen.ensureUnmountOnDetachedFromWindow();
141
+    private void performOnScreen(String screenInstanceId, Task<Screen> task) {
142
+        if (stack.isEmpty()) {
143
+            return;
150 144
         }
151
-    }
152 145
 
153
-    public void preventMountAfterReatachedToWindow() {
154 146
         for (Screen screen : stack) {
155
-            screen.preventMountAfterReattachedToWindow();
147
+            if (screen.getScreenInstanceId().equals(screenInstanceId)) {
148
+                task.run(screen);
149
+                return;
150
+            }
156 151
         }
157 152
     }
158
-
159
-    public ScreenStyleParams getCurrentScreenStyleParams() {
160
-        return stack.peek().getStyleParams();
161
-    }
162 153
 }

+ 5
- 0
android/app/src/main/java/com/reactnativenavigation/utils/Task.java Просмотреть файл

@@ -0,0 +1,5 @@
1
+package com.reactnativenavigation.utils;
2
+
3
+public interface Task<T> {
4
+    void run(T param);
5
+}

+ 47
- 1
example-redux/src/app.js Просмотреть файл

@@ -35,10 +35,56 @@ export default class App {
35 35
   startApp(root) {
36 36
     switch (root) {
37 37
       case 'login':
38
+        //Navigation.startSingleScreenApp({
39
+        //  screen: {
40
+        //    screen: 'example.LoginScreen',
41
+        //    title: 'Login',
42
+        //    navigatorStyle: {}
43
+        //  },
44
+        //  passProps: {
45
+        //    str: 'This is a prop passed in \'startSingleScreenApp()\'!',
46
+        //    obj: {
47
+        //      str: 'This is a prop passed in an object!',
48
+        //      arr: [
49
+        //        {
50
+        //          str: 'This is a prop in an object in an array in an object!'
51
+        //        }
52
+        //      ],
53
+        //      arr2: [
54
+        //        [
55
+        //          'array of strings',
56
+        //          'with two strings'
57
+        //        ],
58
+        //        [
59
+        //          1, 2, 3
60
+        //        ]
61
+        //      ]
62
+        //    },
63
+        //    num: 1234
64
+        //  }
65
+        //});
38 66
         Navigation.startSingleScreenApp({
39 67
           screen: {
40
-            screen: 'example.LoginScreen',
68
+            screen: 'example.FirstTabScreen',
41 69
             title: 'Login',
70
+            topTabs: [
71
+              {
72
+                screenId: 'example.ListScreen',
73
+                title: 'Tab1'
74
+              },
75
+              {
76
+                screenId: 'example.PushedScreen',
77
+                title: 'Tab2'
78
+              },
79
+              {
80
+                screenId: 'example.PushedScreen',
81
+                title: 'Tab3'
82
+              },
83
+              {
84
+                screenId: 'example.FirstTabScreen',
85
+                title: 'Tab4'
86
+              }
87
+            ],
42 88
             navigatorStyle: {}
43 89
           },
44 90
           passProps: {

+ 6
- 7
example-redux/src/screens/PushedScreen.js Просмотреть файл

@@ -25,11 +25,10 @@ class PushedScreen extends Component {
25 25
   };
26 26
 
27 27
   static navigatorButtons = {
28
-    leftButton:
29
-      {
30
-        id: 'back',
31
-        color: '#00ff00'
32
-      }
28
+    leftButton: {
29
+      id: 'back',
30
+      color: '#00ff00'
31
+    }
33 32
   };
34 33
 
35 34
   constructor(props) {
@@ -127,8 +126,8 @@ class PushedScreen extends Component {
127 126
 
128 127
   onPushPress() {
129 128
     this.props.navigator.push({
130
-      title: "More",
131
-      screen: "example.PushedScreen",
129
+      title: "List",
130
+      screen: "example.ListScreen",
132 131
       passProps: {
133 132
         passed: 'This is a prop passed in \'navigator.push()\'!',
134 133
         obj: {