Guy Carmeli пре 7 година
родитељ
комит
9a39716b42
14 измењених фајлова са 321 додато и 188 уклоњено
  1. 1
    4
      lib/android/app/src/main/java/com/reactnativenavigation/parse/LayoutFactory.java
  2. 28
    1
      lib/android/app/src/main/java/com/reactnativenavigation/react/NavigationModule.java
  3. 16
    0
      lib/android/app/src/main/java/com/reactnativenavigation/utils/CommandListenerAdapter.java
  4. 4
    0
      lib/android/app/src/main/java/com/reactnativenavigation/viewcontrollers/ModalStack.java
  5. 17
    5
      lib/android/app/src/main/java/com/reactnativenavigation/viewcontrollers/Navigator.java
  6. 38
    5
      lib/android/app/src/main/java/com/reactnativenavigation/viewcontrollers/StackController.java
  7. 3
    3
      lib/android/app/src/test/java/com/reactnativenavigation/viewcontrollers/BottomTabsControllerTest.java
  8. 8
    8
      lib/android/app/src/test/java/com/reactnativenavigation/viewcontrollers/FloatingActionButtonTest.java
  9. 62
    49
      lib/android/app/src/test/java/com/reactnativenavigation/viewcontrollers/NavigatorTest.java
  10. 14
    13
      lib/android/app/src/test/java/com/reactnativenavigation/viewcontrollers/OptionsApplyingTest.java
  11. 4
    4
      lib/android/app/src/test/java/com/reactnativenavigation/viewcontrollers/ParentControllerTest.java
  12. 121
    91
      lib/android/app/src/test/java/com/reactnativenavigation/viewcontrollers/StackControllerTest.java
  13. 3
    3
      lib/android/app/src/test/java/com/reactnativenavigation/viewcontrollers/TopTabsViewControllerTest.java
  14. 2
    2
      lib/android/app/src/test/java/com/reactnativenavigation/viewcontrollers/ViewControllerTest.java

+ 1
- 4
lib/android/app/src/main/java/com/reactnativenavigation/parse/LayoutFactory.java Прегледај датотеку

@@ -4,7 +4,6 @@ import android.app.Activity;
4 4
 
5 5
 import com.facebook.react.ReactInstanceManager;
6 6
 import com.reactnativenavigation.utils.ImageLoader;
7
-import com.reactnativenavigation.utils.NoOpPromise;
8 7
 import com.reactnativenavigation.utils.TypefaceLoader;
9 8
 import com.reactnativenavigation.viewcontrollers.ComponentViewController;
10 9
 import com.reactnativenavigation.viewcontrollers.SideMenuController;
