|
@@ -15,6 +15,7 @@ import com.reactnativenavigation.presentation.OverlayManager;
|
15
|
15
|
import com.reactnativenavigation.react.EventEmitter;
|
16
|
16
|
import com.reactnativenavigation.utils.CommandListener;
|
17
|
17
|
import com.reactnativenavigation.utils.CompatUtils;
|
|
18
|
+import com.reactnativenavigation.utils.Task;
|
18
|
19
|
import com.reactnativenavigation.viewcontrollers.modal.ModalStack;
|
19
|
20
|
import com.reactnativenavigation.viewcontrollers.stack.StackController;
|
20
|
21
|
import com.reactnativenavigation.views.element.ElementTransitionManager;
|
|
@@ -147,54 +148,28 @@ public class Navigator extends ParentController {
|
147
|
148
|
}
|
148
|
149
|
}
|
149
|
150
|
|
150
|
|
- public void push(final String fromId, final ViewController viewController, CommandListener listener) {
|
151
|
|
- ViewController from = findControllerById(fromId);
|
152
|
|
- if (from != null) {
|
153
|
|
- from.performOnParentStack(
|
154
|
|
- stack -> ((StackController) stack).push(viewController, listener),
|
155
|
|
- () -> rejectPush(fromId, viewController, listener)
|
156
|
|
- );
|
157
|
|
- } else {
|
158
|
|
- rejectPush(fromId, viewController, listener);
|
159
|
|
- }
|
|
151
|
+ public void push(final String id, final ViewController viewController, CommandListener listener) {
|
|
152
|
+ applyOnStack(id, listener, stack -> stack.push(viewController, listener));
|
160
|
153
|
}
|
161
|
154
|
|
162
|
|
- public void setStackRoot(String fromId, ViewController viewController, CommandListener listener) {
|
163
|
|
- ViewController from = findControllerById(fromId);
|
164
|
|
- if (from != null) {
|
165
|
|
- from.performOnParentStack(stack -> ((StackController) stack).setRoot(viewController, listener));
|
166
|
|
- }
|
167
|
|
- }
|
168
|
|
-
|
169
|
|
- public void pop(final String fromId, CommandListener listener) {
|
170
|
|
- ViewController from = findControllerById(fromId);
|
171
|
|
- if (from != null) {
|
172
|
|
- from.performOnParentStack(stack -> ((StackController) stack).pop(listener));
|
173
|
|
- }
|
|
155
|
+ public void setStackRoot(String id, ViewController viewController, CommandListener listener) {
|
|
156
|
+ applyOnStack(id, listener, stack -> stack.setRoot(viewController, listener));
|
174
|
157
|
}
|
175
|
158
|
|
176
|
|
- public void popSpecific(final String id, CommandListener listener) {
|
177
|
|
- ViewController from = findControllerById(id);
|
178
|
|
- if (from != null) {
|
179
|
|
- from.performOnParentStack(stack -> ((StackController) stack).popSpecific(from, listener), () -> listener.onError("Nothing to pop"));
|
180
|
|
- } else {
|
181
|
|
- listener.onError("Nothing to pop");
|
182
|
|
- }
|
|
159
|
+ public void pop(String id, CommandListener listener) {
|
|
160
|
+ applyOnStack(id, listener, stack -> stack.pop(listener));
|
183
|
161
|
}
|
184
|
162
|
|
185
|
163
|
public void popToRoot(final String id, CommandListener listener) {
|
186
|
|
- ViewController from = findControllerById(id);
|
187
|
|
- if (from != null) {
|
188
|
|
- from.performOnParentStack(stack -> ((StackController) stack).popToRoot(listener));
|
189
|
|
- }
|
|
164
|
+ applyOnStack(id, listener, stack -> stack.popToRoot(listener));
|
190
|
165
|
}
|
191
|
166
|
|
192
|
|
- public void popTo(final String componentId, CommandListener listener) {
|
193
|
|
- ViewController target = findControllerById(componentId);
|
|
167
|
+ public void popTo(final String id, CommandListener listener) {
|
|
168
|
+ ViewController target = findControllerById(id);
|
194
|
169
|
if (target != null) {
|
195
|
|
- target.performOnParentStack(stack -> ((StackController) stack).popTo(target, listener), () -> listener.onError("Nothing to pop"));
|
|
170
|
+ target.performOnParentStack(stack -> ((StackController) stack).popTo(target, listener));
|
196
|
171
|
} else {
|
197
|
|
- listener.onError("Nothing to pop");
|
|
172
|
+ listener.onError("Failed to execute stack command. Stack by " + id + " not found.");
|
198
|
173
|
}
|
199
|
174
|
}
|
200
|
175
|
|
|
@@ -229,12 +204,17 @@ public class Navigator extends ParentController {
|
229
|
204
|
return controllerById != null ? controllerById : modalStack.findControllerById(id);
|
230
|
205
|
}
|
231
|
206
|
|
232
|
|
- private void rejectPush(String fromId, ViewController viewController, CommandListener listener) {
|
233
|
|
- listener.onError("Could not push component: " +
|
234
|
|
- viewController.getId() +
|
235
|
|
- ". Stack with id " +
|
236
|
|
- fromId +
|
237
|
|
- " was not found.");
|
|
207
|
+ private void applyOnStack(String fromId, CommandListener listener, Task<StackController> task) {
|
|
208
|
+ ViewController from = findControllerById(fromId);
|
|
209
|
+ if (from != null) {
|
|
210
|
+ if (from instanceof StackController) {
|
|
211
|
+ task.run((StackController) from);
|
|
212
|
+ } else {
|
|
213
|
+ from.performOnParentStack(stack -> task.run((StackController) stack) );
|
|
214
|
+ }
|
|
215
|
+ } else {
|
|
216
|
+ listener.onError("Failed to execute stack command. Stack " + fromId + " not found.");
|
|
217
|
+ }
|
238
|
218
|
}
|
239
|
219
|
|
240
|
220
|
private boolean isRootNotCreated() {
|