Browse Source

Stop passing promise to pop

Guy Carmeli 6 years ago
parent
commit
c84a670f92

+ 5
- 5
lib/android/app/src/main/java/com/reactnativenavigation/react/NavigationModule.java View File

@@ -80,17 +80,17 @@ public class NavigationModule extends ReactContextBaseJavaModule {
80 80
 
81 81
 	@ReactMethod
82 82
 	public void pop(final String onComponentId, final ReadableMap options, final Promise promise) {
83
-		handle(() -> navigator().popSpecific(onComponentId, promise));
83
+		handle(() -> navigator().popSpecific(onComponentId, new CommandListenerAdapter(promise)));
84 84
 	}
85 85
 
86 86
 	@ReactMethod
87 87
 	public void popTo(final String componentId, final Promise promise) {
88
-		handle(() -> navigator().popTo(componentId, promise));
88
+		handle(() -> navigator().popTo(componentId, new CommandListenerAdapter(promise)));
89 89
 	}
90 90
 
91 91
 	@ReactMethod
92 92
 	public void popToRoot(final String componentId, final Promise promise) {
93
-		handle(() -> navigator().popToRoot(componentId, promise));
93
+		handle(() -> navigator().popToRoot(componentId, new CommandListenerAdapter(promise)));
94 94
 	}
95 95
 
96 96
 	@ReactMethod
@@ -104,12 +104,12 @@ public class NavigationModule extends ReactContextBaseJavaModule {
104 104
 
105 105
 	@ReactMethod
106 106
 	public void dismissModal(final String componentId, final Promise promise) {
107
-		handle(() -> navigator().dismissModal(componentId, promise));
107
+		handle(() -> navigator().dismissModal(componentId, new CommandListenerAdapter(promise)));
108 108
 	}
109 109
 
110 110
 	@ReactMethod
111 111
 	public void dismissAllModals(final Promise promise) {
112
-		handle(() -> navigator().dismissAllModals(promise));
112
+		handle(() -> navigator().dismissAllModals(new CommandListenerAdapter(promise)));
113 113
 	}
114 114
 
115 115
 	@ReactMethod

+ 7
- 6
lib/android/app/src/main/java/com/reactnativenavigation/viewcontrollers/ModalStack.java View File

@@ -3,8 +3,9 @@ package com.reactnativenavigation.viewcontrollers;
3 3
 import android.support.annotation.Nullable;
4 4
 
5 5
 import com.facebook.react.bridge.Promise;
6
-import com.reactnativenavigation.utils.NoOpPromise;
6
+import com.reactnativenavigation.utils.CommandListenerAdapter;
7 7
 import com.reactnativenavigation.utils.Task;
8
+import com.reactnativenavigation.viewcontrollers.Navigator.CommandListener;
8 9
 import com.reactnativenavigation.viewcontrollers.modal.Modal;
9 10
 import com.reactnativenavigation.viewcontrollers.modal.ModalCreator;
10 11
 import com.reactnativenavigation.viewcontrollers.modal.ModalListener;
@@ -30,17 +31,17 @@ class ModalStack implements ModalListener {
30 31
         promise.resolve(viewController.getId());
31 32
     }
32 33
 
33
-    void dismissModal(final String componentId, Promise promise) {
34
-        applyOnModal(componentId, (modal) -> modal.dismiss(promise), () -> Navigator.rejectPromise(promise));
34
+    void dismissModal(final String componentId, CommandListener listener) {
35
+        applyOnModal(componentId, (modal) -> modal.dismiss(listener), () -> listener.onError("Nothing to dismiss"));
35 36
     }
36 37
 
37 38
     void dismissAll() {
38
-        dismissAll(new NoOpPromise());
39
+        dismissAll(new CommandListenerAdapter());
39 40
     }
40 41
 
41
-    void dismissAll(Promise promise) {
42
+    void dismissAll(CommandListener listener) {
42 43
         for (Modal modal : modals) {
43
-            modal.dismiss(size() == 1 ? promise : new NoOpPromise());
44
+            modal.dismiss(size() == 1 ? listener : new CommandListenerAdapter());
44 45
         }
45 46
         modals.clear();
46 47
     }

+ 14
- 18
lib/android/app/src/main/java/com/reactnativenavigation/viewcontrollers/Navigator.java View File

@@ -120,35 +120,35 @@ public class Navigator extends ParentController implements ModalListener {
120 120
         }
121 121
     }
122 122
 
123
-    void pop(final String fromId, Promise promise) {
123
+    void pop(final String fromId, CommandListener listener) {
124 124
         ViewController from = findControllerById(fromId);
125 125
         if (from != null) {
126
-            from.performOnParentStack(stack -> ((StackController) stack).pop(promise));
126
+            from.performOnParentStack(stack -> ((StackController) stack).pop(listener));
127 127
         }
128 128
     }
129 129
 
130
-    public void popSpecific(final String id, Promise promise) {
130
+    public void popSpecific(final String id, CommandListener listener) {
131 131
         ViewController from = findControllerById(id);
132 132
         if (from != null) {
133
-            from.performOnParentStack(stack -> ((StackController) stack).popSpecific(from, promise), () -> rejectPromise(promise));
133
+            from.performOnParentStack(stack -> ((StackController) stack).popSpecific(from, listener), () -> listener.onError("Nothing to pop"));
134 134
         } else {
135
-            rejectPromise(promise);
135
+            listener.onError("Nothing to pop");
136 136
         }
137 137
     }
138 138
 
139
-    public void popToRoot(final String id, Promise promise) {
139
+    public void popToRoot(final String id, CommandListener listener) {
140 140
         ViewController from = findControllerById(id);
141 141
         if (from != null) {
142
-            from.performOnParentStack(stack -> ((StackController) stack).popToRoot(promise));
142
+            from.performOnParentStack(stack -> ((StackController) stack).popToRoot(listener));
143 143
         }
144 144
     }
145 145
 
146
-    public void popTo(final String componentId, Promise promise) {
146
+    public void popTo(final String componentId, CommandListener listener) {
147 147
         ViewController target = findControllerById(componentId);
148 148
         if (target != null) {
149
-            target.performOnParentStack(stack -> ((StackController) stack).popTo(target, promise), () -> rejectPromise(promise));
149
+            target.performOnParentStack(stack -> ((StackController) stack).popTo(target, listener), () -> listener.onError("Nothing to pop"));
150 150
         } else {
151
-            rejectPromise(promise);
151
+            listener.onError("Nothing to pop");
152 152
         }
153 153
     }
154 154
 
@@ -156,8 +156,8 @@ public class Navigator extends ParentController implements ModalListener {
156 156
         modalStack.showModal(viewController, promise);
157 157
     }
158 158
 
159
-    public void dismissModal(final String componentId, Promise promise) {
160
-        modalStack.dismissModal(componentId, promise);
159
+    public void dismissModal(final String componentId, CommandListener listener) {
160
+        modalStack.dismissModal(componentId, listener);
161 161
     }
162 162
 
163 163
     @Override
@@ -175,8 +175,8 @@ public class Navigator extends ParentController implements ModalListener {
175 175
         }
176 176
     }
177 177
 
178
-    public void dismissAllModals(Promise promise) {
179
-        modalStack.dismissAll(promise);
178
+    public void dismissAllModals(CommandListener listener) {
179
+        modalStack.dismissAll(listener);
180 180
     }
181 181
 
182 182
     public void showOverlay(ViewController overlay) {
@@ -187,10 +187,6 @@ public class Navigator extends ParentController implements ModalListener {
187 187
         overlayManager.dismiss(getView(), componentId);
188 188
     }
189 189
 
190
-    static void rejectPromise(Promise promise) {
191
-        promise.reject(new Throwable("Nothing to pop"));
192
-    }
193
-
194 190
     @Nullable
195 191
     @Override
196 192
     public ViewController findControllerById(String id) {

+ 22
- 23
lib/android/app/src/main/java/com/reactnativenavigation/viewcontrollers/StackController.java View File

@@ -6,11 +6,9 @@ import android.support.annotation.RestrictTo;
6 6
 import android.support.v4.view.ViewPager;
7 7
 import android.view.View;
8 8
 
9
-import com.facebook.react.bridge.Promise;
10 9
 import com.reactnativenavigation.anim.NavigationAnimator;
11 10
 import com.reactnativenavigation.parse.Options;
12 11
 import com.reactnativenavigation.utils.CommandListenerAdapter;
13
-import com.reactnativenavigation.utils.NoOpPromise;
14 12
 import com.reactnativenavigation.viewcontrollers.Navigator.CommandListener;
15 13
 import com.reactnativenavigation.viewcontrollers.topbar.TopBarBackgroundViewController;
16 14
 import com.reactnativenavigation.viewcontrollers.topbar.TopBarController;
@@ -27,7 +25,6 @@ import static android.view.ViewGroup.LayoutParams.MATCH_PARENT;
27 25
 
28 26
 public class StackController extends ParentController<StackLayout> {
29 27
 
30
-    private static final NoOpPromise NO_OP = new NoOpPromise();
31 28
     private final IdStack<ViewController> stack = new IdStack<>();
32 29
     private final NavigationAnimator animator;
33 30
     private final ReactViewCreator topBarButtonCreator;
@@ -137,9 +134,9 @@ public class StackController extends ParentController<StackLayout> {
137 134
         }
138 135
     }
139 136
 
140
-    void pop(final Promise promise) {
137
+    void pop(CommandListener listener) {
141 138
         if (!canPop()) {
142
-            Navigator.rejectPromise(promise);
139
+            listener.onError("Nothing to pop");
143 140
             return;
144 141
         }
145 142
 
@@ -147,12 +144,12 @@ public class StackController extends ParentController<StackLayout> {
147 144
         final ViewController enteringController = stack.peek();
148 145
         popInternal(exitingController, enteringController);
149 146
 
150
-        finishPopping(exitingController.getView(), exitingController, promise);
147
+        finishPopping(exitingController.getView(), exitingController, listener);
151 148
     }
152 149
 
153
-    void animatePop(final Promise promise) {
150
+    void animatePop(CommandListener listener) {
154 151
         if (!canPop()) {
155
-            Navigator.rejectPromise(promise);
152
+            listener.onError("Nothing to pop");
156 153
             return;
157 154
         }
158 155
 
@@ -160,8 +157,10 @@ public class StackController extends ParentController<StackLayout> {
160 157
         final ViewController enteringController = stack.peek();
161 158
         popInternal(exitingController, enteringController);
162 159
 
163
-        animator.animatePop(exitingController.getView(), () -> finishPopping(exitingController.getView(),
164
-                exitingController, promise));
160
+        animator.animatePop(
161
+                exitingController.getView(),
162
+                () -> finishPopping(exitingController.getView(), exitingController, listener)
163
+        );
165 164
     }
166 165
 
167 166
     private void popInternal(ViewController disappearing, ViewController appearing) {
@@ -176,25 +175,25 @@ public class StackController extends ParentController<StackLayout> {
176 175
         return stack.size() > 1;
177 176
     }
178 177
 
179
-    private void finishPopping(View exitingView, ViewController poppedTop, Promise promise) {
178
+    private void finishPopping(View exitingView, ViewController poppedTop, CommandListener listener) {
180 179
         getView().removeView(exitingView);
181 180
         poppedTop.destroy();
182
-        promise.resolve(poppedTop.getId());
181
+        listener.onSuccess(poppedTop.getId());
183 182
     }
184 183
 
185
-    void popSpecific(final ViewController childController, Promise promise) {
184
+    void popSpecific(final ViewController childController, CommandListener listener) {
186 185
         if (stack.isTop(childController.getId())) {
187
-            animatePop(promise);
186
+            animatePop(listener);
188 187
         } else {
189 188
             stack.remove(childController.getId());
190 189
             childController.destroy();
191
-            promise.resolve(childController.getId());
190
+            listener.onSuccess(childController.getId());
192 191
         }
193 192
     }
194 193
 
195
-    void popTo(final ViewController viewController, Promise promise) {
194
+    void popTo(final ViewController viewController, CommandListener listener) {
196 195
         if (!stack.containsId(viewController.getId())) {
197
-            Navigator.rejectPromise(promise);
196
+            listener.onError("Nothing to pop");
198 197
             return;
199 198
         }
200 199
 
@@ -204,21 +203,21 @@ public class StackController extends ParentController<StackLayout> {
204 203
             String nextControlId = iterator.next();
205 204
             boolean animate = nextControlId.equals(viewController.getId());
206 205
             if (animate) {
207
-                animatePop(promise);
206
+                animatePop(listener);
208 207
             } else {
209
-                pop(NO_OP);
208
+                pop(listener);
210 209
             }
211 210
             currentControlId = nextControlId;
212 211
         }
213 212
     }
214 213
 
215
-    void popToRoot(Promise promise) {
214
+    void popToRoot(CommandListener listener) {
216 215
         while (canPop()) {
217 216
             boolean animate = stack.size() == 2; // First element is root
218 217
             if (animate) {
219
-                animatePop(promise);
218
+                animatePop(listener);
220 219
             } else {
221
-                pop(NO_OP);
220
+                pop(listener);
222 221
             }
223 222
         }
224 223
     }
@@ -238,7 +237,7 @@ public class StackController extends ParentController<StackLayout> {
238 237
     @Override
239 238
     public boolean handleBack() {
240 239
         if (canPop()) {
241
-            animatePop(NO_OP);
240
+            animatePop(new CommandListenerAdapter());
242 241
             return true;
243 242
         }
244 243
         return false;

+ 6
- 6
lib/android/app/src/main/java/com/reactnativenavigation/viewcontrollers/modal/Modal.java View File

@@ -8,9 +8,9 @@ import android.support.annotation.Nullable;
8 8
 import android.view.KeyEvent;
9 9
 import android.view.View;
10 10
 
11
-import com.facebook.react.bridge.Promise;
12 11
 import com.reactnativenavigation.R;
13 12
 import com.reactnativenavigation.anim.ModalAnimator;
13
+import com.reactnativenavigation.viewcontrollers.Navigator.CommandListener;
14 14
 import com.reactnativenavigation.viewcontrollers.ViewController;
15 15
 
16 16
 import static android.view.View.MeasureSpec.EXACTLY;
@@ -20,7 +20,7 @@ public class Modal implements DialogInterface.OnKeyListener, DialogInterface.OnD
20 20
     public final ViewController viewController;
21 21
     private final Dialog dialog;
22 22
     private ModalListener modalListener;
23
-    @Nullable private Promise dismissPromise;
23
+    @Nullable private CommandListener dismissCommandListener;
24 24
 
25 25
     private ModalAnimator animator;
26 26
 
@@ -46,8 +46,8 @@ public class Modal implements DialogInterface.OnKeyListener, DialogInterface.OnD
46 46
         });
47 47
     }
48 48
 
49
-    public void dismiss(Promise promise) {
50
-        dismissPromise = promise;
49
+    public void dismiss(CommandListener listener) {
50
+        dismissCommandListener = listener;
51 51
         animator.animateDismiss(viewController.getView(), new AnimatorListenerAdapter() {
52 52
             @Override
53 53
             public void onAnimationEnd(Animator animation) {
@@ -79,8 +79,8 @@ public class Modal implements DialogInterface.OnKeyListener, DialogInterface.OnD
79 79
     @Override
80 80
     public void onDismiss(DialogInterface dialog) {
81 81
         modalListener.onModalDismiss(this);
82
-        if (dismissPromise != null) {
83
-            dismissPromise.resolve(viewController.getId());
82
+        if (dismissCommandListener != null) {
83
+            dismissCommandListener.onSuccess(viewController.getId());
84 84
         }
85 85
     }
86 86
 

+ 3
- 3
lib/android/app/src/test/java/com/reactnativenavigation/viewcontrollers/FloatingActionButtonTest.java View File

@@ -6,7 +6,6 @@ import android.view.View;
6 6
 import android.view.ViewGroup;
7 7
 
8 8
 import com.reactnativenavigation.BaseTest;
9
-import com.reactnativenavigation.mocks.MockPromise;
10 9
 import com.reactnativenavigation.mocks.SimpleViewController;
11 10
 import com.reactnativenavigation.mocks.TitleBarReactViewCreatorMock;
12 11
 import com.reactnativenavigation.mocks.TopBarBackgroundViewCreatorMock;
@@ -15,6 +14,7 @@ import com.reactnativenavigation.parse.FabOptions;
15 14
 import com.reactnativenavigation.parse.Options;
16 15
 import com.reactnativenavigation.parse.params.Bool;
17 16
 import com.reactnativenavigation.parse.params.Text;
17
+import com.reactnativenavigation.utils.CommandListenerAdapter;
18 18
 import com.reactnativenavigation.viewcontrollers.topbar.TopBarBackgroundViewController;
19 19
 import com.reactnativenavigation.viewcontrollers.topbar.TopBarController;
20 20
 import com.reactnativenavigation.views.Fab;
@@ -104,7 +104,7 @@ public class FloatingActionButtonTest extends BaseTest {
104 104
         stackController.push(childFab);
105 105
         childFab.onViewAppeared();
106 106
         assertThat(hasFab()).isTrue();
107
-        stackController.pop(new MockPromise());
107
+        stackController.pop(new CommandListenerAdapter());
108 108
         childNoFab.onViewAppeared();
109 109
         assertThat(hasFab()).isFalse();
110 110
     }
@@ -118,7 +118,7 @@ public class FloatingActionButtonTest extends BaseTest {
118 118
         stackController.push(childNoFab);
119 119
         childNoFab.onViewAppeared();
120 120
         assertThat(hasFab()).isFalse();
121
-        stackController.pop(new MockPromise());
121
+        stackController.pop(new CommandListenerAdapter());
122 122
         childFab.onViewAppeared();
123 123
         assertThat(hasFab()).isTrue();
124 124
     }

+ 17
- 16
lib/android/app/src/test/java/com/reactnativenavigation/viewcontrollers/ModalStackTest.java View File

@@ -5,6 +5,7 @@ import com.reactnativenavigation.mocks.MockPromise;
5 5
 import com.reactnativenavigation.mocks.ModalCreatorMock;
6 6
 import com.reactnativenavigation.mocks.SimpleViewController;
7 7
 import com.reactnativenavigation.parse.Options;
8
+import com.reactnativenavigation.utils.CommandListenerAdapter;
8 9
 import com.reactnativenavigation.viewcontrollers.modal.Modal;
9 10
 import com.reactnativenavigation.viewcontrollers.modal.ModalListener;
10 11
 
@@ -48,13 +49,13 @@ public class ModalStackTest extends BaseTest {
48 49
     }
49 50
 
50 51
     @Test
51
-    public void modalRefIsSaved() throws Exception {
52
+    public void modalRefIsSaved() {
52 53
         uut.showModal(viewController, new MockPromise());
53 54
         assertThat(findModal(CONTROLLER_ID)).isNotNull();
54 55
     }
55 56
 
56 57
     @Test
57
-    public void modalIsShown() throws Exception {
58
+    public void modalIsShown() {
58 59
         uut.showModal(viewController, new MockPromise() {
59 60
             @Override
60 61
             public void resolve(@Nullable Object value) {
@@ -65,13 +66,13 @@ public class ModalStackTest extends BaseTest {
65 66
     }
66 67
 
67 68
     @Test
68
-    public void modalIsDismissed() throws Exception {
69
+    public void modalIsDismissed() {
69 70
         uut.showModal(viewController, new MockPromise());
70 71
         final Modal modal = findModal(CONTROLLER_ID);
71 72
         assertThat(modal).isNotNull();
72
-        uut.dismissModal(CONTROLLER_ID, new MockPromise() {
73
+        uut.dismissModal(CONTROLLER_ID, new CommandListenerAdapter() {
73 74
             @Override
74
-            public void resolve(@Nullable Object value) {
75
+            public void onSuccess(String childId) {
75 76
                 assertThat(findModal(CONTROLLER_ID)).isNull();
76 77
                 verify(uut, times(1)).onModalDismiss(modal);
77 78
             }
@@ -79,46 +80,46 @@ public class ModalStackTest extends BaseTest {
79 80
     }
80 81
 
81 82
     @Test
82
-    public void dismissAllModals() throws Exception {
83
+    public void dismissAllModals() {
83 84
         uut.showModal(new SimpleViewController(newActivity(), "1", new Options()), new MockPromise());
84 85
         uut.showModal(new SimpleViewController(newActivity(), "2", new Options()), new MockPromise());
85
-        uut.dismissAll(new MockPromise() {
86
+        uut.dismissAll(new CommandListenerAdapter() {
86 87
             @Override
87
-            public void resolve(@Nullable Object value) {
88
+            public void onSuccess(String childId) {
88 89
                 assertThat(uut.isEmpty()).isTrue();
89 90
             }
90 91
         });
91 92
     }
92 93
 
93 94
     @Test
94
-    public void isEmpty() throws Exception {
95
+    public void isEmpty() {
95 96
         assertThat(uut.isEmpty()).isTrue();
96 97
         uut.showModal(viewController, new MockPromise());
97 98
         assertThat(uut.isEmpty()).isFalse();
98
-        uut.dismissAll(new MockPromise());
99
+        uut.dismissAll(new CommandListenerAdapter());
99 100
         assertThat(uut.isEmpty()).isTrue();
100 101
     }
101 102
 
102 103
     @Test
103
-    public void onDismiss() throws Exception {
104
+    public void onDismiss() {
104 105
         uut.showModal(viewController, new MockPromise());
105 106
         uut.showModal(new SimpleViewController(newActivity(), "otherComponent", new Options()), new MockPromise());
106
-        uut.dismissAll(new MockPromise() {
107
+        uut.dismissAll(new CommandListenerAdapter() {
107 108
             @Override
108
-            public void resolve(@Nullable Object value) {
109
+            public void onSuccess(String childId) {
109 110
                 verify(uut, times(2)).onModalDismiss(any());
110 111
             }
111 112
         });
112 113
     }
113 114
 
114 115
     @Test
115
-    public void onDismiss_onViewAppearedInvokedOnPreviousModal() throws Exception {
116
+    public void onDismiss_onViewAppearedInvokedOnPreviousModal() {
116 117
         SimpleViewController viewController = spy(new SimpleViewController(newActivity(), "otherComponent", new Options()));
117 118
         uut.showModal(viewController, new MockPromise());
118 119
         uut.showModal(this.viewController, new MockPromise());
119
-        uut.dismissModal(CONTROLLER_ID, new MockPromise() {
120
+        uut.dismissModal(CONTROLLER_ID, new CommandListenerAdapter() {
120 121
             @Override
121
-            public void resolve(@Nullable Object value) {
122
+            public void onSuccess(String childId) {
122 123
                 verify(viewController, times(1)).onViewAppeared();
123 124
             }
124 125
         });

+ 16
- 16
lib/android/app/src/test/java/com/reactnativenavigation/viewcontrollers/NavigatorTest.java View File

@@ -122,9 +122,9 @@ public class NavigatorTest extends BaseTest {
122 122
 
123 123
     @Test
124 124
     public void pop_InvalidDoesNothing() {
125
-        uut.pop("123", new MockPromise());
125
+        uut.pop("123", new CommandListenerAdapter());
126 126
         uut.setRoot(child1, new MockPromise());
127
-        uut.pop(child1.getId(), new MockPromise());
127
+        uut.pop(child1.getId(), new CommandListenerAdapter());
128 128
         assertThat(uut.getChildControllers()).hasSize(1);
129 129
     }
130 130
 
@@ -143,7 +143,7 @@ public class NavigatorTest extends BaseTest {
143 143
                 stack2.push(child4, new CommandListenerAdapter() {
144 144
                             @Override
145 145
                             public void onSuccess(String childId) {
146
-                                uut.pop("child4", new MockPromise());
146
+                                uut.pop("child4", new CommandListenerAdapter());
147 147
                                 assertThat(stack2.getChildControllers()).containsOnly(child2, child3);
148 148
                             }
149 149
                         }
@@ -164,7 +164,7 @@ public class NavigatorTest extends BaseTest {
164 164
         bottomTabsController.setTabs(Arrays.asList(stack1, stack2));
165 165
         uut.setRoot(bottomTabsController, new MockPromise());
166 166
 
167
-        uut.popSpecific(child2.getId(), new MockPromise());
167
+        uut.popSpecific(child2.getId(), new CommandListenerAdapter());
168 168
 
169 169
         assertThat(stack2.getChildControllers()).containsOnly(child4, child3);
170 170
     }
@@ -184,7 +184,7 @@ public class NavigatorTest extends BaseTest {
184 184
         stack2.push(child5, new CommandListenerAdapter() {
185 185
             @Override
186 186
             public void onSuccess(String childId) {
187
-                uut.popTo(child2.getId(), new MockPromise());
187
+                uut.popTo(child2.getId(), new CommandListenerAdapter());
188 188
                 assertThat(stack2.getChildControllers()).containsOnly(child2);
189 189
             }
190 190
         });
@@ -205,7 +205,7 @@ public class NavigatorTest extends BaseTest {
205 205
         stack2.push(child5, new CommandListenerAdapter() {
206 206
             @Override
207 207
             public void onSuccess(String childId) {
208
-                uut.popToRoot(child3.getId(), new MockPromise());
208
+                uut.popToRoot(child3.getId(), new CommandListenerAdapter());
209 209
                 assertThat(stack2.getChildControllers()).containsOnly(child2);
210 210
             }
211 211
         });
@@ -306,11 +306,11 @@ public class NavigatorTest extends BaseTest {
306 306
 
307 307
     @Test
308 308
     public void pop_InvalidDoesNothing_Promise() {
309
-        uut.pop("123", new MockPromise());
309
+        uut.pop("123", new CommandListenerAdapter());
310 310
         uut.setRoot(child1, new MockPromise());
311
-        uut.pop(child1.getId(), new MockPromise() {
311
+        uut.pop(child1.getId(), new CommandListenerAdapter() {
312 312
             @Override
313
-            public void reject(Throwable reason) {
313
+            public void onError(String reason) {
314 314
                 assertThat(uut.getChildControllers()).hasSize(1);
315 315
             }
316 316
         });
@@ -330,7 +330,7 @@ public class NavigatorTest extends BaseTest {
330 330
         stack2.push(child4, new CommandListenerAdapter() {
331 331
             @Override
332 332
             public void onSuccess(String childId) {
333
-                uut.pop("child4", new MockPromise());
333
+                uut.pop("child4", new CommandListenerAdapter());
334 334
                 assertThat(stack2.getChildControllers()).containsOnly(child2, child3);
335 335
             }
336 336
         });
@@ -361,14 +361,14 @@ public class NavigatorTest extends BaseTest {
361 361
         child1.ensureViewIsCreated();
362 362
         child2.ensureViewIsCreated();
363 363
 
364
-        MockPromise promise = new MockPromise() {
364
+        Navigator.CommandListener listener = new CommandListenerAdapter() {
365 365
             @Override
366
-            public void resolve(@Nullable Object value) {
366
+            public void onSuccess(String childId) {
367 367
                 assertThat(parentController.getChildControllers().size()).isEqualTo(1);
368 368
             }
369 369
         };
370
-        uut.popSpecific("child2", promise);
371
-        verify(parentController, times(1)).popSpecific(child2, promise);
370
+        uut.popSpecific("child2", listener);
371
+        verify(parentController, times(1)).popSpecific(child2, listener);
372 372
     }
373 373
 
374 374
     @Test
@@ -388,9 +388,9 @@ public class NavigatorTest extends BaseTest {
388 388
         uut.showModal(child1, new MockPromise() {
389 389
             @Override
390 390
             public void resolve(@Nullable Object value) {
391
-                uut.dismissModal("child1", new MockPromise() {
391
+                uut.dismissModal("child1", new CommandListenerAdapter() {
392 392
                     @Override
393
-                    public void resolve(@Nullable Object value) {
393
+                    public void onSuccess(String childId) {
394 394
                         verify(parentController, times(1)).onViewRegainedFocus();
395 395
                     }
396 396
                 });

+ 22
- 25
lib/android/app/src/test/java/com/reactnativenavigation/viewcontrollers/StackControllerTest.java View File

@@ -6,7 +6,6 @@ import android.view.View;
6 6
 
7 7
 import com.reactnativenavigation.BaseTest;
8 8
 import com.reactnativenavigation.anim.NavigationAnimator;
9
-import com.reactnativenavigation.mocks.MockPromise;
10 9
 import com.reactnativenavigation.mocks.SimpleViewController;
11 10
 import com.reactnativenavigation.mocks.TitleBarReactViewCreatorMock;
12 11
 import com.reactnativenavigation.mocks.TopBarBackgroundViewCreatorMock;
@@ -29,8 +28,6 @@ import org.junit.Test;
29 28
 import org.mockito.ArgumentCaptor;
30 29
 import org.mockito.Mockito;
31 30
 
32
-import javax.annotation.Nullable;
33
-
34 31
 import static org.assertj.core.api.Java6Assertions.assertThat;
35 32
 import static org.mockito.ArgumentMatchers.eq;
36 33
 import static org.mockito.Mockito.mock;
@@ -113,7 +110,7 @@ public class StackControllerTest extends BaseTest {
113 110
             @Override
114 111
             public void onSuccess(String childId) {
115 112
                 assertContainsOnlyId(child2.getId(), child1.getId());
116
-                uut.pop(new MockPromise());
113
+                uut.pop(new CommandListenerAdapter());
117 114
                 assertContainsOnlyId(child1.getId());
118 115
             }
119 116
         });
@@ -125,7 +122,7 @@ public class StackControllerTest extends BaseTest {
125 122
         uut.push(child2, new CommandListenerAdapter() {
126 123
             @Override
127 124
             public void onSuccess(String childId) {
128
-                uut.pop(new MockPromise());
125
+                uut.pop(new CommandListenerAdapter());
129 126
                 verify(uut, times(1)).applyChildOptions(uut.options, eq((ReactComponent) child1.getView()));
130 127
             }
131 128
         });
@@ -147,9 +144,9 @@ public class StackControllerTest extends BaseTest {
147 144
         uut.push(child2, new CommandListenerAdapter() {
148 145
             @Override
149 146
             public void onSuccess(String childId) {
150
-                uut.animatePop(new MockPromise() {
147
+                uut.animatePop(new CommandListenerAdapter() {
151 148
                     @Override
152
-                    public void resolve(@Nullable Object value) {
149
+                    public void onSuccess(String childId) {
153 150
                         verify(stackLayout[0], times(1)).onChildWillDisappear(child2.options, child1.options, () -> {
154 151
                         });
155 152
                     }
@@ -204,11 +201,11 @@ public class StackControllerTest extends BaseTest {
204 201
     @Test
205 202
     public void popDoesNothingWhenZeroOrOneChild() {
206 203
         assertThat(uut.isEmpty()).isTrue();
207
-        uut.pop(new MockPromise());
204
+        uut.pop(new CommandListenerAdapter());
208 205
         assertThat(uut.isEmpty()).isTrue();
209 206
 
210 207
         uut.push(child1, new CommandListenerAdapter());
211
-        uut.pop(new MockPromise());
208
+        uut.pop(new CommandListenerAdapter());
212 209
         assertContainsOnlyId(child1.getId());
213 210
     }
214 211
 
@@ -256,7 +253,7 @@ public class StackControllerTest extends BaseTest {
256 253
             public void onSuccess(String childId) {
257 254
                 assertIsChildById(uut.getView(), child2View);
258 255
                 assertNotChildOf(uut.getView(), child1View);
259
-                uut.pop(new MockPromise());
256
+                uut.pop(new CommandListenerAdapter());
260 257
                 assertNotChildOf(uut.getView(), child2View);
261 258
                 assertIsChildById(uut.getView(), child1View);
262 259
             }
@@ -269,9 +266,9 @@ public class StackControllerTest extends BaseTest {
269 266
         uut.push(child2, new CommandListenerAdapter() {
270 267
             @Override
271 268
             public void onSuccess(String childId) {
272
-                uut.popSpecific(child2, new MockPromise() {
269
+                uut.popSpecific(child2, new CommandListenerAdapter() {
273 270
                     @Override
274
-                    public void resolve(@Nullable Object value) {
271
+                    public void onSuccess(String childId) {
275 272
                         assertContainsOnlyId(child1.getId());
276 273
                         assertIsChildById(uut.getView(), child1.getView());
277 274
                     }
@@ -285,7 +282,7 @@ public class StackControllerTest extends BaseTest {
285 282
         uut.push(child1, new CommandListenerAdapter());
286 283
         uut.push(child2, new CommandListenerAdapter());
287 284
         assertIsChildById(uut.getView(), child2.getView());
288
-        uut.popSpecific(child1, new MockPromise());
285
+        uut.popSpecific(child1, new CommandListenerAdapter());
289 286
         assertContainsOnlyId(child2.getId());
290 287
         assertIsChildById(uut.getView(), child2.getView());
291 288
     }
@@ -300,7 +297,7 @@ public class StackControllerTest extends BaseTest {
300 297
                 assertThat(uut.size()).isEqualTo(3);
301 298
                 assertThat(uut.peek()).isEqualTo(child3);
302 299
 
303
-                uut.popTo(child1, new MockPromise());
300
+                uut.popTo(child1, new CommandListenerAdapter());
304 301
 
305 302
                 assertThat(uut.size()).isEqualTo(1);
306 303
                 assertThat(uut.peek()).isEqualTo(child1);
@@ -313,7 +310,7 @@ public class StackControllerTest extends BaseTest {
313 310
         uut.push(child1, new CommandListenerAdapter());
314 311
         uut.push(child3, new CommandListenerAdapter());
315 312
         assertThat(uut.size()).isEqualTo(2);
316
-        uut.popTo(child2, new MockPromise());
313
+        uut.popTo(child2, new CommandListenerAdapter());
317 314
         assertThat(uut.size()).isEqualTo(2);
318 315
     }
319 316
 
@@ -330,9 +327,9 @@ public class StackControllerTest extends BaseTest {
330 327
                 assertThat(uut.size()).isEqualTo(3);
331 328
                 assertThat(uut.peek()).isEqualTo(child3);
332 329
 
333
-                uut.popToRoot(new MockPromise() {
330
+                uut.popToRoot(new CommandListenerAdapter() {
334 331
                     @Override
335
-                    public void resolve(@Nullable Object value) {
332
+                    public void onSuccess(String childId) {
336 333
                         assertThat(uut.size()).isEqualTo(1);
337 334
                         assertThat(uut.peek()).isEqualTo(child1);
338 335
                     }
@@ -344,7 +341,7 @@ public class StackControllerTest extends BaseTest {
344 341
     @Test
345 342
     public void popToRoot_EmptyStackDoesNothing() {
346 343
         assertThat(uut.isEmpty()).isTrue();
347
-        uut.popToRoot(new MockPromise());
344
+        uut.popToRoot(new CommandListenerAdapter());
348 345
         assertThat(uut.isEmpty()).isTrue();
349 346
     }
350 347
 
@@ -375,7 +372,7 @@ public class StackControllerTest extends BaseTest {
375 372
             @Override
376 373
             public void onSuccess(String childId) {
377 374
                 verify(child3, times(0)).destroy();
378
-                uut.pop(new MockPromise());
375
+                uut.pop(new CommandListenerAdapter());
379 376
                 verify(child3, times(1)).destroy();
380 377
             }
381 378
         });
@@ -389,7 +386,7 @@ public class StackControllerTest extends BaseTest {
389 386
         child2 = spy(child2);
390 387
         uut.push(child1, new CommandListenerAdapter());
391 388
         uut.push(child2, new CommandListenerAdapter());
392
-        uut.pop(new MockPromise());
389
+        uut.pop(new CommandListenerAdapter());
393 390
         verify(child1, times(1)).onViewWillAppear();
394 391
         verify(child2, times(1)).onViewWillDisappear();
395 392
     }
@@ -406,9 +403,9 @@ public class StackControllerTest extends BaseTest {
406 403
 
407 404
         assertThat(uut.getTopBar().getVisibility()).isEqualTo(View.GONE);
408 405
         uut.push(child2, new CommandListenerAdapter());
409
-        uut.animatePop(new MockPromise() {
406
+        uut.animatePop(new CommandListenerAdapter() {
410 407
             @Override
411
-            public void resolve(@Nullable Object value) {
408
+            public void onSuccess(String childId) {
412 409
                 verify(uut.getTopBar(), times(1)).hide();
413 410
             }
414 411
         });
@@ -424,7 +421,7 @@ public class StackControllerTest extends BaseTest {
424 421
         uut.push(child3, new CommandListenerAdapter());
425 422
 
426 423
         verify(child2, times(0)).destroy();
427
-        uut.popSpecific(child2, new MockPromise());
424
+        uut.popSpecific(child2, new CommandListenerAdapter());
428 425
         verify(child2, times(1)).destroy();
429 426
     }
430 427
 
@@ -441,9 +438,9 @@ public class StackControllerTest extends BaseTest {
441 438
                 verify(child2, times(0)).destroy();
442 439
                 verify(child3, times(0)).destroy();
443 440
 
444
-                uut.popTo(child1, new MockPromise() {
441
+                uut.popTo(child1, new CommandListenerAdapter() {
445 442
                     @Override
446
-                    public void resolve(@Nullable Object value) {
443
+                    public void onSuccess(String childId) {
447 444
                         verify(child2, times(1)).destroy();
448 445
                         verify(child3, times(1)).destroy();
449 446
                     }

+ 3
- 5
lib/android/app/src/test/java/com/reactnativenavigation/viewcontrollers/TopTabsViewControllerTest.java View File

@@ -5,7 +5,6 @@ import android.support.annotation.NonNull;
5 5
 import android.view.ViewGroup;
6 6
 
7 7
 import com.reactnativenavigation.BaseTest;
8
-import com.reactnativenavigation.mocks.MockPromise;
9 8
 import com.reactnativenavigation.mocks.TestComponentViewCreator;
10 9
 import com.reactnativenavigation.mocks.TestReactView;
11 10
 import com.reactnativenavigation.mocks.TitleBarReactViewCreatorMock;
@@ -14,6 +13,7 @@ import com.reactnativenavigation.mocks.TopBarButtonCreatorMock;
14 13
 import com.reactnativenavigation.parse.Options;
15 14
 import com.reactnativenavigation.parse.params.Bool;
16 15
 import com.reactnativenavigation.parse.params.Text;
16
+import com.reactnativenavigation.utils.CommandListenerAdapter;
17 17
 import com.reactnativenavigation.utils.ViewHelper;
18 18
 import com.reactnativenavigation.viewcontrollers.topbar.TopBarBackgroundViewController;
19 19
 import com.reactnativenavigation.viewcontrollers.topbar.TopBarController;
@@ -30,8 +30,6 @@ import org.mockito.Mockito;
30 30
 import java.util.ArrayList;
31 31
 import java.util.List;
32 32
 
33
-import javax.annotation.Nullable;
34
-
35 33
 import static org.assertj.core.api.Java6Assertions.assertThat;
36 34
 import static org.mockito.ArgumentMatchers.any;
37 35
 import static org.mockito.ArgumentMatchers.eq;
@@ -243,9 +241,9 @@ public class TopTabsViewControllerTest extends BaseTest {
243 241
         uut.onViewAppeared();
244 242
 
245 243
         assertThat(ViewHelper.isVisible(stackController.getTopBar().getTopTabs())).isTrue();
246
-        stackController.animatePop(new MockPromise() {
244
+        stackController.animatePop(new CommandListenerAdapter() {
247 245
             @Override
248
-            public void resolve(@Nullable Object value) {
246
+            public void onSuccess(String childId) {
249 247
                 assertThat(ViewHelper.isVisible(stackController.getTopBar().getTopTabs())).isFalse();
250 248
             }
251 249
         });