@@ -138,9 +137,7 @@ public class LayoutFactory {
138 137
     private void addChildrenToStack(List<LayoutNode> children, StackController stackController) {
139 138
         for (int i = 0; i < children.size(); i++) {
140 139
             if (i < children.size() - 1) {
141
-                stackController.push(create(children.get(i)), new NoOpPromise());
142
-            } else {
143
-                stackController.animatePush(create(children.get(i)), new NoOpPromise());
140
+                stackController.push(create(children.get(i)));
144 141
             }
145 142
         }
146 143
     }

+ 28
- 1
lib/android/app/src/main/java/com/reactnativenavigation/react/NavigationModule.java Прегледај датотеку

@@ -65,10 +65,19 @@ public class NavigationModule extends ReactContextBaseJavaModule {
65 65
 		final LayoutNode layoutTree = LayoutNodeParser.parse(new JSONObject(rawLayoutTree.toHashMap()));
66 66
 		handle(() -> {
67 67
             final ViewController viewController = newLayoutFactory().create(layoutTree);
68
-            navigator().push(onComponentId, viewController, promise);
68
+            navigator().push(onComponentId, viewController, new CommandListenerAdapter(promise));
69 69
         });
70 70
 	}
71 71
 
72
+    @ReactMethod
73
+    public void setStackRoot(final String onComponentId, final ReadableMap rawLayoutTree, final Promise promise) {
74
+        final LayoutNode layoutTree = LayoutNodeParser.parse(new JSONObject(rawLayoutTree.toHashMap()));
75
+        handle(() -> {
76
+            final ViewController viewController = newLayoutFactory().create(layoutTree);
77
+            navigator().setStackRoot(onComponentId, viewController, new CommandListenerAdapter(promise));
78
+        });
79
+    }
80
+
72 81
 	@ReactMethod
73 82
 	public void pop(final String onComponentId, final ReadableMap options, final Promise promise) {
74 83
 		handle(() -> navigator().popSpecific(onComponentId, promise));
@@ -142,4 +151,22 @@ public class NavigationModule extends ReactContextBaseJavaModule {
142 151
     private NavigationActivity activity() {
143 152
         return (NavigationActivity) getCurrentActivity();
144 153
     }
154
+
155
+    private class CommandListenerAdapter implements Navigator.CommandListener {
156
+        private Promise promise;
157
+
158
+        CommandListenerAdapter(Promise promise) {
159
+            this.promise = promise;
160
+        }
161
+
162
+        @Override
163
+        public void onSuccess(String childId) {
164
+            promise.resolve(childId);
165
+        }
166
+
167
+        @Override
168
+        public void onError(String message) {
169
+            promise.reject(new Throwable(message));
170
+        }
171
+    }
145 172
 }

+ 16
- 0
lib/android/app/src/main/java/com/reactnativenavigation/utils/CommandListenerAdapter.java Прегледај датотеку

@@ -0,0 +1,16 @@
1
+package com.reactnativenavigation.utils;
2
+
3
+import com.reactnativenavigation.viewcontrollers.Navigator;
4
+
5
+public class CommandListenerAdapter implements Navigator.CommandListener {
6
+    @Override
7
+    public void onSuccess(String childId) {
8
+
9
+    }
10
+
11
+    @Override
12
+    public void onError(String message) {
13
+
14
+    }
15
+}
16
+

+ 4
- 0
lib/android/app/src/main/java/com/reactnativenavigation/viewcontrollers/ModalStack.java Прегледај датотеку

@@ -34,6 +34,10 @@ class ModalStack implements ModalListener {
34 34
         applyOnModal(componentId, (modal) -> modal.dismiss(promise), () -> Navigator.rejectPromise(promise));
35 35
     }
36 36
 
37
+    void dismissAll() {
38
+        dismissAll(new NoOpPromise());
39
+    }
40
+
37 41
     void dismissAll(Promise promise) {
38 42
         for (Modal modal : modals) {
39 43
             modal.dismiss(size() == 1 ? promise : new NoOpPromise());

+ 17
- 5
lib/android/app/src/main/java/com/reactnativenavigation/viewcontrollers/Navigator.java Прегледај датотеку

@@ -14,7 +14,6 @@ import com.reactnativenavigation.parse.Options;
14 14
 import com.reactnativenavigation.presentation.NavigationOptionsListener;
15 15
 import com.reactnativenavigation.presentation.OverlayManager;
16 16
 import com.reactnativenavigation.utils.CompatUtils;
17
-import com.reactnativenavigation.utils.NoOpPromise;
18 17
 import com.reactnativenavigation.viewcontrollers.modal.Modal;
19 18
 import com.reactnativenavigation.viewcontrollers.modal.ModalCreator;
20 19
 import com.reactnativenavigation.viewcontrollers.modal.ModalListener;
@@ -24,7 +23,12 @@ import java.util.Collections;
24 23
 
25 24
 public class Navigator extends ParentController implements ModalListener {
26 25
 
27
-    private static final NoOpPromise NO_OP = new NoOpPromise();
26
+    public interface CommandListener {
27
+        void onSuccess(String childId);
28
+
29
+        void onError(String message);
30
+    }
31
+
28 32
     private final ModalStack modalStack;
29 33
     private ViewController root;
30 34
     private OverlayManager overlayManager = new OverlayManager();
@@ -54,7 +58,7 @@ public class Navigator extends ParentController implements ModalListener {
54 58
 
55 59
     @Override
56 60
     public void destroy() {
57
-        modalStack.dismissAll(NO_OP);
61
+        modalStack.dismissAll();
58 62
         super.destroy();
59 63
     }
60 64
 
@@ -100,10 +104,18 @@ public class Navigator extends ParentController implements ModalListener {
100 104
         }
101 105
     }
102 106
 
103
-    public void push(final String fromId, final ViewController viewController, Promise promise) {
107
+    public void push(final String fromId, final ViewController viewController, CommandListener listener) {
108
+        ViewController from = findControllerById(fromId);
109
+        if (from != null) {
110
+            from.performOnParentStack(stack -> ((StackController) stack).animatePush(viewController, listener));
111
+        }
112
+        listener.onError("Could not push component: " + viewController.getId() + ". Stack with id " + fromId + " was not found.");
113
+    }
114
+
115
+    public void setStackRoot(String fromId, ViewController viewController, CommandListener listener) {
104 116
         ViewController from = findControllerById(fromId);
105 117
         if (from != null) {
106
-            from.performOnParentStack(stack -> ((StackController) stack).animatePush(viewController, promise));
118
+            from.performOnParentStack(stack -> ((StackController) stack).setRoot(viewController, listener));
107 119
         }
108 120
     }
109 121
 

+ 38
- 5
lib/android/app/src/main/java/com/reactnativenavigation/viewcontrollers/StackController.java Прегледај датотеку

@@ -9,7 +9,9 @@ import android.view.View;
9 9
 import com.facebook.react.bridge.Promise;
10 10
 import com.reactnativenavigation.anim.NavigationAnimator;
11 11
 import com.reactnativenavigation.parse.Options;
12
+import com.reactnativenavigation.utils.CommandListenerAdapter;
12 13
 import com.reactnativenavigation.utils.NoOpPromise;
14
+import com.reactnativenavigation.viewcontrollers.Navigator.CommandListener;
13 15
 import com.reactnativenavigation.viewcontrollers.topbar.TopBarBackgroundViewController;
14 16
 import com.reactnativenavigation.viewcontrollers.topbar.TopBarController;
15 17
 import com.reactnativenavigation.views.Component;
@@ -91,7 +93,11 @@ public class StackController extends ParentController<StackLayout> {
91 93
         topBarController.clear();
92 94
     }
93 95
 
94
-    public void push(ViewController child, final Promise promise) {
96
+    public void push(ViewController child) {
97
+        push(child, new CommandListenerAdapter());
98
+    }
99
+
100
+    public void push(ViewController child, CommandListener listener) {
95 101
         final ViewController toRemove = stack.peek();
96 102
 
97 103
         child.setParentController(this);
@@ -102,10 +108,10 @@ public class StackController extends ParentController<StackLayout> {
102 108
         if (toRemove != null) {
103 109
             getView().removeView(toRemove.getView());
104 110
         }
105
-        promise.resolve(child.getId());
111
+        listener.onSuccess(child.getId());
106 112
     }
107 113
 
108
-    public void animatePush(final ViewController child, final Promise promise) {
114
+    public void animatePush(final ViewController child, CommandListener listener) {
109 115
         final ViewController toRemove = stack.peek();
110 116
 
111 117
         child.setParentController(this);
@@ -116,10 +122,37 @@ public class StackController extends ParentController<StackLayout> {
116 122
         if (toRemove != null) {
117 123
             animator.animatePush(enteringView, () -> {
118 124
                 getView().removeView(toRemove.getView());
119
-                promise.resolve(child.getId());
125
+                listener.onSuccess(child.getId());
120 126
             });
121 127
         } else {
122
-            promise.resolve(child.getId());
128
+            listener.onSuccess(child.getId());
129
+        }
130
+    }
131
+
132
+    public void setRoot(ViewController child, CommandListener listener) {
133
+        push(child);
134
+        removeChildrenBellowTop();
135
+        listener.onSuccess(child.getId());
136
+    }
137
+
138
+    public void animateSetRoot(ViewController child, CommandListener listener) {
139
+        animatePush(child, new CommandListenerAdapter() {
140
+            @Override
141
+            public void onSuccess(String childId) {
142
+                removeChildrenBellowTop();
143
+                listener.onSuccess(childId);
144
+            }
145
+        });
146
+    }
147
+
148
+    private void removeChildrenBellowTop() {
149
+        Iterator<String> iterator = stack.iterator();
150
+        while (stack.size() > 1) {
151
+            ViewController controller = stack.get(iterator.next());
152
+            if (!stack.isTop(controller.getId())) {
153
+                stack.remove(controller.getId());
154
+                controller.destroy();
155
+            }
123 156
         }
124 157
     }
125 158
 

+ 3
- 3
lib/android/app/src/test/java/com/reactnativenavigation/viewcontrollers/BottomTabsControllerTest.java Прегледај датотеку

@@ -6,7 +6,6 @@ import android.widget.RelativeLayout;
6 6
 
7 7
 import com.reactnativenavigation.BaseTest;
8 8
 import com.reactnativenavigation.mocks.ImageLoaderMock;
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;
@@ -14,6 +13,7 @@ import com.reactnativenavigation.mocks.TopBarButtonCreatorMock;
14 13
 import com.reactnativenavigation.parse.Options;
15 14
 import com.reactnativenavigation.parse.params.Color;
16 15
 import com.reactnativenavigation.parse.params.Number;
16
+import com.reactnativenavigation.utils.CommandListenerAdapter;
17 17
 import com.reactnativenavigation.utils.ImageLoader;
18 18
 import com.reactnativenavigation.utils.OptionHelper;
19 19
 import com.reactnativenavigation.viewcontrollers.bottomtabs.BottomTabsController;
@@ -105,7 +105,7 @@ public class BottomTabsControllerTest extends BaseTest {
105 105
         assertThat(uut.findControllerById("123")).isNull();
106 106
         assertThat(uut.findControllerById(uut.getId())).isEqualTo(uut);
107 107
         StackController inner = createStack("inner");
108
-        inner.animatePush(child1, new MockPromise());
108
+        inner.animatePush(child1, new CommandListenerAdapter());
109 109
         assertThat(uut.findControllerById(child1.getId())).isNull();
110 110
         uut.setTabs(Collections.singletonList(inner));
111 111
         assertThat(uut.findControllerById(child1.getId())).isEqualTo(child1);
@@ -137,7 +137,7 @@ public class BottomTabsControllerTest extends BaseTest {
137 137
 
138 138
         StackController stack = spy(createStack("stack"));
139 139
         stack.ensureViewIsCreated();
140
-        stack.push(uut, new MockPromise());
140
+        stack.push(uut);
141 141
 
142 142
         child1.onViewAppeared();
143 143
         ArgumentCaptor<Options> optionsCaptor = ArgumentCaptor.forClass(Options.class);

+ 8
- 8
lib/android/app/src/test/java/com/reactnativenavigation/viewcontrollers/FloatingActionButtonTest.java Прегледај датотеку

@@ -81,25 +81,25 @@ public class FloatingActionButtonTest extends BaseTest {
81 81
 
82 82
     @Test
83 83
     public void showOnPush() {
84
-        stackController.push(childFab, new MockPromise());
84
+        stackController.push(childFab);
85 85
         childFab.onViewAppeared();
86 86
         assertThat(hasFab()).isTrue();
87 87
     }
88 88
 
89 89
     @Test
90 90
     public void hideOnPush() {
91
-        stackController.push(childFab, new MockPromise());
91
+        stackController.push(childFab);
92 92
         childFab.onViewAppeared();
93 93
         assertThat(hasFab()).isTrue();
94
-        stackController.push(childNoFab, new MockPromise());
94
+        stackController.push(childNoFab);
95 95
         childNoFab.onViewAppeared();
96 96
         assertThat(hasFab()).isFalse();
97 97
     }
98 98
 
99 99
     @Test
100 100
     public void hideOnPop() {
101
-        stackController.push(childNoFab, new MockPromise());
102
-        stackController.push(childFab, new MockPromise());
101
+        stackController.push(childNoFab);
102
+        stackController.push(childFab);
103 103
         childFab.onViewAppeared();
104 104
         assertThat(hasFab()).isTrue();
105 105
         stackController.pop(new MockPromise());
@@ -109,8 +109,8 @@ public class FloatingActionButtonTest extends BaseTest {
109 109
 
110 110
     @Test
111 111
     public void showOnPop() {
112
-        stackController.push(childFab, new MockPromise());
113
-        stackController.push(childNoFab, new MockPromise());
112
+        stackController.push(childFab);
113
+        stackController.push(childNoFab);
114 114
         childNoFab.onViewAppeared();
115 115
         assertThat(hasFab()).isFalse();
116 116
         stackController.pop(new MockPromise());
@@ -121,7 +121,7 @@ public class FloatingActionButtonTest extends BaseTest {
121 121
     @Test
122 122
     public void hasChildren() {
123 123
         childFab = new SimpleViewController(activity, "child1", getOptionsWithFabActions());
124
-        stackController.push(childFab, new MockPromise());
124
+        stackController.push(childFab);
125 125
         childFab.onViewAppeared();
126 126
         assertThat(hasFab()).isTrue();
127 127
         assertThat(containsActions()).isTrue();

+ 62
- 49
lib/android/app/src/test/java/com/reactnativenavigation/viewcontrollers/NavigatorTest.java Прегледај датотеку

@@ -13,6 +13,7 @@ import com.reactnativenavigation.mocks.TopBarBackgroundViewCreatorMock;
13 13
 import com.reactnativenavigation.mocks.TopBarButtonCreatorMock;
14 14
 import com.reactnativenavigation.parse.Options;
15 15
 import com.reactnativenavigation.parse.params.Text;
16
+import com.reactnativenavigation.utils.CommandListenerAdapter;
16 17
 import com.reactnativenavigation.utils.CompatUtils;
17 18
 import com.reactnativenavigation.utils.ImageLoader;
18 19
 import com.reactnativenavigation.utils.OptionHelper;
@@ -82,13 +83,13 @@ public class NavigatorTest extends BaseTest {
82 83
     @Test
83 84
     public void push() {
84 85
         StackController stackController = newStack();
85
-        stackController.animatePush(child1, new MockPromise());
86
+        stackController.animatePush(child1, new CommandListenerAdapter());
86 87
         uut.setRoot(stackController, new MockPromise());
87 88
 
88 89
         assertIsChildById(uut.getView(), stackController.getView());
89 90
         assertIsChildById(stackController.getView(), child1.getView());
90 91
 
91
-        uut.push(child1.getId(), child2, new MockPromise());
92
+        uut.push(child1.getId(), child2, new CommandListenerAdapter());
92 93
 
93 94
         assertIsChildById(uut.getView(), stackController.getView());
94 95
         assertIsChildById(stackController.getView(), child2.getView());
@@ -97,7 +98,7 @@ public class NavigatorTest extends BaseTest {
97 98
     @Test
98 99
     public void push_InvalidPushWithoutAStack_DoesNothing() {
99 100
         uut.setRoot(child1, new MockPromise());
100
-        uut.push(child1.getId(), child2, new MockPromise());
101
+        uut.push(child1.getId(), child2, new CommandListenerAdapter());
101 102
         assertIsChildById(uut.getView(), child1.getView());
102 103
     }
103 104
 
@@ -106,13 +107,13 @@ public class NavigatorTest extends BaseTest {
106 107
         BottomTabsController bottomTabsController = newTabs();
107 108
         StackController stack1 = newStack();
108 109
         StackController stack2 = newStack();
109
-        stack1.animatePush(child1, new MockPromise());
110
-        stack2.animatePush(child2, new MockPromise());
110
+        stack1.animatePush(child1, new CommandListenerAdapter());
111
+        stack2.animatePush(child2, new CommandListenerAdapter());
111 112
         bottomTabsController.setTabs(Arrays.asList(stack1, stack2));
112 113
         uut.setRoot(bottomTabsController, new MockPromise());
113 114
 
114 115
         SimpleViewController newChild = new SimpleViewController(activity, "new child", tabOptions);
115
-        uut.push(child2.getId(), newChild, new MockPromise());
116
+        uut.push(child2.getId(), newChild, new CommandListenerAdapter());
116 117
 
117 118
         assertThat(stack1.getChildControllers()).doesNotContain(newChild);
118 119
         assertThat(stack2.getChildControllers()).contains(newChild);
@@ -133,18 +134,19 @@ public class NavigatorTest extends BaseTest {
133 134
         StackController stack2 = newStack();
134 135
         bottomTabsController.setTabs(Arrays.asList(stack1, stack2));
135 136
         uut.setRoot(bottomTabsController, new MockPromise());
136
-        stack1.animatePush(child1, new MockPromise());
137
-        stack2.animatePush(child2, new MockPromise());
138
-        stack2.animatePush(child3, new MockPromise() {
137
+        stack1.animatePush(child1, new CommandListenerAdapter());
138
+        stack2.animatePush(child2, new CommandListenerAdapter());
139
+        stack2.animatePush(child3, new CommandListenerAdapter() {
139 140
             @Override
140
-            public void resolve(@Nullable Object value) {
141
-                stack2.animatePush(child4, new MockPromise() {
142
-                    @Override
143
-                    public void resolve(@Nullable Object value) {
144
-                        uut.pop("child4", new MockPromise());
145
-                        assertThat(stack2.getChildControllers()).containsOnly(child2, child3);
146
-                    }
147
-                });
141
+            public void onSuccess(String childId) {
142
+                stack2.animatePush(child4, new CommandListenerAdapter() {
143
+                            @Override
144
+                            public void onSuccess(String childId) {
145
+                                uut.pop("child4", new MockPromise());
146
+                                assertThat(stack2.getChildControllers()).containsOnly(child2, child3);
147
+                            }
148
+                        }
149
+                );
148 150
             }
149 151
         });
150 152
     }
@@ -154,10 +156,10 @@ public class NavigatorTest extends BaseTest {
154 156
         BottomTabsController bottomTabsController = newTabs();
155 157
         StackController stack1 = newStack();
156 158
         StackController stack2 = newStack();
157
-        stack1.animatePush(child1, new MockPromise());
158
-        stack2.animatePush(child2, new MockPromise());
159
-        stack2.animatePush(child3, new MockPromise());
160
-        stack2.animatePush(child4, new MockPromise());
159
+        stack1.animatePush(child1, new CommandListenerAdapter());
160
+        stack2.animatePush(child2, new CommandListenerAdapter());
161
+        stack2.animatePush(child3, new CommandListenerAdapter());
162
+        stack2.animatePush(child4, new CommandListenerAdapter());
161 163
         bottomTabsController.setTabs(Arrays.asList(stack1, stack2));
162 164
         uut.setRoot(bottomTabsController, new MockPromise());
163 165
 
@@ -174,13 +176,13 @@ public class NavigatorTest extends BaseTest {
174 176
         bottomTabsController.setTabs(Arrays.asList(stack1, stack2));
175 177
         uut.setRoot(bottomTabsController, new MockPromise());
176 178
 
177
-        stack1.animatePush(child1, new MockPromise());
178
-        stack2.animatePush(child2, new MockPromise());
179
-        stack2.animatePush(child3, new MockPromise());
180
-        stack2.animatePush(child4, new MockPromise());
181
-        stack2.animatePush(child5, new MockPromise() {
179
+        stack1.animatePush(child1, new CommandListenerAdapter());
180
+        stack2.animatePush(child2, new CommandListenerAdapter());
181
+        stack2.animatePush(child3, new CommandListenerAdapter());
182
+        stack2.animatePush(child4, new CommandListenerAdapter());
183
+        stack2.animatePush(child5, new CommandListenerAdapter() {
182 184
             @Override
183
-            public void resolve(@Nullable Object value) {
185
+            public void onSuccess(String childId) {
184 186
                 uut.popTo(child2.getId(), new MockPromise());
185 187
                 assertThat(stack2.getChildControllers()).containsOnly(child2);
186 188
             }
@@ -195,20 +197,31 @@ public class NavigatorTest extends BaseTest {
195 197
         bottomTabsController.setTabs(Arrays.asList(stack1, stack2));
196 198
         uut.setRoot(bottomTabsController, new MockPromise());
197 199
 
198
-        stack1.animatePush(child1, new MockPromise());
199
-        stack2.animatePush(child2, new MockPromise());
200
-        stack2.animatePush(child3, new MockPromise());
201
-        stack2.animatePush(child4, new MockPromise());
202
-        stack2.animatePush(child5, new MockPromise() {
200
+        stack1.animatePush(child1, new CommandListenerAdapter());
201
+        stack2.animatePush(child2, new CommandListenerAdapter());
202
+        stack2.animatePush(child3, new CommandListenerAdapter());
203
+        stack2.animatePush(child4, new CommandListenerAdapter());
204
+        stack2.animatePush(child5, new CommandListenerAdapter() {
203 205
             @Override
204
-            public void resolve(@Nullable Object value) {
206
+            public void onSuccess(String childId) {
205 207
                 uut.popToRoot(child3.getId(), new MockPromise());
206
-
207 208
                 assertThat(stack2.getChildControllers()).containsOnly(child2);
208 209
             }
209 210
         });
210 211
     }
211 212
 
213
+    @Test
214
+    public void setStackRoot() {
215
+        StackController stack = newStack();
216
+        uut.setRoot(stack, new MockPromise());
217
+
218
+        stack.animatePush(child1, new CommandListenerAdapter());
219
+        stack.animatePush(child2, new CommandListenerAdapter());
220
+        stack.setRoot(child3, new CommandListenerAdapter());
221
+
222
+        assertThat(stack.getChildControllers()).containsOnly(child3);
223
+    }
224
+
212 225
     @Test
213 226
     public void handleBack_DelegatesToRoot() {
214 227
         ViewController root = spy(child1);
@@ -259,15 +272,15 @@ public class NavigatorTest extends BaseTest {
259 272
     @Test
260 273
     public void push_Promise() {
261 274
         final StackController stackController = newStack();
262
-        stackController.animatePush(child1, new MockPromise());
275
+        stackController.animatePush(child1, new CommandListenerAdapter());
263 276
         uut.setRoot(stackController, new MockPromise());
264 277
 
265 278
         assertIsChildById(uut.getView(), stackController.getView());
266 279
         assertIsChildById(stackController.getView(), child1.getView());
267 280
 
268
-        uut.push(child1.getId(), child2, new MockPromise() {
281
+        uut.push(child1.getId(), child2, new CommandListenerAdapter() {
269 282
             @Override
270
-            public void resolve(@Nullable Object value) {
283
+            public void onSuccess(String childId) {
271 284
                 assertIsChildById(uut.getView(), stackController.getView());
272 285
                 assertIsChildById(stackController.getView(), child2.getView());
273 286
             }
@@ -277,9 +290,9 @@ public class NavigatorTest extends BaseTest {
277 290
     @Test
278 291
     public void push_InvalidPushWithoutAStack_DoesNothing_Promise() {
279 292
         uut.setRoot(child1, new MockPromise());
280
-        uut.push(child1.getId(), child2, new MockPromise() {
293
+        uut.push(child1.getId(), child2, new CommandListenerAdapter() {
281 294
             @Override
282
-            public void reject(String code, Throwable e) {
295
+            public void onError(String message) {
283 296
                 assertIsChildById(uut.getView(), child1.getView());
284 297
             }
285 298
         });
@@ -306,12 +319,12 @@ public class NavigatorTest extends BaseTest {
306 319
         bottomTabsController.setTabs(Arrays.asList(stack1, stack2));
307 320
         uut.setRoot(bottomTabsController, new MockPromise());
308 321
 
309
-        stack1.animatePush(child1, new MockPromise());
310
-        stack2.animatePush(child2, new MockPromise());
311
-        stack2.animatePush(child3, new MockPromise());
312
-        stack2.animatePush(child4, new MockPromise() {
322
+        stack1.animatePush(child1, new CommandListenerAdapter());
323
+        stack2.animatePush(child2, new CommandListenerAdapter());
324
+        stack2.animatePush(child3, new CommandListenerAdapter());
325
+        stack2.animatePush(child4, new CommandListenerAdapter() {
313 326
             @Override
314
-            public void resolve(@Nullable Object value) {
327
+            public void onSuccess(String childId) {
315 328
                 uut.pop("child4", new MockPromise());
316 329
                 assertThat(stack2.getChildControllers()).containsOnly(child2, child3);
317 330
             }
@@ -322,9 +335,9 @@ public class NavigatorTest extends BaseTest {
322 335
     public void pushIntoModal() {
323 336
         uut.setRoot(parentController, new MockPromise());
324 337
         StackController stackController = newStack();
325
-        stackController.push(child1, new MockPromise());
338
+        stackController.push(child1);
326 339
         uut.showModal(stackController, new MockPromise());
327
-        uut.push(stackController.getId(), child2, new MockPromise());
340
+        uut.push(stackController.getId(), child2, new CommandListenerAdapter());
328 341
         assertIsChildById(stackController.getView(), child2.getView());
329 342
     }
330 343
 
@@ -333,10 +346,10 @@ public class NavigatorTest extends BaseTest {
333 346
         StackController parent = newStack();
334 347
         parent.ensureViewIsCreated();
335 348
         uut.setRoot(parent, new MockPromise());
336
-        parent.push(parentController, new MockPromise());
349
+        parent.push(parentController);
337 350
 
338
-        parentController.push(child1, new MockPromise());
339
-        parentController.push(child2, new MockPromise());
351
+        parentController.push(child1);
352
+        parentController.push(child2);
340 353
         assertThat(parentController.getChildControllers().size()).isEqualTo(2);
341 354
         child1.ensureViewIsCreated();
342 355
         child2.ensureViewIsCreated();

+ 14
- 13
lib/android/app/src/test/java/com/reactnativenavigation/viewcontrollers/OptionsApplyingTest.java Прегледај датотеку

@@ -7,7 +7,6 @@ import android.view.View;
7 7
 import android.widget.RelativeLayout;
8 8
 
9 9
 import com.reactnativenavigation.BaseTest;
10
-import com.reactnativenavigation.mocks.MockPromise;
11 10
 import com.reactnativenavigation.mocks.TestComponentLayout;
12 11
 import com.reactnativenavigation.mocks.TestReactView;
13 12
 import com.reactnativenavigation.mocks.TitleBarReactViewCreatorMock;
@@ -20,6 +19,7 @@ import com.reactnativenavigation.parse.TopBarBackgroundOptions;
20 19
 import com.reactnativenavigation.parse.params.Bool;
21 20
 import com.reactnativenavigation.parse.params.Fraction;
22 21
 import com.reactnativenavigation.parse.params.Text;
22
+import com.reactnativenavigation.utils.CommandListenerAdapter;
23 23
 import com.reactnativenavigation.utils.ViewUtils;
24 24
 import com.reactnativenavigation.viewcontrollers.topbar.TopBarBackgroundViewController;
25 25
 import com.reactnativenavigation.viewcontrollers.topbar.TopBarController;
@@ -28,8 +28,6 @@ import com.reactnativenavigation.views.topbar.TopBarBackgroundView;
28 28
 import org.json.JSONObject;
29 29
 import org.junit.Test;
30 30
 
31
-import javax.annotation.Nullable;
32
-
33 31
 import static android.view.ViewGroup.LayoutParams.MATCH_PARENT;
34 32
 import static android.widget.RelativeLayout.BELOW;
35 33
 import static org.assertj.core.api.Java6Assertions.assertThat;
@@ -55,7 +53,8 @@ public class OptionsApplyingTest extends BaseTest {
55 53
                 (activity1, componentId, componentName) -> view,
56 54
                 initialNavigationOptions
57 55
         );
58
-        stackController = new StackController(activity, new TopBarButtonCreatorMock(), new TitleBarReactViewCreatorMock(), new TopBarBackgroundViewController(activity, new TopBarBackgroundViewCreatorMock()), new TopBarController(), "stack", new Options());
56
+        stackController =
57
+                new StackController(activity, new TopBarButtonCreatorMock(), new TitleBarReactViewCreatorMock(), new TopBarBackgroundViewController(activity, new TopBarBackgroundViewCreatorMock()), new TopBarController(), "stack", new Options());
59 58
         stackController.ensureViewIsCreated();
60 59
         uut.setParentController(stackController);
61 60
     }
@@ -72,8 +71,9 @@ public class OptionsApplyingTest extends BaseTest {
72 71
     @Test
73 72
     public void initialOptionsAppliedOnAppear() {
74 73
         uut.options.topBarOptions.title.text = new Text("the title");
75
-        StackController stackController = new StackController(activity, new TopBarButtonCreatorMock(), new TitleBarReactViewCreatorMock(), new TopBarBackgroundViewController(activity, new TopBarBackgroundViewCreatorMock()), new TopBarController(), "stackId", new Options());
76
-        stackController.animatePush(uut, new MockPromise() {});
74
+        StackController stackController =
75
+                new StackController(activity, new TopBarButtonCreatorMock(), new TitleBarReactViewCreatorMock(), new TopBarBackgroundViewController(activity, new TopBarBackgroundViewCreatorMock()), new TopBarController(), "stackId", new Options());
76
+        stackController.animatePush(uut, new CommandListenerAdapter());
77 77
         assertThat(stackController.getTopBar().getTitle()).isEmpty();
78 78
 
79 79
         uut.onViewAppeared();
@@ -118,9 +118,9 @@ public class OptionsApplyingTest extends BaseTest {
118 118
     @Test
119 119
     public void appliesTopBarTextColor() {
120 120
         assertThat(uut.initialOptions).isSameAs(initialNavigationOptions);
121
-        stackController.animatePush(uut, new MockPromise() {
121
+        stackController.animatePush(uut, new CommandListenerAdapter() {
122 122
             @Override
123
-            public void resolve(@Nullable Object value) {
123
+            public void onSuccess(String childId) {
124 124
                 Options opts = new Options();
125 125
                 opts.topBarOptions.title.text = new Text("the title");
126 126
                 opts.topBarOptions.title.color = new com.reactnativenavigation.parse.params.Color(Color.RED);
@@ -169,11 +169,12 @@ public class OptionsApplyingTest extends BaseTest {
169 169
         uut.options.topBarOptions.title.text = new Text("the title");
170 170
         uut.options.topBarOptions.drawBehind = new Bool(false);
171 171
         uut.ensureViewIsCreated();
172
-        stackController.animatePush(uut, new MockPromise() {
172
+        stackController.animatePush(uut, new CommandListenerAdapter() {
173 173
             @Override
174
-            public void resolve(@Nullable Object value) {
174
+            public void onSuccess(String childId) {
175 175
                 uut.onViewAppeared();
176
-                RelativeLayout.LayoutParams uutLayoutParams = (RelativeLayout.LayoutParams) uut.getComponent().asView().getLayoutParams();
176
+                RelativeLayout.LayoutParams uutLayoutParams =
177
+                        (RelativeLayout.LayoutParams) uut.getComponent().asView().getLayoutParams();
177 178
                 assertThat(uutLayoutParams.getRule(BELOW)).isNotEqualTo(0);
178 179
 
179 180
                 Options opts = new Options();
@@ -192,7 +193,7 @@ public class OptionsApplyingTest extends BaseTest {
192 193
         json.put("component", "someComponent");
193 194
         uut.options.topBarOptions.background = TopBarBackgroundOptions.parse(json);
194 195
         uut.ensureViewIsCreated();
195
-        stackController.push(uut, new MockPromise());
196
+        stackController.push(uut);
196 197
         uut.onViewAppeared();
197 198
 
198 199
         assertThat(((ColorDrawable) stackController.getTopBar().getTitleBar().getBackground()).getColor()).isEqualTo(Color.TRANSPARENT);
@@ -205,7 +206,7 @@ public class OptionsApplyingTest extends BaseTest {
205 206
         json.put("text", "sub");
206 207
         uut.options.topBarOptions.subtitle = SubtitleOptions.parse(new TypefaceLoaderMock(), json);
207 208
         uut.ensureViewIsCreated();
208
-        stackController.push(uut, new MockPromise());
209
+        stackController.push(uut);
209 210
         uut.onViewAppeared();
210 211
 
211 212
         assertThat(stackController.getTopBar().getTitleBar().getSubtitle()).isEqualTo("sub");

+ 4
- 4
lib/android/app/src/test/java/com/reactnativenavigation/viewcontrollers/ParentControllerTest.java Прегледај датотеку

@@ -6,13 +6,13 @@ import android.view.ViewGroup;
6 6
 import android.widget.FrameLayout;
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;
13 12
 import com.reactnativenavigation.mocks.TopBarButtonCreatorMock;
14 13
 import com.reactnativenavigation.parse.Options;
15 14
 import com.reactnativenavigation.parse.params.Text;
15
+import com.reactnativenavigation.utils.CommandListenerAdapter;
16 16
 import com.reactnativenavigation.viewcontrollers.topbar.TopBarBackgroundViewController;
17 17
 import com.reactnativenavigation.viewcontrollers.topbar.TopBarController;
18 18
 import com.reactnativenavigation.views.ReactComponent;
@@ -95,8 +95,8 @@ public class ParentControllerTest extends BaseTest {
95 95
         StackController stackController = createStack();
96 96
         SimpleViewController child1 = new SimpleViewController(activity, "child1", new Options());
97 97
         SimpleViewController child2 = new SimpleViewController(activity, "child2", new Options());
98
-        stackController.animatePush(child1, new MockPromise());
99
-        stackController.animatePush(child2, new MockPromise());
98
+        stackController.animatePush(child1, new CommandListenerAdapter());
99
+        stackController.animatePush(child2, new CommandListenerAdapter());
100 100
         children.add(stackController);
101 101
 
102 102
         assertThat(uut.findControllerById("child2")).isEqualTo(child2);
@@ -116,7 +116,7 @@ public class ParentControllerTest extends BaseTest {
116 116
     public void optionsAreClearedWhenChildIsAppeared() {
117 117
         StackController stackController = spy(createStack());
118 118
         SimpleViewController child1 = new SimpleViewController(activity, "child1", new Options());
119
-        stackController.animatePush(child1, new MockPromise());
119
+        stackController.animatePush(child1, new CommandListenerAdapter());
120 120
 
121 121
         child1.onViewAppeared();
122 122
         verify(stackController, times(1)).clearOptions();

+ 121
- 91
lib/android/app/src/test/java/com/reactnativenavigation/viewcontrollers/StackControllerTest.java Прегледај датотеку

@@ -15,6 +15,7 @@ import com.reactnativenavigation.parse.NestedAnimationsOptions;
15 15
 import com.reactnativenavigation.parse.Options;
16 16
 import com.reactnativenavigation.parse.params.Bool;
17 17
 import com.reactnativenavigation.parse.params.Text;
18
+import com.reactnativenavigation.utils.CommandListenerAdapter;
18 19
 import com.reactnativenavigation.utils.ViewHelper;
19 20
 import com.reactnativenavigation.viewcontrollers.topbar.TopBarBackgroundViewController;
20 21
 import com.reactnativenavigation.viewcontrollers.topbar.TopBarController;
@@ -65,9 +66,9 @@ public class StackControllerTest extends BaseTest {
65 66
     @Test
66 67
     public void holdsAStackOfViewControllers() {
67 68
         assertThat(uut.isEmpty()).isTrue();
68
-        uut.animatePush(child1, new MockPromise());
69
-        uut.animatePush(child2, new MockPromise());
70
-        uut.animatePush(child3, new MockPromise());
69
+        uut.animatePush(child1, new CommandListenerAdapter());
70
+        uut.animatePush(child2, new CommandListenerAdapter());
71
+        uut.animatePush(child3, new CommandListenerAdapter());
71 72
         assertThat(uut.peek()).isEqualTo(child3);
72 73
         assertContainsOnlyId(child1.getId(), child2.getId(), child3.getId());
73 74
     }
@@ -75,16 +76,42 @@ public class StackControllerTest extends BaseTest {
75 76
     @Test
76 77
     public void push() {
77 78
         assertThat(uut.isEmpty()).isTrue();
78
-        uut.animatePush(child1, new MockPromise());
79
+        uut.animatePush(child1, new CommandListenerAdapter());
79 80
         assertContainsOnlyId(child1.getId());
80 81
     }
81 82
 
83
+    @Test
84
+    public void animateSetRoot() {
85
+        assertThat(uut.isEmpty()).isTrue();
86
+        uut.push(child1, new CommandListenerAdapter());
87
+        uut.push(child2, new CommandListenerAdapter());
88
+        uut.animateSetRoot(child3, new CommandListenerAdapter() {
89
+            @Override
90
+            public void onSuccess(String childId) {
91
+                assertContainsOnlyId(child3.getId());
92
+            }
93
+        });
94
+    }
95
+
96
+    @Test
97
+    public void setRoot() {
98
+        assertThat(uut.isEmpty()).isTrue();
99
+        uut.push(child1, new CommandListenerAdapter());
100
+        uut.push(child2, new CommandListenerAdapter());
101
+        uut.setRoot(child3, new CommandListenerAdapter() {
102
+            @Override
103
+            public void onSuccess(String childId) {
104
+                assertContainsOnlyId(child3.getId());
105
+            }
106
+        });
107
+    }
108
+
82 109
     @Test
83 110
     public void pop() {
84
-        uut.animatePush(child1, new MockPromise());
85
-        uut.animatePush(child2, new MockPromise() {
111
+        uut.animatePush(child1, new CommandListenerAdapter());
112
+        uut.animatePush(child2, new CommandListenerAdapter() {
86 113
             @Override
87
-            public void resolve(@Nullable Object value) {
114
+            public void onSuccess(String childId) {
88 115
                 assertContainsOnlyId(child2.getId(), child1.getId());
89 116
                 uut.pop(new MockPromise());
90 117
                 assertContainsOnlyId(child1.getId());
@@ -94,10 +121,10 @@ public class StackControllerTest extends BaseTest {
94 121
 
95 122
     @Test
96 123
     public void pop_appliesOptionsAfterPop() {
97
-        uut.animatePush(child1, new MockPromise());
98
-        uut.animatePush(child2, new MockPromise() {
124
+        uut.animatePush(child1, new CommandListenerAdapter());
125
+        uut.animatePush(child2, new CommandListenerAdapter() {
99 126
             @Override
100
-            public void resolve(@Nullable Object value) {
127
+            public void onSuccess(String childId) {
101 128
                 uut.pop(new MockPromise());
102 129
                 verify(uut, times(1)).applyChildOptions(uut.options, eq((ReactComponent) child1.getView()));
103 130
             }
@@ -107,18 +134,19 @@ public class StackControllerTest extends BaseTest {
107 134
     @Test
108 135
     public void pop_layoutHandlesChildWillDisappear() {
109 136
         final StackLayout[] stackLayout = new StackLayout[1];
110
-        uut = new StackController(activity, new TopBarButtonCreatorMock(), new TitleBarReactViewCreatorMock(), new TopBarBackgroundViewController(activity, new TopBarBackgroundViewCreatorMock()), new TopBarController(), "uut", new Options()) {
111
-            @NonNull
112
-            @Override
113
-            protected StackLayout createView() {
114
-                stackLayout[0] = spy(super.createView());
115
-                return stackLayout[0];
116
-            }
117
-        };
118
-        uut.push(child1, new MockPromise());
119
-        uut.animatePush(child2, new MockPromise() {
137
+        uut =
138
+                new StackController(activity, new TopBarButtonCreatorMock(), new TitleBarReactViewCreatorMock(), new TopBarBackgroundViewController(activity, new TopBarBackgroundViewCreatorMock()), new TopBarController(), "uut", new Options()) {
139
+                    @NonNull
140
+                    @Override
141
+                    protected StackLayout createView() {
142
+                        stackLayout[0] = spy(super.createView());
143
+                        return stackLayout[0];
144
+                    }
145
+                };
146
+        uut.push(child1, new CommandListenerAdapter());
147
+        uut.animatePush(child2, new CommandListenerAdapter() {
120 148
             @Override
121
-            public void resolve(@Nullable Object value) {
149
+            public void onSuccess(String childId) {
122 150
                 uut.animatePop(new MockPromise() {
123 151
                     @Override
124 152
                     public void resolve(@Nullable Object value) {
@@ -135,7 +163,7 @@ public class StackControllerTest extends BaseTest {
135 163
         assertThat(uut.peek()).isNull();
136 164
         assertThat(uut.size()).isZero();
137 165
         assertThat(uut.isEmpty()).isTrue();
138
-        uut.animatePush(child1, new MockPromise());
166
+        uut.animatePush(child1, new CommandListenerAdapter());
139 167
         assertThat(uut.peek()).isEqualTo(child1);
140 168
         assertThat(uut.size()).isEqualTo(1);
141 169
         assertThat(uut.isEmpty()).isFalse();
@@ -144,11 +172,11 @@ public class StackControllerTest extends BaseTest {
144 172
     @Test
145 173
     public void pushAssignsRefToSelfOnPushedController() {
146 174
         assertThat(child1.getParentController()).isNull();
147
-        uut.animatePush(child1, new MockPromise());
175
+        uut.animatePush(child1, new CommandListenerAdapter());
148 176
         assertThat(child1.getParentController()).isEqualTo(uut);
149 177
 
150 178
         StackController anotherNavController = createStackController("another");
151
-        anotherNavController.animatePush(child2, new MockPromise());
179
+        anotherNavController.animatePush(child2, new CommandListenerAdapter());
152 180
         assertThat(child2.getParentController()).isEqualTo(anotherNavController);
153 181
     }
154 182
 
@@ -157,13 +185,13 @@ public class StackControllerTest extends BaseTest {
157 185
         assertThat(uut.isEmpty()).isTrue();
158 186
         assertThat(uut.handleBack()).isFalse();
159 187
 
160
-        uut.animatePush(child1, new MockPromise());
188
+        uut.animatePush(child1, new CommandListenerAdapter());
161 189
         assertThat(uut.size()).isEqualTo(1);
162 190
         assertThat(uut.handleBack()).isFalse();
163 191
 
164
-        uut.animatePush(child2, new MockPromise() {
192
+        uut.animatePush(child2, new CommandListenerAdapter() {
165 193
             @Override
166
-            public void resolve(@Nullable Object value) {
194
+            public void onSuccess(String childId) {
167 195
                 assertThat(uut.size()).isEqualTo(2);
168 196
                 assertThat(uut.handleBack()).isTrue();
169 197
 
@@ -179,7 +207,7 @@ public class StackControllerTest extends BaseTest {
179 207
         uut.pop(new MockPromise());
180 208
         assertThat(uut.isEmpty()).isTrue();
181 209
 
182
-        uut.animatePush(child1, new MockPromise());
210
+        uut.animatePush(child1, new CommandListenerAdapter());
183 211
         uut.pop(new MockPromise());
184 212
         assertContainsOnlyId(child1.getId());
185 213
     }
@@ -188,10 +216,10 @@ public class StackControllerTest extends BaseTest {
188 216
     public void canPopWhenSizeIsMoreThanOne() {
189 217
         assertThat(uut.isEmpty()).isTrue();
190 218
         assertThat(uut.canPop()).isFalse();
191
-        uut.animatePush(child1, new MockPromise());
219
+        uut.animatePush(child1, new CommandListenerAdapter());
192 220
         assertContainsOnlyId(child1.getId());
193 221
         assertThat(uut.canPop()).isFalse();
194
-        uut.animatePush(child2, new MockPromise());
222
+        uut.animatePush(child2, new CommandListenerAdapter());
195 223
         assertContainsOnlyId(child1.getId(), child2.getId());
196 224
         assertThat(uut.canPop()).isTrue();
197 225
     }
@@ -199,18 +227,18 @@ public class StackControllerTest extends BaseTest {
199 227
     @Test
200 228
     public void pushAddsToViewTree() {
201 229
         assertThat(uut.getView().findViewById(child1.getView().getId())).isNull();
202
-        uut.animatePush(child1, new MockPromise());
230
+        uut.animatePush(child1, new CommandListenerAdapter());
203 231
         assertThat(uut.getView().findViewById(child1.getView().getId())).isNotNull();
204 232
     }
205 233
 
206 234
     @Test
207 235
     public void pushRemovesPreviousFromTree() {
208 236
         assertThat(uut.getView().findViewById(child1.getView().getId())).isNull();
209
-        uut.animatePush(child1, new MockPromise());
237
+        uut.animatePush(child1, new CommandListenerAdapter());
210 238
         assertThat(uut.getView().findViewById(child1.getView().getId())).isNotNull();
211
-        uut.animatePush(child2, new MockPromise() {
239
+        uut.animatePush(child2, new CommandListenerAdapter() {
212 240
             @Override
213
-            public void resolve(@Nullable Object value) {
241
+            public void onSuccess(String childId) {
214 242
                 assertThat(uut.getView().findViewById(child1.getView().getId())).isNull();
215 243
                 assertThat(uut.getView().findViewById(child2.getView().getId())).isNotNull();
216 244
             }
@@ -222,10 +250,10 @@ public class StackControllerTest extends BaseTest {
222 250
         final View child2View = child2.getView();
223 251
         final View child1View = child1.getView();
224 252
 
225
-        uut.animatePush(child1, new MockPromise());
226
-        uut.animatePush(child2, new MockPromise() {
253
+        uut.animatePush(child1, new CommandListenerAdapter());
254
+        uut.animatePush(child2, new CommandListenerAdapter() {
227 255
             @Override
228
-            public void resolve(@Nullable Object value) {
256
+            public void onSuccess(String childId) {
229 257
                 assertIsChildById(uut.getView(), child2View);
230 258
                 assertNotChildOf(uut.getView(), child1View);
231 259
                 uut.pop(new MockPromise());
@@ -237,10 +265,10 @@ public class StackControllerTest extends BaseTest {
237 265
 
238 266
     @Test
239 267
     public void popSpecificWhenTopIsRegularPop() {
240
-        uut.animatePush(child1, new MockPromise());
241
-        uut.animatePush(child2, new MockPromise() {
268
+        uut.animatePush(child1, new CommandListenerAdapter());
269
+        uut.animatePush(child2, new CommandListenerAdapter() {
242 270
             @Override
243
-            public void resolve(@Nullable Object value) {
271
+            public void onSuccess(String childId) {
244 272
                 uut.popSpecific(child2, new MockPromise() {
245 273
                     @Override
246 274
                     public void resolve(@Nullable Object value) {
@@ -254,8 +282,8 @@ public class StackControllerTest extends BaseTest {
254 282
 
255 283
     @Test
256 284
     public void popSpecificDeepInStack() {
257
-        uut.animatePush(child1, new MockPromise());
258
-        uut.animatePush(child2, new MockPromise());
285
+        uut.animatePush(child1, new CommandListenerAdapter());
286
+        uut.animatePush(child2, new CommandListenerAdapter());
259 287
         assertIsChildById(uut.getView(), child2.getView());
260 288
         uut.popSpecific(child1, new MockPromise());
261 289
         assertContainsOnlyId(child2.getId());
@@ -264,11 +292,11 @@ public class StackControllerTest extends BaseTest {
264 292
 
265 293
     @Test
266 294
     public void popTo_PopsTopUntilControllerIsNewTop() {
267
-        uut.animatePush(child1, new MockPromise());
268
-        uut.animatePush(child2, new MockPromise());
269
-        uut.animatePush(child3, new MockPromise() {
295
+        uut.animatePush(child1, new CommandListenerAdapter());
296
+        uut.animatePush(child2, new CommandListenerAdapter());
297
+        uut.animatePush(child3, new CommandListenerAdapter() {
270 298
             @Override
271
-            public void resolve(@Nullable Object value) {
299
+            public void onSuccess(String childId) {
272 300
                 assertThat(uut.size()).isEqualTo(3);
273 301
                 assertThat(uut.peek()).isEqualTo(child3);
274 302
 
@@ -282,8 +310,8 @@ public class StackControllerTest extends BaseTest {
282 310
 
283 311
     @Test
284 312
     public void popTo_NotAChildOfThisStack_DoesNothing() {
285
-        uut.animatePush(child1, new MockPromise());
286
-        uut.animatePush(child3, new MockPromise());
313
+        uut.animatePush(child1, new CommandListenerAdapter());
314
+        uut.animatePush(child3, new CommandListenerAdapter());
287 315
         assertThat(uut.size()).isEqualTo(2);
288 316
         uut.popTo(child2, new MockPromise());
289 317
         assertThat(uut.size()).isEqualTo(2);
@@ -291,11 +319,11 @@ public class StackControllerTest extends BaseTest {
291 319
 
292 320
     @Test
293 321
     public void popToRoot_PopsEverythingAboveFirstController() {
294
-        uut.animatePush(child1, new MockPromise());
295
-        uut.animatePush(child2, new MockPromise());
296
-        uut.animatePush(child3, new MockPromise() {
322
+        uut.animatePush(child1, new CommandListenerAdapter());
323
+        uut.animatePush(child2, new CommandListenerAdapter());
324
+        uut.animatePush(child3, new CommandListenerAdapter() {
297 325
             @Override
298
-            public void resolve(@Nullable Object value) {
326
+            public void onSuccess(String childId) {
299 327
                 assertThat(uut.size()).isEqualTo(3);
300 328
                 assertThat(uut.peek()).isEqualTo(child3);
301 329
 
@@ -321,15 +349,15 @@ public class StackControllerTest extends BaseTest {
321 349
     public void findControllerById_ReturnsSelfOrChildrenById() {
322 350
         assertThat(uut.findControllerById("123")).isNull();
323 351
         assertThat(uut.findControllerById(uut.getId())).isEqualTo(uut);
324
-        uut.animatePush(child1, new MockPromise());
352
+        uut.animatePush(child1, new CommandListenerAdapter());
325 353
         assertThat(uut.findControllerById(child1.getId())).isEqualTo(child1);
326 354
     }
327 355
 
328 356
     @Test
329 357
     public void findControllerById_Deeply() {
330 358
         StackController stack = createStackController("another");
331
-        stack.animatePush(child2, new MockPromise());
332
-        uut.animatePush(stack, new MockPromise());
359
+        stack.animatePush(child2, new CommandListenerAdapter());
360
+        uut.animatePush(stack, new CommandListenerAdapter());
333 361
         assertThat(uut.findControllerById(child2.getId())).isEqualTo(child2);
334 362
     }
335 363
 
@@ -338,11 +366,11 @@ public class StackControllerTest extends BaseTest {
338 366
         child1 = spy(child1);
339 367
         child2 = spy(child2);
340 368
         child3 = spy(child3);
341
-        uut.animatePush(child1, new MockPromise());
342
-        uut.animatePush(child2, new MockPromise());
343
-        uut.animatePush(child3, new MockPromise() {
369
+        uut.animatePush(child1, new CommandListenerAdapter());
370
+        uut.animatePush(child2, new CommandListenerAdapter());
371
+        uut.animatePush(child3, new CommandListenerAdapter() {
344 372
             @Override
345
-            public void resolve(@Nullable Object value) {
373
+            public void onSuccess(String childId) {
346 374
                 verify(child3, times(0)).destroy();
347 375
                 uut.pop(new MockPromise());
348 376
                 verify(child3, times(1)).destroy();
@@ -354,8 +382,8 @@ public class StackControllerTest extends BaseTest {
354 382
     public void pop_callWillAppearWillDisappear() {
355 383
         child1 = spy(child1);
356 384
         child2 = spy(child2);
357
-        uut.push(child1, new MockPromise());
358
-        uut.push(child2, new MockPromise());
385
+        uut.push(child1, new CommandListenerAdapter());
386
+        uut.push(child2, new CommandListenerAdapter());
359 387
         uut.pop(new MockPromise());
360 388
         verify(child1, times(1)).onViewWillAppear();
361 389
         verify(child2, times(1)).onViewWillDisappear();
@@ -368,11 +396,11 @@ public class StackControllerTest extends BaseTest {
368 396
         child1.options.topBarOptions.visible = new Bool(false);
369 397
         child1.options.topBarOptions.animate = new Bool(false);
370 398
         child2.options.topBarOptions.visible = new Bool(true);
371
-        uut.push(child1, new MockPromise());
399
+        uut.push(child1, new CommandListenerAdapter());
372 400
         child1.onViewAppeared();
373 401
 
374 402
         assertThat(uut.getTopBar().getVisibility()).isEqualTo(View.GONE);
375
-        uut.push(child2, new MockPromise());
403
+        uut.push(child2, new CommandListenerAdapter());
376 404
         uut.animatePop(new MockPromise() {
377 405
             @Override
378 406
             public void resolve(@Nullable Object value) {
@@ -386,9 +414,9 @@ public class StackControllerTest extends BaseTest {
386 414
         child1 = spy(child1);
387 415
         child2 = spy(child2);
388 416
         child3 = spy(child3);
389
-        uut.animatePush(child1, new MockPromise());
390
-        uut.animatePush(child2, new MockPromise());
391
-        uut.animatePush(child3, new MockPromise());
417
+        uut.animatePush(child1, new CommandListenerAdapter());
418
+        uut.animatePush(child2, new CommandListenerAdapter());
419
+        uut.animatePush(child3, new CommandListenerAdapter());
392 420
 
393 421
         verify(child2, times(0)).destroy();
394 422
         uut.popSpecific(child2, new MockPromise());
@@ -400,11 +428,11 @@ public class StackControllerTest extends BaseTest {
400 428
         child1 = spy(child1);
401 429
         child2 = spy(child2);
402 430
         child3 = spy(child3);
403
-        uut.animatePush(child1, new MockPromise());
404
-        uut.animatePush(child2, new MockPromise());
405
-        uut.animatePush(child3, new MockPromise() {
431
+        uut.animatePush(child1, new CommandListenerAdapter());
432
+        uut.animatePush(child2, new CommandListenerAdapter());
433
+        uut.animatePush(child3, new CommandListenerAdapter() {
406 434
             @Override
407
-            public void resolve(@Nullable Object value) {
435
+            public void onSuccess(String childId) {
408 436
                 verify(child2, times(0)).destroy();
409 437
                 verify(child3, times(0)).destroy();
410 438
 
@@ -423,7 +451,7 @@ public class StackControllerTest extends BaseTest {
423 451
     public void stackCanBePushed() {
424 452
         StackController parent = createStackController("someStack");
425 453
         parent.ensureViewIsCreated();
426
-        parent.push(uut, new MockPromise());
454
+        parent.push(uut, new CommandListenerAdapter());
427 455
         uut.onViewAppeared();
428 456
         assertThat(parent.getView().getChildAt(1)).isEqualTo(uut.getView());
429 457
     }
@@ -432,12 +460,12 @@ public class StackControllerTest extends BaseTest {
432 460
     public void applyOptions_applyOnlyOnFirstStack() {
433 461
         StackController parent = spy(createStackController("someStack"));
434 462
         parent.ensureViewIsCreated();
435
-        parent.push(uut, new MockPromise());
463
+        parent.push(uut, new CommandListenerAdapter());
436 464
 
437 465
         Options childOptions = new Options();
438 466
         childOptions.topBarOptions.title.text = new Text("Something");
439 467
         child1.options = childOptions;
440
-        uut.push(child1, new MockPromise());
468
+        uut.push(child1, new CommandListenerAdapter());
441 469
         child1.ensureViewIsCreated();
442 470
         child1.onViewAppeared();
443 471
 
@@ -450,7 +478,7 @@ public class StackControllerTest extends BaseTest {
450 478
     @Test
451 479
     public void applyOptions_topTabsAreNotVisibleIfNoTabsAreDefined() {
452 480
         uut.ensureViewIsCreated();
453
-        uut.push(child1, new MockPromise());
481
+        uut.push(child1, new CommandListenerAdapter());
454 482
         child1.ensureViewIsCreated();
455 483
         child1.onViewAppeared();
456 484
         assertThat(ViewHelper.isVisible(uut.getTopBar().getTopTabs())).isFalse();
@@ -459,7 +487,7 @@ public class StackControllerTest extends BaseTest {
459 487
     @Test
460 488
     public void buttonPressInvokedOnCurrentStack() {
461 489
         uut.ensureViewIsCreated();
462
-        uut.push(child1, new MockPromise());
490
+        uut.push(child1, new CommandListenerAdapter());
463 491
         uut.sendOnNavigationButtonPressed("btn1");
464 492
         verify(child1, times(1)).sendOnNavigationButtonPressed("btn1");
465 493
     }
@@ -467,14 +495,15 @@ public class StackControllerTest extends BaseTest {
467 495
     @Test
468 496
     public void mergeChildOptions_updatesViewWithNewOptions() {
469 497
         final StackLayout[] stackLayout = new StackLayout[1];
470
-        StackController uut = new StackController(activity, new TopBarButtonCreatorMock(), new TitleBarReactViewCreatorMock(), new TopBarBackgroundViewController(activity, new TopBarBackgroundViewCreatorMock()), new TopBarController(), "stack", new Options()) {
471
-            @NonNull
472
-            @Override
473
-            protected StackLayout createView() {
474
-                stackLayout[0] = spy(super.createView());
475
-                return stackLayout[0];
476
-            }
477
-        };
498
+        StackController uut =
499
+                new StackController(activity, new TopBarButtonCreatorMock(), new TitleBarReactViewCreatorMock(), new TopBarBackgroundViewController(activity, new TopBarBackgroundViewCreatorMock()), new TopBarController(), "stack", new Options()) {
500
+                    @NonNull
501
+                    @Override
502
+                    protected StackLayout createView() {
503
+                        stackLayout[0] = spy(super.createView());
504
+                        return stackLayout[0];
505
+                    }
506
+                };
478 507
         Options optionsToMerge = new Options();
479 508
         Component component = mock(Component.class);
480 509
         uut.mergeChildOptions(optionsToMerge, component);
@@ -484,14 +513,15 @@ public class StackControllerTest extends BaseTest {
484 513
     @Test
485 514
     public void mergeChildOptions_updatesParentControllerWithNewOptions() {
486 515
         final StackLayout[] stackLayout = new StackLayout[1];
487
-        StackController uut = new StackController(activity, new TopBarButtonCreatorMock(), new TitleBarReactViewCreatorMock(), new TopBarBackgroundViewController(activity, new TopBarBackgroundViewCreatorMock()), new TopBarController(), "stack", new Options()) {
488
-            @NonNull
489
-            @Override
490
-            protected StackLayout createView() {
491
-                stackLayout[0] = spy(super.createView());
492
-                return stackLayout[0];
493
-            }
494
-        };
516
+        StackController uut =
517
+                new StackController(activity, new TopBarButtonCreatorMock(), new TitleBarReactViewCreatorMock(), new TopBarBackgroundViewController(activity, new TopBarBackgroundViewCreatorMock()), new TopBarController(), "stack", new Options()) {
518
+                    @NonNull
519
+                    @Override
520
+                    protected StackLayout createView() {
521
+                        stackLayout[0] = spy(super.createView());
522
+                        return stackLayout[0];
523
+                    }
524
+                };
495 525
         ParentController parentController = Mockito.mock(ParentController.class);
496 526
         uut.setParentController(parentController);
497 527
         Options optionsToMerge = new Options();

+ 3
- 3
lib/android/app/src/test/java/com/reactnativenavigation/viewcontrollers/TopTabsViewControllerTest.java Прегледај датотеку

@@ -65,7 +65,7 @@ public class TopTabsViewControllerTest extends BaseTest {
65 65
         tabControllers.forEach(viewController -> viewController.setParentController(uut));
66 66
 
67 67
         parentController = spy(createStackController("stackId"));
68
-        parentController.push(uut, new MockPromise());
68
+        parentController.push(uut);
69 69
         uut.setParentController(parentController);
70 70
     }
71 71
 
@@ -232,8 +232,8 @@ public class TopTabsViewControllerTest extends BaseTest {
232 232
                 new TestComponentViewCreator(),
233 233
                 new Options()
234 234
         );
235
-        stackController.push(first, new MockPromise());
236
-        stackController.push(uut, new MockPromise());
235
+        stackController.push(first);
236
+        stackController.push(uut);
237 237
 
238 238
         first.ensureViewIsCreated();
239 239
         uut.ensureViewIsCreated();

+ 2
- 2
lib/android/app/src/test/java/com/reactnativenavigation/viewcontrollers/ViewControllerTest.java Прегледај датотеку

@@ -7,12 +7,12 @@ import android.widget.FrameLayout;
7 7
 import android.widget.LinearLayout;
8 8
 
9 9
 import com.reactnativenavigation.BaseTest;
10
-import com.reactnativenavigation.mocks.MockPromise;
11 10
 import com.reactnativenavigation.mocks.SimpleViewController;
12 11
 import com.reactnativenavigation.mocks.TitleBarReactViewCreatorMock;
13 12
 import com.reactnativenavigation.mocks.TopBarBackgroundViewCreatorMock;
14 13
 import com.reactnativenavigation.mocks.TopBarButtonCreatorMock;
15 14
 import com.reactnativenavigation.parse.Options;
15
+import com.reactnativenavigation.utils.CommandListenerAdapter;
16 16
 import com.reactnativenavigation.viewcontrollers.topbar.TopBarBackgroundViewController;
17 17
 import com.reactnativenavigation.viewcontrollers.topbar.TopBarController;
18 18
 
@@ -71,7 +71,7 @@ public class ViewControllerTest extends BaseTest {
71 71
     public void holdsAReferenceToStackControllerOrNull() {
72 72
         assertThat(uut.getParentController()).isNull();
73 73
         StackController nav = new StackController(activity, new TopBarButtonCreatorMock(), new TitleBarReactViewCreatorMock(), new TopBarBackgroundViewController(activity, new TopBarBackgroundViewCreatorMock()), new TopBarController(), "stack", new Options());
74
-        nav.animatePush(uut, new MockPromise());
74
+        nav.animatePush(uut, new CommandListenerAdapter());
75 75
         assertThat(uut.getParentController()).isEqualTo(nav);
76 76
     }
77 77