|
@@ -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
|
}
|