|
@@ -4,7 +4,6 @@ import android.app.Activity;
|
4
|
4
|
import android.support.annotation.NonNull;
|
5
|
5
|
import android.support.annotation.RestrictTo;
|
6
|
6
|
import android.support.v4.view.ViewPager;
|
7
|
|
-import android.view.View;
|
8
|
7
|
|
9
|
8
|
import com.reactnativenavigation.anim.NavigationAnimator;
|
10
|
9
|
import com.reactnativenavigation.parse.Options;
|
|
@@ -128,8 +127,7 @@ public class StackController extends ParentController<StackLayout> {
|
128
|
127
|
while (stack.size() > 1) {
|
129
|
128
|
ViewController controller = stack.get(iterator.next());
|
130
|
129
|
if (!stack.isTop(controller.getId())) {
|
131
|
|
- stack.remove(controller.getId());
|
132
|
|
- controller.destroy();
|
|
130
|
+ removeAndDestroyController(controller);
|
133
|
131
|
}
|
134
|
132
|
}
|
135
|
133
|
}
|
|
@@ -140,53 +138,35 @@ public class StackController extends ParentController<StackLayout> {
|
140
|
138
|
return;
|
141
|
139
|
}
|
142
|
140
|
|
143
|
|
- final ViewController exitingController = stack.pop();
|
144
|
|
- final ViewController enteringController = stack.peek();
|
145
|
|
- popInternal(exitingController, enteringController);
|
146
|
|
-
|
147
|
|
- finishPopping(exitingController.getView(), exitingController, listener);
|
148
|
|
- }
|
149
|
|
-
|
150
|
|
- void animatePop(CommandListener listener) {
|
151
|
|
- if (!canPop()) {
|
152
|
|
- listener.onError("Nothing to pop");
|
153
|
|
- return;
|
154
|
|
- }
|
155
|
|
-
|
156
|
|
- final ViewController exitingController = stack.pop();
|
157
|
|
- final ViewController enteringController = stack.peek();
|
158
|
|
- popInternal(exitingController, enteringController);
|
159
|
|
-
|
160
|
|
- animator.animatePop(
|
161
|
|
- exitingController.getView(),
|
162
|
|
- () -> finishPopping(exitingController.getView(), exitingController, listener)
|
163
|
|
- );
|
164
|
|
- }
|
165
|
|
-
|
166
|
|
- private void popInternal(ViewController disappearing, ViewController appearing) {
|
|
141
|
+ final ViewController disappearing = stack.pop();
|
|
142
|
+ final ViewController appearing = stack.peek();
|
167
|
143
|
disappearing.onViewWillDisappear();
|
168
|
144
|
appearing.onViewWillAppear();
|
169
|
145
|
getView().onChildWillDisappear(disappearing.options, appearing.options, () ->
|
170
|
146
|
getView().addView(appearing.getView(), getView().indexOfChild(disappearing.getView()))
|
171
|
147
|
);
|
172
|
|
- }
|
173
|
148
|
|
174
|
|
- boolean canPop() {
|
175
|
|
- return stack.size() > 1;
|
|
149
|
+ if (disappearing.options.animated.isTrueOrUndefined()) {
|
|
150
|
+ animator.animatePop(
|
|
151
|
+ disappearing.getView(),
|
|
152
|
+ () -> finishPopping(disappearing, listener)
|
|
153
|
+ );
|
|
154
|
+ } else {
|
|
155
|
+ finishPopping(disappearing, listener);
|
|
156
|
+ }
|
176
|
157
|
}
|
177
|
158
|
|
178
|
|
- private void finishPopping(View exitingView, ViewController poppedTop, CommandListener listener) {
|
179
|
|
- getView().removeView(exitingView);
|
180
|
|
- poppedTop.destroy();
|
181
|
|
- listener.onSuccess(poppedTop.getId());
|
|
159
|
+ private void finishPopping(ViewController disappearing, CommandListener listener) {
|
|
160
|
+ getView().removeView(disappearing.getView());
|
|
161
|
+ disappearing.destroy();
|
|
162
|
+ listener.onSuccess(disappearing.getId());
|
182
|
163
|
}
|
183
|
164
|
|
184
|
|
- void popSpecific(final ViewController childController, CommandListener listener) {
|
|
165
|
+ void popSpecific(ViewController childController, CommandListener listener) {
|
185
|
166
|
if (stack.isTop(childController.getId())) {
|
186
|
|
- animatePop(listener);
|
|
167
|
+ pop(listener);
|
187
|
168
|
} else {
|
188
|
|
- stack.remove(childController.getId());
|
189
|
|
- childController.destroy();
|
|
169
|
+ removeAndDestroyController(childController);
|
190
|
170
|
listener.onSuccess(childController.getId());
|
191
|
171
|
}
|
192
|
172
|
}
|
|
@@ -203,9 +183,9 @@ public class StackController extends ParentController<StackLayout> {
|
203
|
183
|
String nextControlId = iterator.next();
|
204
|
184
|
boolean animate = nextControlId.equals(viewController.getId());
|
205
|
185
|
if (animate) {
|
206
|
|
- animatePop(listener);
|
|
186
|
+ pop(listener);
|
207
|
187
|
} else {
|
208
|
|
- pop(new CommandListenerAdapter());
|
|
188
|
+ removeAndDestroyController(stack.get(currentControlId));
|
209
|
189
|
}
|
210
|
190
|
currentControlId = nextControlId;
|
211
|
191
|
}
|
|
@@ -221,12 +201,16 @@ public class StackController extends ParentController<StackLayout> {
|
221
|
201
|
while (stack.size() > 2) {
|
222
|
202
|
ViewController controller = stack.get(iterator.next());
|
223
|
203
|
if (!stack.isTop(controller.getId())) {
|
224
|
|
- stack.remove(controller.getId());
|
225
|
|
- controller.destroy();
|
|
204
|
+ removeAndDestroyController(controller);
|
226
|
205
|
}
|
227
|
206
|
}
|
228
|
207
|
|
229
|
|
- animatePop(listener);
|
|
208
|
+ pop(listener);
|
|
209
|
+ }
|
|
210
|
+
|
|
211
|
+ private void removeAndDestroyController(ViewController controller) {
|
|
212
|
+ stack.remove(controller.getId());
|
|
213
|
+ controller.destroy();
|
230
|
214
|
}
|
231
|
215
|
|
232
|
216
|
ViewController peek() {
|
|
@@ -244,12 +228,16 @@ public class StackController extends ParentController<StackLayout> {
|
244
|
228
|
@Override
|
245
|
229
|
public boolean handleBack() {
|
246
|
230
|
if (canPop()) {
|
247
|
|
- animatePop(new CommandListenerAdapter());
|
|
231
|
+ pop(new CommandListenerAdapter());
|
248
|
232
|
return true;
|
249
|
233
|
}
|
250
|
234
|
return false;
|
251
|
235
|
}
|
252
|
236
|
|
|
237
|
+ boolean canPop() {
|
|
238
|
+ return stack.size() > 1;
|
|
239
|
+ }
|
|
240
|
+
|
253
|
241
|
@Override
|
254
|
242
|
public void sendOnNavigationButtonPressed(String buttonId) {
|
255
|
243
|
peek().sendOnNavigationButtonPressed(buttonId);
|