Browse Source

Unmount title view when corresponding child component is unmounted (#3759)

Unmount Title component only when related child component is destroyed

Currently TopBar title component, background and buttons are unmounted when a new screen is pushed to the stack.
This causes a bug when props are passed to these components as props are cleared when child components unmount.

This commit fixes this bug for title components.
Guy Carmeli 6 years ago
parent
commit
24ec70db15
No account linked to committer's email address
25 changed files with 247 additions and 177 deletions
  1. 1
    3
      lib/android/app/src/main/java/com/reactnativenavigation/parse/LayoutFactory.java
  2. 58
    6
      lib/android/app/src/main/java/com/reactnativenavigation/presentation/StackOptionsPresenter.java
  3. 7
    1
      lib/android/app/src/main/java/com/reactnativenavigation/viewcontrollers/ComponentViewController.java
  4. 5
    1
      lib/android/app/src/main/java/com/reactnativenavigation/viewcontrollers/ParentController.java
  5. 2
    2
      lib/android/app/src/main/java/com/reactnativenavigation/viewcontrollers/SideMenuController.java
  6. 6
    2
      lib/android/app/src/main/java/com/reactnativenavigation/viewcontrollers/ViewController.java
  7. 2
    2
      lib/android/app/src/main/java/com/reactnativenavigation/viewcontrollers/bottomtabs/BottomTabsController.java
  8. 9
    7
      lib/android/app/src/main/java/com/reactnativenavigation/viewcontrollers/stack/StackController.java
  9. 0
    13
      lib/android/app/src/main/java/com/reactnativenavigation/viewcontrollers/stack/StackControllerBuilder.java
  10. 4
    5
      lib/android/app/src/main/java/com/reactnativenavigation/viewcontrollers/topbar/TopBarController.java
  11. 4
    4
      lib/android/app/src/main/java/com/reactnativenavigation/viewcontrollers/toptabs/TopTabsController.java
  12. 4
    5
      lib/android/app/src/main/java/com/reactnativenavigation/views/StackLayout.java
  13. 13
    24
      lib/android/app/src/main/java/com/reactnativenavigation/views/titlebar/TitleBar.java
  14. 7
    8
      lib/android/app/src/main/java/com/reactnativenavigation/views/topbar/TopBar.java
  15. 6
    0
      lib/android/app/src/test/java/com/reactnativenavigation/BaseTest.java
  16. 3
    5
      lib/android/app/src/test/java/com/reactnativenavigation/TestUtils.java
  17. 7
    1
      lib/android/app/src/test/java/com/reactnativenavigation/mocks/SimpleViewController.java
  18. 2
    1
      lib/android/app/src/test/java/com/reactnativenavigation/viewcontrollers/BottomTabsControllerTest.java
  19. 3
    5
      lib/android/app/src/test/java/com/reactnativenavigation/viewcontrollers/OptionsApplyingTest.java
  20. 71
    3
      lib/android/app/src/test/java/com/reactnativenavigation/viewcontrollers/StackOptionsPresenterTest.java
  21. 11
    45
      lib/android/app/src/test/java/com/reactnativenavigation/viewcontrollers/TitleBarTest.java
  22. 5
    7
      lib/android/app/src/test/java/com/reactnativenavigation/viewcontrollers/TopBarControllerTest.java
  23. 13
    10
      lib/android/app/src/test/java/com/reactnativenavigation/viewcontrollers/stack/StackControllerTest.java
  24. 2
    3
      lib/android/app/src/test/java/com/reactnativenavigation/views/TopBarBackgroundComponentTest.java
  25. 2
    14
      lib/android/app/src/test/java/com/reactnativenavigation/views/TopBarTest.java

+ 1
- 3
lib/android/app/src/main/java/com/reactnativenavigation/parse/LayoutFactory.java View File

@@ -162,13 +162,11 @@ public class LayoutFactory {
162 162
                 .setChildren(createChildren(node.children))
163 163
                 .setChildRegistry(childRegistry)
164 164
                 .setTopBarButtonCreator(new TitleBarButtonCreator(reactInstanceManager))
165
-                .setTitleBarReactViewCreator(new TitleBarReactViewCreator(reactInstanceManager))
166 165
                 .setTopBarBackgroundViewController(new TopBarBackgroundViewController(activity, new TopBarBackgroundViewCreator(reactInstanceManager)))
167 166
                 .setTopBarController(new TopBarController())
168 167
                 .setId(node.id)
169 168
                 .setInitialOptions(parse(typefaceManager, node.getOptions()))
170
-                .setOptionsPresenter(new OptionsPresenter(activity, defaultOptions))
171
-                .setStackPresenter(new StackOptionsPresenter(activity, defaultOptions))
169
+                .setStackPresenter(new StackOptionsPresenter(activity, new TitleBarReactViewCreator(reactInstanceManager), defaultOptions))
172 170
                 .build();
173 171
 	}
174 172
 

+ 58
- 6
lib/android/app/src/main/java/com/reactnativenavigation/presentation/StackOptionsPresenter.java View File

@@ -1,12 +1,15 @@
1 1
 package com.reactnativenavigation.presentation;
2 2
 
3 3
 import android.app.Activity;
4
-import android.content.Context;
5 4
 import android.graphics.Color;
6 5
 import android.support.annotation.Nullable;
6
+import android.support.annotation.RestrictTo;
7
+import android.support.v7.widget.Toolbar;
8
+import android.view.Gravity;
7 9
 import android.view.View;
8 10
 import android.view.ViewGroup.LayoutParams;
9 11
 
12
+import com.reactnativenavigation.parse.Alignment;
10 13
 import com.reactnativenavigation.parse.AnimationsOptions;
11 14
 import com.reactnativenavigation.parse.Options;
12 15
 import com.reactnativenavigation.parse.OrientationOptions;
@@ -17,11 +20,15 @@ import com.reactnativenavigation.parse.TopTabsOptions;
17 20
 import com.reactnativenavigation.parse.params.Button;
18 21
 import com.reactnativenavigation.utils.UiUtils;
19 22
 import com.reactnativenavigation.viewcontrollers.IReactView;
23
+import com.reactnativenavigation.viewcontrollers.TitleBarReactViewController;
20 24
 import com.reactnativenavigation.views.Component;
25
+import com.reactnativenavigation.views.titlebar.TitleBarReactViewCreator;
21 26
 import com.reactnativenavigation.views.topbar.TopBar;
22 27
 
23 28
 import java.util.ArrayList;
29
+import java.util.HashMap;
24 30
 import java.util.List;
31
+import java.util.Map;
25 32
 
26 33
 public class StackOptionsPresenter {
27 34
     private static final int DEFAULT_TITLE_COLOR = Color.BLACK;
@@ -30,14 +37,19 @@ public class StackOptionsPresenter {
30 37
     private static final double DEFAULT_ELEVATION = 4d;
31 38
     private final double defaultTitleFontSize;
32 39
     private final double defaultSubtitleFontSize;
40
+    private final Activity activity;
33 41
 
34 42
     private TopBar topBar;
43
+    private TitleBarReactViewCreator titleViewCreator;
35 44
     private Options defaultOptions;
45
+    private Map<Component, TitleBarReactViewController> titleComponentViewControllers = new HashMap<>();
36 46
 
37
-    public StackOptionsPresenter(Context context, Options defaultOptions) {
38
-        defaultTitleFontSize = UiUtils.dpToSp(context, 18);
39
-        defaultSubtitleFontSize = UiUtils.dpToSp(context, 14);
47
+    public StackOptionsPresenter(Activity activity, TitleBarReactViewCreator titleViewCreator, Options defaultOptions) {
48
+        this.activity = activity;
49
+        this.titleViewCreator = titleViewCreator;
40 50
         this.defaultOptions = defaultOptions;
51
+        defaultTitleFontSize = UiUtils.dpToSp(activity, 18);
52
+        defaultSubtitleFontSize = UiUtils.dpToSp(activity, 14);
41 53
     }
42 54
 
43 55
     public void setDefaultOptions(Options defaultOptions) {
@@ -78,13 +90,32 @@ public class StackOptionsPresenter {
78 90
         ((Activity) topBar.getContext()).setRequestedOrientation(withDefaultOptions.getValue());
79 91
     }
80 92
 
93
+    public void onChildDestroyed(Component child) {
94
+        TitleBarReactViewController removed = titleComponentViewControllers.remove(child);
95
+        if (removed != null) {
96
+            removed.destroy();
97
+        }
98
+    }
99
+
81 100
     private void applyTopBarOptions(TopBarOptions options, AnimationsOptions animationOptions, Component component, Options componentOptions) {
82 101
         topBar.setHeight(options.height.get(LayoutParams.WRAP_CONTENT));
83 102
         topBar.setElevation(options.elevation.get(DEFAULT_ELEVATION));
84 103
 
85 104
         topBar.setTitleHeight(options.title.height.get(LayoutParams.WRAP_CONTENT));
86 105
         topBar.setTitle(options.title.text.get(""));
87
-        if (options.title.component.hasValue()) topBar.setTitleComponent(options.title.component);
106
+
107
+        if (options.title.component.hasValue()) {
108
+            if (titleComponentViewControllers.containsKey(component)) {
109
+                topBar.setTitleComponent(titleComponentViewControllers.get(component).getView());
110
+            } else {
111
+                TitleBarReactViewController controller = new TitleBarReactViewController(activity, titleViewCreator);
112
+                titleComponentViewControllers.put(component, controller);
113
+                controller.setComponent(options.title.component);
114
+                controller.getView().setLayoutParams(getComponentLayoutParams(options.title.component));
115
+                topBar.setTitleComponent(controller.getView());
116
+            }
117
+        }
118
+
88 119
         topBar.setTitleFontSize(options.title.fontSize.get(defaultTitleFontSize));
89 120
         topBar.setTitleTextColor(options.title.color.get(DEFAULT_TITLE_COLOR));
90 121
         topBar.setTitleTypeface(options.title.fontFamily);
@@ -210,7 +241,19 @@ public class StackOptionsPresenter {
210 241
 
211 242
         if (options.title.height.hasValue()) topBar.setTitleHeight(options.title.height.get());
212 243
         if (options.title.text.hasValue()) topBar.setTitle(options.title.text.get());
213
-        if (options.title.component.hasValue()) topBar.setTitleComponent(options.title.component);
244
+
245
+        if (options.title.component.hasValue()) {
246
+            if (titleComponentViewControllers.containsKey(component)) {
247
+                topBar.setTitleComponent(titleComponentViewControllers.get(component).getView());
248
+            } else {
249
+                TitleBarReactViewController controller = new TitleBarReactViewController(activity, titleViewCreator);
250
+                titleComponentViewControllers.put(component, controller);
251
+                controller.setComponent(options.title.component);
252
+                controller.getView().setLayoutParams(getComponentLayoutParams(options.title.component));
253
+                topBar.setTitleComponent(controller.getView());
254
+            }
255
+        }
256
+
214 257
         if (options.title.color.hasValue()) topBar.setTitleTextColor(options.title.color.get());
215 258
         if (options.title.fontSize.hasValue()) topBar.setTitleFontSize(options.title.fontSize.get());
216 259
         if (options.title.fontFamily != null) topBar.setTitleTypeface(options.title.fontFamily);
@@ -262,4 +305,13 @@ public class StackOptionsPresenter {
262 305
     private void mergeTopTabOptions(TopTabOptions topTabOptions) {
263 306
         if (topTabOptions.fontFamily != null) topBar.setTopTabFontFamily(topTabOptions.tabIndex, topTabOptions.fontFamily);
264 307
     }
308
+
309
+    private LayoutParams getComponentLayoutParams(com.reactnativenavigation.parse.Component component) {
310
+        return new Toolbar.LayoutParams(component.alignment == Alignment.Center ? Gravity.CENTER : Gravity.START);
311
+    }
312
+
313
+    @RestrictTo(RestrictTo.Scope.TESTS)
314
+    public Map<Component, TitleBarReactViewController> getTitleComponents() {
315
+        return titleComponentViewControllers;
316
+    }
265 317
 }

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

@@ -63,10 +63,16 @@ public class ComponentViewController extends ChildController<ComponentLayout> {
63 63
 
64 64
     @Override
65 65
     public void mergeOptions(Options options) {
66
-        applyOnParentController(parentController -> parentController.mergeChildOptions(options, getView()));
66
+        performOnParentController(parentController -> parentController.mergeChildOptions(options, getView()));
67 67
         super.mergeOptions(options);
68 68
     }
69 69
 
70
+    @Override
71
+    public void destroy() {
72
+        if (!isDestroyed()) performOnParentController(parent -> parent.onChildDestroyed(getView()));
73
+        super.destroy();
74
+    }
75
+
70 76
     ReactComponent getComponent() {
71 77
         return view;
72 78
     }

+ 5
- 1
lib/android/app/src/main/java/com/reactnativenavigation/viewcontrollers/ParentController.java View File

@@ -117,7 +117,7 @@ public abstract class ParentController<T extends ViewGroup> extends ChildControl
117 117
 
118 118
 	@CallSuper
119 119
     protected void clearOptions() {
120
-	    applyOnParentController(parent -> ((ParentController) parent).clearOptions());
120
+	    performOnParentController(parent -> ((ParentController) parent).clearOptions());
121 121
         options = initialOptions.copy().clearOneTimeOptions();
122 122
     }
123 123
 
@@ -133,4 +133,8 @@ public abstract class ParentController<T extends ViewGroup> extends ChildControl
133 133
     public boolean isRendered() {
134 134
         return getCurrentChild() != null && getCurrentChild().isRendered();
135 135
     }
136
+
137
+    public void onChildDestroyed(Component child) {
138
+
139
+    }
136 140
 }

+ 2
- 2
lib/android/app/src/main/java/com/reactnativenavigation/viewcontrollers/SideMenuController.java View File

@@ -64,7 +64,7 @@ public class SideMenuController extends ParentController<DrawerLayout> {
64 64
     @Override
65 65
     public void applyChildOptions(Options options, Component child) {
66 66
         super.applyChildOptions(options, child);
67
-        applyOnParentController(parentController ->
67
+        performOnParentController(parentController ->
68 68
                 ((ParentController) parentController).applyChildOptions(this.options, child)
69 69
         );
70 70
     }
@@ -73,7 +73,7 @@ public class SideMenuController extends ParentController<DrawerLayout> {
73 73
     public void mergeChildOptions(Options options, Component child) {
74 74
         super.mergeChildOptions(options, child);
75 75
         new SideMenuOptionsPresenter(getView()).present(options.sideMenuRootOptions);
76
-        applyOnParentController(parentController ->
76
+        performOnParentController(parentController ->
77 77
                 ((ParentController) parentController).mergeChildOptions(options.copy().clearSideMenuOptions(), child)
78 78
         );
79 79
     }

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

@@ -118,7 +118,7 @@ public abstract class ViewController<T extends ViewGroup> implements ViewTreeObs
118 118
         return activity;
119 119
     }
120 120
 
121
-    protected void applyOnParentController(Task<ParentController> task) {
121
+    protected void performOnParentController(Task<ParentController> task) {
122 122
         if (parentController != null) task.run(parentController);
123 123
     }
124 124
 
@@ -193,7 +193,7 @@ public abstract class ViewController<T extends ViewGroup> implements ViewTreeObs
193 193
     public void onViewAppeared() {
194 194
         isShown = true;
195 195
         applyOptions(options);
196
-        applyOnParentController(parentController -> {
196
+        performOnParentController(parentController -> {
197 197
             parentController.clearOptions();
198 198
             if (getView() instanceof Component) parentController.applyChildOptions(options, (Component) getView());
199 199
         });
@@ -234,6 +234,10 @@ public abstract class ViewController<T extends ViewGroup> implements ViewTreeObs
234 234
         }
235 235
     }
236 236
 
237
+    protected boolean isDestroyed() {
238
+        return isDestroyed;
239
+    }
240
+
237 241
     @Override
238 242
     public void onGlobalLayout() {
239 243
         if (!isShown && isViewShown()) {

+ 2
- 2
lib/android/app/src/main/java/com/reactnativenavigation/viewcontrollers/bottomtabs/BottomTabsController.java View File

@@ -84,7 +84,7 @@ public class BottomTabsController extends ParentController implements AHBottomNa
84 84
     public void applyChildOptions(Options options, Component child) {
85 85
         super.applyChildOptions(options, child);
86 86
         presenter.applyChildOptions(this.options, child);
87
-        applyOnParentController(parentController ->
87
+        performOnParentController(parentController ->
88 88
                 ((ParentController) parentController).applyChildOptions(this.options.copy().clearBottomTabsOptions().clearBottomTabOptions(), child)
89 89
         );
90 90
     }
@@ -94,7 +94,7 @@ public class BottomTabsController extends ParentController implements AHBottomNa
94 94
         super.mergeChildOptions(options, child);
95 95
         presenter.mergeChildOptions(options, child);
96 96
         tabPresenter.mergeChildOptions(options, child);
97
-        applyOnParentController(parentController ->
97
+        performOnParentController(parentController ->
98 98
                 ((ParentController) parentController).mergeChildOptions(options.copy().clearBottomTabsOptions(), child)
99 99
         );
100 100
     }

+ 9
- 7
lib/android/app/src/main/java/com/reactnativenavigation/viewcontrollers/stack/StackController.java View File

@@ -26,7 +26,6 @@ import com.reactnativenavigation.viewcontrollers.topbar.TopBarController;
26 26
 import com.reactnativenavigation.views.Component;
27 27
 import com.reactnativenavigation.views.ReactComponent;
28 28
 import com.reactnativenavigation.views.StackLayout;
29
-import com.reactnativenavigation.views.titlebar.TitleBarReactViewCreator;
30 29
 import com.reactnativenavigation.views.topbar.TopBar;
31 30
 
32 31
 import java.util.Collection;
@@ -40,17 +39,15 @@ public class StackController extends ParentController<StackLayout> {
40 39
     private final IdStack<ViewController> stack = new IdStack<>();
41 40
     private final NavigationAnimator animator;
42 41
     private final ReactViewCreator topBarButtonCreator;
43
-    private final TitleBarReactViewCreator titleBarReactViewCreator;
44 42
     private TopBarBackgroundViewController topBarBackgroundViewController;
45 43
     private TopBarController topBarController;
46 44
     private BackButtonHelper backButtonHelper;
47 45
     private final StackOptionsPresenter presenter;
48 46
 
49
-    public StackController(Activity activity, List<ViewController> children, ChildControllersRegistry childRegistry, ReactViewCreator topBarButtonCreator, TitleBarReactViewCreator titleBarReactViewCreator, TopBarBackgroundViewController topBarBackgroundViewController, TopBarController topBarController, NavigationAnimator animator, String id, Options initialOptions, BackButtonHelper backButtonHelper, StackOptionsPresenter stackPresenter, OptionsPresenter presenter) {
47
+    public StackController(Activity activity, List<ViewController> children, ChildControllersRegistry childRegistry, ReactViewCreator topBarButtonCreator, TopBarBackgroundViewController topBarBackgroundViewController, TopBarController topBarController, NavigationAnimator animator, String id, Options initialOptions, BackButtonHelper backButtonHelper, StackOptionsPresenter stackPresenter, OptionsPresenter presenter) {
50 48
         super(activity, childRegistry, id, presenter, initialOptions);
51 49
         this.topBarController = topBarController;
52 50
         this.topBarButtonCreator = topBarButtonCreator;
53
-        this.titleBarReactViewCreator = titleBarReactViewCreator;
54 51
         this.topBarBackgroundViewController = topBarBackgroundViewController;
55 52
         this.animator = animator;
56 53
         this.backButtonHelper = backButtonHelper;
@@ -79,7 +76,7 @@ public class StackController extends ParentController<StackLayout> {
79 76
         if (child instanceof ReactComponent) {
80 77
             fabOptionsPresenter.applyOptions(this.options.fabOptions, (ReactComponent) child, getView());
81 78
         }
82
-        applyOnParentController(parentController ->
79
+        performOnParentController(parentController ->
83 80
                 ((ParentController) parentController).applyChildOptions(
84 81
                         this.options.copy()
85 82
                                 .clearTopBarOptions()
@@ -99,7 +96,7 @@ public class StackController extends ParentController<StackLayout> {
99 96
         if (options.fabOptions.hasValue() && child instanceof ReactComponent) {
100 97
             fabOptionsPresenter.mergeOptions(options.fabOptions, (ReactComponent) child, getView());
101 98
         }
102
-        applyOnParentController(parentController ->
99
+        performOnParentController(parentController ->
103 100
                 ((ParentController) parentController).mergeChildOptions(
104 101
                         options.copy()
105 102
                                 .clearTopBarOptions()
@@ -124,6 +121,12 @@ public class StackController extends ParentController<StackLayout> {
124 121
         topBarController.clear();
125 122
     }
126 123
 
124
+    @Override
125
+    public void onChildDestroyed(Component child) {
126
+        super.onChildDestroyed(child);
127
+        presenter.onChildDestroyed(child);
128
+    }
129
+
127 130
     public void push(ViewController child, CommandListener listener) {
128 131
         final ViewController toRemove = stack.peek();
129 132
         child.setParentController(this);
@@ -296,7 +299,6 @@ public class StackController extends ParentController<StackLayout> {
296 299
     protected StackLayout createView() {
297 300
         StackLayout stackLayout = new StackLayout(getActivity(),
298 301
                 topBarButtonCreator,
299
-                titleBarReactViewCreator,
300 302
                 topBarBackgroundViewController,
301 303
                 topBarController,
302 304
                 this::onNavigationButtonPressed,

+ 0
- 13
lib/android/app/src/main/java/com/reactnativenavigation/viewcontrollers/stack/StackControllerBuilder.java View File

@@ -12,7 +12,6 @@ import com.reactnativenavigation.viewcontrollers.ViewController;
12 12
 import com.reactnativenavigation.viewcontrollers.topbar.TopBarBackgroundViewController;
13 13
 import com.reactnativenavigation.viewcontrollers.topbar.TopBarController;
14 14
 import com.reactnativenavigation.views.element.ElementTransitionManager;
15
-import com.reactnativenavigation.views.titlebar.TitleBarReactViewCreator;
16 15
 
17 16
 import java.util.ArrayList;
18 17
 import java.util.List;
@@ -21,7 +20,6 @@ public class StackControllerBuilder {
21 20
     private Activity activity;
22 21
     private ChildControllersRegistry childRegistry;
23 22
     private ReactViewCreator topBarButtonCreator;
24
-    private TitleBarReactViewCreator titleBarReactViewCreator;
25 23
     private TopBarBackgroundViewController topBarBackgroundViewController;
26 24
     private TopBarController topBarController;
27 25
     private String id;
@@ -43,11 +41,6 @@ public class StackControllerBuilder {
43 41
         return this;
44 42
     }
45 43
 
46
-    public StackControllerBuilder setOptionsPresenter(OptionsPresenter presenter) {
47
-        this.presenter = presenter;
48
-        return this;
49
-    }
50
-
51 44
     public StackControllerBuilder setStackPresenter(StackOptionsPresenter stackPresenter) {
52 45
         this.stackPresenter = stackPresenter;
53 46
         return this;
@@ -63,11 +56,6 @@ public class StackControllerBuilder {
63 56
         return this;
64 57
     }
65 58
 
66
-    public StackControllerBuilder setTitleBarReactViewCreator(TitleBarReactViewCreator titleBarReactViewCreator) {
67
-        this.titleBarReactViewCreator = titleBarReactViewCreator;
68
-        return this;
69
-    }
70
-
71 59
     public StackControllerBuilder setTopBarBackgroundViewController(TopBarBackgroundViewController topBarBackgroundViewController) {
72 60
         this.topBarBackgroundViewController = topBarBackgroundViewController;
73 61
         return this;
@@ -103,7 +91,6 @@ public class StackControllerBuilder {
103 91
                 children,
104 92
                 childRegistry,
105 93
                 topBarButtonCreator,
106
-                titleBarReactViewCreator,
107 94
                 topBarBackgroundViewController,
108 95
                 topBarController,
109 96
                 animator,

+ 4
- 5
lib/android/app/src/main/java/com/reactnativenavigation/viewcontrollers/topbar/TopBarController.java View File

@@ -9,23 +9,22 @@ import com.reactnativenavigation.utils.ImageLoader;
9 9
 import com.reactnativenavigation.viewcontrollers.ReactViewCreator;
10 10
 import com.reactnativenavigation.viewcontrollers.TopBarButtonController;
11 11
 import com.reactnativenavigation.views.StackLayout;
12
-import com.reactnativenavigation.views.titlebar.TitleBarReactViewCreator;
13 12
 import com.reactnativenavigation.views.topbar.TopBar;
14 13
 
15 14
 
16 15
 public class TopBarController {
17 16
     private TopBar topBar;
18 17
 
19
-    public View createView(Context context, ReactViewCreator buttonCreator, TitleBarReactViewCreator titleBarReactViewCreator, TopBarBackgroundViewController topBarBackgroundViewController, TopBarButtonController.OnClickListener topBarButtonClickListener, StackLayout stackLayout) {
18
+    public View createView(Context context, ReactViewCreator buttonCreator, TopBarBackgroundViewController topBarBackgroundViewController, TopBarButtonController.OnClickListener topBarButtonClickListener, StackLayout stackLayout) {
20 19
         if (topBar == null) {
21
-            topBar = createTopBar(context, buttonCreator, titleBarReactViewCreator, topBarBackgroundViewController, topBarButtonClickListener, stackLayout, new ImageLoader());
20
+            topBar = createTopBar(context, buttonCreator, topBarBackgroundViewController, topBarButtonClickListener, stackLayout, new ImageLoader());
22 21
             topBar.setId(CompatUtils.generateViewId());
23 22
         }
24 23
         return topBar;
25 24
     }
26 25
 
27
-    protected TopBar createTopBar(Context context, ReactViewCreator buttonCreator, TitleBarReactViewCreator titleBarReactViewCreator, TopBarBackgroundViewController topBarBackgroundViewController, TopBarButtonController.OnClickListener topBarButtonClickListener, StackLayout stackLayout, ImageLoader imageLoader) {
28
-        return new TopBar(context, buttonCreator, titleBarReactViewCreator, topBarBackgroundViewController, topBarButtonClickListener, stackLayout, imageLoader);
26
+    protected TopBar createTopBar(Context context, ReactViewCreator buttonCreator, TopBarBackgroundViewController topBarBackgroundViewController, TopBarButtonController.OnClickListener topBarButtonClickListener, StackLayout stackLayout, ImageLoader imageLoader) {
27
+        return new TopBar(context, buttonCreator, topBarBackgroundViewController, topBarButtonClickListener, stackLayout, imageLoader);
29 28
     }
30 29
 
31 30
     public void clear() {

+ 4
- 4
lib/android/app/src/main/java/com/reactnativenavigation/viewcontrollers/toptabs/TopTabsController.java View File

@@ -60,7 +60,7 @@ public class TopTabsController extends ParentController<TopTabsViewPager> {
60 60
     @Override
61 61
     public void onViewAppeared() {
62 62
         super.onViewAppeared();
63
-        applyOnParentController(parentController -> ((ParentController) parentController).setupTopTabsWithViewPager(getView()));
63
+        performOnParentController(parentController -> ((ParentController) parentController).setupTopTabsWithViewPager(getView()));
64 64
         performOnCurrentTab(ViewController::onViewAppeared);
65 65
     }
66 66
 
@@ -73,7 +73,7 @@ public class TopTabsController extends ParentController<TopTabsViewPager> {
73 73
     public void onViewDisappear() {
74 74
         super.onViewDisappear();
75 75
         performOnCurrentTab(ViewController::onViewDisappear);
76
-        applyOnParentController(parentController -> ((ParentController) parentController).clearTopTabs());
76
+        performOnParentController(parentController -> ((ParentController) parentController).clearTopTabs());
77 77
     }
78 78
 
79 79
     @Override
@@ -90,13 +90,13 @@ public class TopTabsController extends ParentController<TopTabsViewPager> {
90 90
     @Override
91 91
     public void applyChildOptions(Options options, Component child) {
92 92
         super.applyChildOptions(options, child);
93
-        applyOnParentController(parentController -> ((ParentController) parentController).applyChildOptions(this.options.copy(), child));
93
+        performOnParentController(parentController -> ((ParentController) parentController).applyChildOptions(this.options.copy(), child));
94 94
     }
95 95
 
96 96
     @CallSuper
97 97
     public void mergeChildOptions(Options options, Component child) {
98 98
         super.mergeChildOptions(options, child);
99
-        applyOnParentController(parentController -> ((ParentController) parentController).applyChildOptions(options.copy(), child));
99
+        performOnParentController(parentController -> ((ParentController) parentController).applyChildOptions(options.copy(), child));
100 100
     }
101 101
 
102 102
     public void switchToTab(int index) {

+ 4
- 5
lib/android/app/src/main/java/com/reactnativenavigation/views/StackLayout.java View File

@@ -8,7 +8,6 @@ import com.reactnativenavigation.viewcontrollers.ReactViewCreator;
8 8
 import com.reactnativenavigation.viewcontrollers.TopBarButtonController;
9 9
 import com.reactnativenavigation.viewcontrollers.topbar.TopBarBackgroundViewController;
10 10
 import com.reactnativenavigation.viewcontrollers.topbar.TopBarController;
11
-import com.reactnativenavigation.views.titlebar.TitleBarReactViewCreator;
12 11
 import com.reactnativenavigation.views.topbar.TopBar;
13 12
 
14 13
 import static android.view.ViewGroup.LayoutParams.MATCH_PARENT;
@@ -18,15 +17,15 @@ import static android.view.ViewGroup.LayoutParams.WRAP_CONTENT;
18 17
 public class StackLayout extends RelativeLayout implements Component {
19 18
     private String stackId;
20 19
 
21
-    public StackLayout(Context context, ReactViewCreator topBarButtonCreator, TitleBarReactViewCreator titleBarReactViewCreator, TopBarBackgroundViewController topBarBackgroundViewController, TopBarController topBarController, TopBarButtonController.OnClickListener topBarButtonClickListener, String stackId) {
20
+    public StackLayout(Context context, ReactViewCreator topBarButtonCreator, TopBarBackgroundViewController topBarBackgroundViewController, TopBarController topBarController, TopBarButtonController.OnClickListener topBarButtonClickListener, String stackId) {
22 21
         super(context);
23 22
         this.stackId = stackId;
24
-        createLayout(topBarButtonCreator, titleBarReactViewCreator, topBarBackgroundViewController, topBarController, topBarButtonClickListener);
23
+        createLayout(topBarButtonCreator, topBarBackgroundViewController, topBarController, topBarButtonClickListener);
25 24
         setContentDescription("StackLayout");
26 25
     }
27 26
 
28
-    private void createLayout(ReactViewCreator buttonCreator, TitleBarReactViewCreator titleBarReactViewCreator, TopBarBackgroundViewController topBarBackgroundViewController, TopBarController topBarController, TopBarButtonController.OnClickListener topBarButtonClickListener) {
29
-        addView(topBarController.createView(getContext(), buttonCreator, titleBarReactViewCreator, topBarBackgroundViewController, topBarButtonClickListener, this), MATCH_PARENT, WRAP_CONTENT);
27
+    private void createLayout(ReactViewCreator buttonCreator, TopBarBackgroundViewController topBarBackgroundViewController, TopBarController topBarController, TopBarButtonController.OnClickListener topBarButtonClickListener) {
28
+        addView(topBarController.createView(getContext(), buttonCreator, topBarBackgroundViewController, topBarButtonClickListener, this), MATCH_PARENT, WRAP_CONTENT);
30 29
     }
31 30
 
32 31
     public String getStackId() {

+ 13
- 24
lib/android/app/src/main/java/com/reactnativenavigation/views/titlebar/TitleBar.java View File

@@ -6,13 +6,12 @@ import android.content.Context;
6 6
 import android.graphics.Typeface;
7 7
 import android.support.v7.widget.Toolbar;
8 8
 import android.util.Log;
9
-import android.view.Gravity;
9
+import android.view.View;
10 10
 import android.view.ViewGroup;
11 11
 import android.widget.TextView;
12 12
 
13 13
 import com.reactnativenavigation.parse.Alignment;
14 14
 import com.reactnativenavigation.parse.BackButton;
15
-import com.reactnativenavigation.parse.Component;
16 15
 import com.reactnativenavigation.parse.params.Button;
17 16
 import com.reactnativenavigation.parse.params.Color;
18 17
 import com.reactnativenavigation.utils.ButtonOptionsPresenter;
@@ -20,7 +19,6 @@ import com.reactnativenavigation.utils.ImageLoader;
20 19
 import com.reactnativenavigation.utils.UiUtils;
21 20
 import com.reactnativenavigation.utils.ViewUtils;
22 21
 import com.reactnativenavigation.viewcontrollers.ReactViewCreator;
23
-import com.reactnativenavigation.viewcontrollers.TitleBarReactViewController;
24 22
 import com.reactnativenavigation.viewcontrollers.TopBarButtonController;
25 23
 import com.reactnativenavigation.viewcontrollers.button.NavigationIconResolver;
26 24
 
@@ -29,24 +27,21 @@ import java.util.List;
29 27
 
30 28
 import javax.annotation.Nullable;
31 29
 
32
-import static android.view.ViewGroup.LayoutParams.MATCH_PARENT;
33
-
34 30
 @SuppressLint("ViewConstructor")
35 31
 public class TitleBar extends Toolbar {
32
+    public static final int DEFAULT_LEFT_MARGIN = 16;
33
+
36 34
     private final ReactViewCreator buttonCreator;
37
-    private TitleBarReactViewController reactViewController;
38
-    private final TitleBarReactViewCreator reactViewCreator;
39 35
     private final TopBarButtonController.OnClickListener onClickListener;
40 36
     private final List<TopBarButtonController> rightButtonControllers = new ArrayList<>();
41 37
     private TopBarButtonController leftButtonController;
42 38
     private ImageLoader imageLoader;
39
+    private View component;
43 40
 
44
-    public TitleBar(Context context, ReactViewCreator buttonCreator, TitleBarReactViewCreator reactViewCreator, TopBarButtonController.OnClickListener onClickListener, ImageLoader imageLoader) {
41
+    public TitleBar(Context context, ReactViewCreator buttonCreator, TopBarButtonController.OnClickListener onClickListener, ImageLoader imageLoader) {
45 42
         super(context);
46 43
         this.buttonCreator = buttonCreator;
47
-        this.reactViewCreator = reactViewCreator;
48 44
         this.imageLoader = imageLoader;
49
-        reactViewController = new TitleBarReactViewController((Activity) context, reactViewCreator);
50 45
         this.onClickListener = onClickListener;
51 46
         getMenu();
52 47
         setContentDescription("titleBar");
@@ -66,11 +61,11 @@ public class TitleBar extends Toolbar {
66 61
         if (color.hasValue()) setTitleTextColor(color.get());
67 62
     }
68 63
 
69
-    public void setComponent(Component component) {
64
+    public void setComponent(View component) {
70 65
         clearTitle();
71 66
         clearSubtitle();
72
-        reactViewController.setComponent(component);
73
-        addView(reactViewController.getView(), getComponentLayoutParams(component));
67
+        this.component = component;
68
+        addView(component);
74 69
     }
75 70
 
76 71
     public void setBackgroundColor(Color color) {
@@ -116,7 +111,7 @@ public class TitleBar extends Toolbar {
116 111
             } else if (leftButtonController != null) {
117 112
                 view.setX(getContentInsetStartWithNavigation());
118 113
             } else {
119
-                view.setX(UiUtils.dpToPx(getContext(), 16));
114
+                view.setX(UiUtils.dpToPx(getContext(), DEFAULT_LEFT_MARGIN));
120 115
             }
121 116
         });
122 117
     }
@@ -150,8 +145,10 @@ public class TitleBar extends Toolbar {
150 145
     }
151 146
 
152 147
     private void clearComponent() {
153
-        reactViewController.destroy();
154
-        reactViewController = new TitleBarReactViewController((Activity) getContext(), reactViewCreator);
148
+        if (component != null) {
149
+            removeView(component);
150
+            component = null;
151
+        }
155 152
     }
156 153
 
157 154
     private void clearLeftButton() {
@@ -213,14 +210,6 @@ public class TitleBar extends Toolbar {
213 210
         );
214 211
     }
215 212
 
216
-    public Toolbar.LayoutParams getComponentLayoutParams(Component component) {
217
-        LayoutParams lp = new LayoutParams(MATCH_PARENT, getHeight());
218
-        if (component.alignment == Alignment.Center) {
219
-            lp.gravity = Gravity.CENTER;
220
-        }
221
-        return lp;
222
-    }
223
-
224 213
     public void setHeight(int height) {
225 214
         if (height == getLayoutParams().height) return;
226 215
         ViewGroup.LayoutParams lp = getLayoutParams();

+ 7
- 8
lib/android/app/src/main/java/com/reactnativenavigation/views/topbar/TopBar.java View File

@@ -39,7 +39,6 @@ import com.reactnativenavigation.viewcontrollers.TopBarButtonController;
39 39
 import com.reactnativenavigation.viewcontrollers.topbar.TopBarBackgroundViewController;
40 40
 import com.reactnativenavigation.views.StackLayout;
41 41
 import com.reactnativenavigation.views.titlebar.TitleBar;
42
-import com.reactnativenavigation.views.titlebar.TitleBarReactViewCreator;
43 42
 import com.reactnativenavigation.views.toptabs.TopTabs;
44 43
 
45 44
 import java.util.List;
@@ -58,7 +57,7 @@ public class TopBar extends AppBarLayout implements ScrollEventListener.ScrollAw
58 57
     private View border;
59 58
     private ImageLoader imageLoader;
60 59
 
61
-    public TopBar(final Context context, ReactViewCreator buttonCreator, TitleBarReactViewCreator titleBarReactViewCreator, TopBarBackgroundViewController topBarBackgroundViewController, TopBarButtonController.OnClickListener onClickListener, StackLayout parentView, ImageLoader imageLoader) {
60
+    public TopBar(final Context context, ReactViewCreator buttonCreator, TopBarBackgroundViewController topBarBackgroundViewController, TopBarButtonController.OnClickListener onClickListener, StackLayout parentView, ImageLoader imageLoader) {
62 61
         super(context);
63 62
         context.setTheme(R.style.TopBar);
64 63
         this.imageLoader = imageLoader;
@@ -66,12 +65,12 @@ public class TopBar extends AppBarLayout implements ScrollEventListener.ScrollAw
66 65
         this.topBarBackgroundViewController = topBarBackgroundViewController;
67 66
         topTabs = new TopTabs(getContext());
68 67
         animator = new TopBarAnimator(this, parentView.getStackId());
69
-        createLayout(buttonCreator, titleBarReactViewCreator, onClickListener);
68
+        createLayout(buttonCreator, onClickListener);
70 69
     }
71 70
 
72
-    private void createLayout(ReactViewCreator buttonCreator, TitleBarReactViewCreator titleBarReactViewCreator, TopBarButtonController.OnClickListener onClickListener) {
71
+    private void createLayout(ReactViewCreator buttonCreator, TopBarButtonController.OnClickListener onClickListener) {
73 72
         setId(CompatUtils.generateViewId());
74
-        titleBar = createTitleBar(getContext(), buttonCreator, titleBarReactViewCreator, onClickListener, imageLoader);
73
+        titleBar = createTitleBar(getContext(), buttonCreator, onClickListener, imageLoader);
75 74
         topTabs = createTopTabs();
76 75
         border = createBorder();
77 76
         LinearLayout content = createContentLayout();
@@ -111,8 +110,8 @@ public class TopBar extends AppBarLayout implements ScrollEventListener.ScrollAw
111 110
         return border;
112 111
     }
113 112
 
114
-    protected TitleBar createTitleBar(Context context, ReactViewCreator buttonCreator, TitleBarReactViewCreator reactViewCreator, TopBarButtonController.OnClickListener onClickListener, ImageLoader imageLoader) {
115
-        TitleBar titleBar = new TitleBar(context, buttonCreator, reactViewCreator, onClickListener, imageLoader);
113
+    protected TitleBar createTitleBar(Context context, ReactViewCreator buttonCreator, TopBarButtonController.OnClickListener onClickListener, ImageLoader imageLoader) {
114
+        TitleBar titleBar = new TitleBar(context, buttonCreator, onClickListener, imageLoader);
116 115
         titleBar.setId(CompatUtils.generateViewId());
117 116
         return titleBar;
118 117
     }
@@ -176,7 +175,7 @@ public class TopBar extends AppBarLayout implements ScrollEventListener.ScrollAw
176 175
         titleBar.setTitleAlignment(alignment);
177 176
     }
178 177
 
179
-    public void setTitleComponent(Component component) {
178
+    public void setTitleComponent(View component) {
180 179
         titleBar.setComponent(component);
181 180
     }
182 181
 

+ 6
- 0
lib/android/app/src/test/java/com/reactnativenavigation/BaseTest.java View File

@@ -60,6 +60,12 @@ public abstract class BaseTest {
60 60
         }
61 61
     }
62 62
 
63
+    protected void disablePopAnimation(ViewController... controllers) {
64
+        for (ViewController controller : controllers) {
65
+            controller.options.animations.pop.enable = new Bool(false);
66
+        }
67
+    }
68
+
63 69
     protected void disableShowModalAnimation(ViewController... modals) {
64 70
         for (ViewController modal : modals) {
65 71
             modal.options.animations.showModal.enable = new Bool(false);

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

@@ -16,7 +16,6 @@ import com.reactnativenavigation.viewcontrollers.stack.StackControllerBuilder;
16 16
 import com.reactnativenavigation.viewcontrollers.topbar.TopBarBackgroundViewController;
17 17
 import com.reactnativenavigation.viewcontrollers.topbar.TopBarController;
18 18
 import com.reactnativenavigation.views.StackLayout;
19
-import com.reactnativenavigation.views.titlebar.TitleBarReactViewCreator;
20 19
 import com.reactnativenavigation.views.topbar.TopBar;
21 20
 
22 21
 public class TestUtils {
@@ -25,17 +24,16 @@ public class TestUtils {
25 24
                 .setId("stack")
26 25
                 .setChildRegistry(new ChildControllersRegistry())
27 26
                 .setTopBarButtonCreator(new TopBarButtonCreatorMock())
28
-                .setTitleBarReactViewCreator(new TitleBarReactViewCreatorMock())
29 27
                 .setTopBarBackgroundViewController(new TopBarBackgroundViewController(activity, new TopBarBackgroundViewCreatorMock()))
30 28
                 .setTopBarController(new TopBarController() {
31 29
                     @Override
32
-                    protected TopBar createTopBar(Context context, ReactViewCreator buttonCreator, TitleBarReactViewCreator titleBarReactViewCreator, TopBarBackgroundViewController topBarBackgroundViewController, TopBarButtonController.OnClickListener topBarButtonClickListener, StackLayout stackLayout, ImageLoader imageLoader) {
33
-                        TopBar topBar = super.createTopBar(context, buttonCreator, titleBarReactViewCreator, topBarBackgroundViewController, topBarButtonClickListener, stackLayout, imageLoader);
30
+                    protected TopBar createTopBar(Context context, ReactViewCreator buttonCreator, TopBarBackgroundViewController topBarBackgroundViewController, TopBarButtonController.OnClickListener topBarButtonClickListener, StackLayout stackLayout, ImageLoader imageLoader) {
31
+                        TopBar topBar = super.createTopBar(context, buttonCreator, topBarBackgroundViewController, topBarButtonClickListener, stackLayout, imageLoader);
34 32
                         topBar.layout(0, 0, 1000, 100);
35 33
                         return topBar;
36 34
                     }
37 35
                 })
38
-                .setStackPresenter(new StackOptionsPresenter(activity, new Options()))
36
+                .setStackPresenter(new StackOptionsPresenter(activity, new TitleBarReactViewCreatorMock(), new Options()))
39 37
                 .setInitialOptions(new Options());
40 38
     }
41 39
 }

+ 7
- 1
lib/android/app/src/test/java/com/reactnativenavigation/mocks/SimpleViewController.java View File

@@ -40,6 +40,12 @@ public class SimpleViewController extends ChildController<SimpleViewController.S
40 40
         getView().sendOnNavigationButtonPressed(buttonId);
41 41
     }
42 42
 
43
+    @Override
44
+    public void destroy() {
45
+        if (!isDestroyed()) performOnParentController(parent -> parent.onChildDestroyed(getView()));
46
+        super.destroy();
47
+    }
48
+
43 49
     @Override
44 50
     public String toString() {
45 51
         return "SimpleViewController " + getId();
@@ -47,7 +53,7 @@ public class SimpleViewController extends ChildController<SimpleViewController.S
47 53
 
48 54
     @Override
49 55
     public void mergeOptions(Options options) {
50
-        applyOnParentController(parentController -> parentController.mergeChildOptions(options, getView()));
56
+        performOnParentController(parentController -> parentController.mergeChildOptions(options, getView()));
51 57
         super.mergeOptions(options);
52 58
     }
53 59
 

+ 2
- 1
lib/android/app/src/test/java/com/reactnativenavigation/viewcontrollers/BottomTabsControllerTest.java View File

@@ -10,6 +10,7 @@ import com.reactnativenavigation.BaseTest;
10 10
 import com.reactnativenavigation.TestUtils;
11 11
 import com.reactnativenavigation.mocks.ImageLoaderMock;
12 12
 import com.reactnativenavigation.mocks.SimpleViewController;
13
+import com.reactnativenavigation.mocks.TitleBarReactViewCreatorMock;
13 14
 import com.reactnativenavigation.parse.Options;
14 15
 import com.reactnativenavigation.parse.params.Bool;
15 16
 import com.reactnativenavigation.parse.params.Color;
@@ -282,7 +283,7 @@ public class BottomTabsControllerTest extends BaseTest {
282 283
         return TestUtils.newStackController(activity)
283 284
                 .setId(id)
284 285
                 .setInitialOptions(tabOptions)
285
-                .setStackPresenter(new StackOptionsPresenter(activity, new Options()))
286
+                .setStackPresenter(new StackOptionsPresenter(activity, new TitleBarReactViewCreatorMock(), new Options()))
286 287
                 .build();
287 288
     }
288 289
 

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

@@ -30,7 +30,6 @@ import com.reactnativenavigation.viewcontrollers.stack.StackControllerBuilder;
30 30
 import com.reactnativenavigation.viewcontrollers.topbar.TopBarBackgroundViewController;
31 31
 import com.reactnativenavigation.viewcontrollers.topbar.TopBarController;
32 32
 import com.reactnativenavigation.views.StackLayout;
33
-import com.reactnativenavigation.views.titlebar.TitleBarReactViewCreator;
34 33
 import com.reactnativenavigation.views.topbar.TopBar;
35 34
 
36 35
 import org.json.JSONObject;
@@ -69,9 +68,9 @@ public class OptionsApplyingTest extends BaseTest {
69 68
         );
70 69
         TopBarController topBarController = new TopBarController() {
71 70
             @Override
72
-            protected TopBar createTopBar(Context context, ReactViewCreator buttonCreator, TitleBarReactViewCreator titleBarReactViewCreator, TopBarBackgroundViewController topBarBackgroundViewController, TopBarButtonController.OnClickListener topBarButtonClickListener, StackLayout stackLayout, ImageLoader imageLoader) {
71
+            protected TopBar createTopBar(Context context, ReactViewCreator buttonCreator, TopBarBackgroundViewController topBarBackgroundViewController, TopBarButtonController.OnClickListener topBarButtonClickListener, StackLayout stackLayout, ImageLoader imageLoader) {
73 72
                 topBar =
74
-                        spy(super.createTopBar(context, buttonCreator, titleBarReactViewCreator, topBarBackgroundViewController, topBarButtonClickListener, stackLayout, imageLoader));
73
+                        spy(super.createTopBar(context, buttonCreator, topBarBackgroundViewController, topBarButtonClickListener, stackLayout, imageLoader));
75 74
                 return topBar;
76 75
             }
77 76
         };
@@ -100,12 +99,11 @@ public class OptionsApplyingTest extends BaseTest {
100 99
         StackController stackController =
101 100
                 new StackControllerBuilder(activity)
102 101
                         .setTopBarButtonCreator(new TopBarButtonCreatorMock())
103
-                        .setTitleBarReactViewCreator(new TitleBarReactViewCreatorMock())
104 102
                         .setTopBarBackgroundViewController(new TopBarBackgroundViewController(activity, new TopBarBackgroundViewCreatorMock()))
105 103
                         .setTopBarController(new TopBarController())
106 104
                         .setId("stackId")
107 105
                         .setInitialOptions(new Options())
108
-                        .setStackPresenter(new StackOptionsPresenter(activity, new Options()))
106
+                        .setStackPresenter(new StackOptionsPresenter(activity, new TitleBarReactViewCreatorMock(), new Options()))
109 107
                         .build();
110 108
         stackController.ensureViewIsCreated();
111 109
         stackController.push(uut, new CommandListenerAdapter());

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

@@ -2,11 +2,16 @@ package com.reactnativenavigation.viewcontrollers;
2 2
 
3 3
 import android.app.Activity;
4 4
 import android.graphics.Typeface;
5
+import android.support.v7.widget.Toolbar;
6
+import android.view.Gravity;
5 7
 import android.view.View;
6 8
 
7 9
 import com.reactnativenavigation.BaseTest;
8 10
 import com.reactnativenavigation.mocks.TestComponentLayout;
9 11
 import com.reactnativenavigation.mocks.TestReactView;
12
+import com.reactnativenavigation.mocks.TitleBarReactViewCreatorMock;
13
+import com.reactnativenavigation.parse.Alignment;
14
+import com.reactnativenavigation.parse.Component;
10 15
 import com.reactnativenavigation.parse.Options;
11 16
 import com.reactnativenavigation.parse.OrientationOptions;
12 17
 import com.reactnativenavigation.parse.SubtitleOptions;
@@ -18,7 +23,7 @@ import com.reactnativenavigation.parse.params.Fraction;
18 23
 import com.reactnativenavigation.parse.params.Number;
19 24
 import com.reactnativenavigation.parse.params.Text;
20 25
 import com.reactnativenavigation.presentation.StackOptionsPresenter;
21
-import com.reactnativenavigation.views.Component;
26
+import com.reactnativenavigation.views.titlebar.TitleBarReactView;
22 27
 import com.reactnativenavigation.views.topbar.TopBar;
23 28
 
24 29
 import org.json.JSONObject;
@@ -45,16 +50,70 @@ public class StackOptionsPresenterTest extends BaseTest {
45 50
     private static final Options EMPTY_OPTIONS = new Options();
46 51
     private StackOptionsPresenter uut;
47 52
     private TestComponentLayout child;
53
+    private TestComponentLayout otherChild;
48 54
     private Activity activity;
49 55
     private TopBar topBar;
50 56
 
51 57
     @Override
52 58
     public void beforeEach() {
53 59
         activity = spy(newActivity());
54
-        uut = spy(new StackOptionsPresenter(activity, new Options()));
60
+
61
+        TitleBarReactViewCreatorMock titleViewCreator = new TitleBarReactViewCreatorMock() {
62
+            @Override
63
+            public TitleBarReactView create(Activity activity, String componentId, String componentName) {
64
+                return spy(super.create(activity, componentId, componentName));
65
+            }
66
+        };
67
+        uut = spy(new StackOptionsPresenter(activity, titleViewCreator, new Options()));
55 68
         topBar = mockTopBar();
56 69
         uut.bindView(topBar);
57 70
         child = spy(new TestComponentLayout(activity, new TestReactView(activity)));
71
+        otherChild = new TestComponentLayout(activity, new TestReactView(activity));
72
+    }
73
+
74
+    @Test
75
+    public void applyChildOptions_setTitleComponent() {
76
+        Options options = new Options();
77
+        options.topBar.title.component = component(Alignment.Default);
78
+        uut.applyChildOptions(options, child);
79
+        verify(topBar).setTitleComponent(uut.getTitleComponents().get(child).getView());
80
+    }
81
+
82
+    @Test
83
+    public void applyChildOptions_setTitleComponentCreatesOnce() {
84
+        Options options = new Options();
85
+        options.topBar.title.component = component(Alignment.Default);
86
+        uut.applyChildOptions(options, child);
87
+
88
+        uut.applyChildOptions(new Options(), otherChild);
89
+
90
+        TitleBarReactViewController titleController = uut.getTitleComponents().get(child);
91
+        uut.applyChildOptions(options, child);
92
+        assertThat(uut.getTitleComponents().size()).isOne();
93
+        assertThat(uut.getTitleComponents().get(child)).isEqualTo(titleController);
94
+    }
95
+
96
+    @Test
97
+    public void applyChildOptions_setTitleComponentAlignment() {
98
+        Options options = new Options();
99
+        options.topBar.title.component = component(Alignment.Center);
100
+        uut.applyChildOptions(options, child);
101
+        ArgumentCaptor<View> captor = ArgumentCaptor.forClass(View.class);
102
+        verify(topBar).setTitleComponent(captor.capture());
103
+
104
+        Toolbar.LayoutParams lp = (Toolbar.LayoutParams) captor.getValue().getLayoutParams();
105
+        assertThat(lp.gravity).isEqualTo(Gravity.CENTER);
106
+    }
107
+
108
+    @Test
109
+    public void onChildDestroyed_destroyTitleComponent() {
110
+        Options options = new Options();
111
+        options.topBar.title.component = component(Alignment.Default);
112
+        uut.applyChildOptions(options, child);
113
+
114
+        TitleBarReactView titleView = uut.getTitleComponents().get(child).getView();
115
+        uut.onChildDestroyed(child);
116
+        verify(titleView).destroy();
58 117
     }
59 118
 
60 119
     @Test
@@ -157,7 +216,7 @@ public class StackOptionsPresenterTest extends BaseTest {
157 216
         Options options = new Options();
158 217
         options.topBar.visible = new Bool(false);
159 218
         options.topBar.animate = new Bool(false);
160
-        View view = Mockito.mock(View.class, Mockito.withSettings().extraInterfaces(Component.class));
219
+        View view = Mockito.mock(View.class, Mockito.withSettings().extraInterfaces(com.reactnativenavigation.views.Component.class));
161 220
 
162 221
         uut.applyLayoutParamsOptions(options, view);
163 222
         verify(topBar).hide();
@@ -176,6 +235,7 @@ public class StackOptionsPresenterTest extends BaseTest {
176 235
         verify(topBar, times(0)).setBackgroundColor(anyInt());
177 236
     }
178 237
 
238
+    @Test
179 239
     public void applyButtons_buttonColorIsMergedToButtons() {
180 240
         Options options = new Options();
181 241
         Button rightButton1 = new Button();
@@ -295,4 +355,12 @@ public class StackOptionsPresenterTest extends BaseTest {
295 355
         when(topBar.getContext()).then(invocation -> activity);
296 356
         return topBar;
297 357
     }
358
+
359
+    private Component component(Alignment alignment) {
360
+        Component component = new Component();
361
+        component.name = new Text("myComp");
362
+        component.alignment = alignment;
363
+        component.componentId = new Text("compId");
364
+        return component;
365
+    }
298 366
 }

+ 11
- 45
lib/android/app/src/test/java/com/reactnativenavigation/viewcontrollers/TitleBarTest.java View File

@@ -1,26 +1,18 @@
1 1
 package com.reactnativenavigation.viewcontrollers;
2 2
 
3 3
 import android.app.Activity;
4
-import android.support.v7.widget.Toolbar;
5
-import android.view.Gravity;
6
-import android.view.ViewGroup;
4
+import android.view.View;
7 5
 
8 6
 import com.reactnativenavigation.BaseTest;
9 7
 import com.reactnativenavigation.mocks.ImageLoaderMock;
10
-import com.reactnativenavigation.mocks.TitleBarReactViewCreatorMock;
11 8
 import com.reactnativenavigation.mocks.TopBarButtonCreatorMock;
12
-import com.reactnativenavigation.parse.Alignment;
13
-import com.reactnativenavigation.parse.Component;
14 9
 import com.reactnativenavigation.parse.params.Button;
15 10
 import com.reactnativenavigation.parse.params.Text;
16 11
 import com.reactnativenavigation.react.Constants;
17 12
 import com.reactnativenavigation.react.ReactView;
18
-import com.reactnativenavigation.utils.ViewUtils;
19 13
 import com.reactnativenavigation.views.titlebar.TitleBar;
20
-import com.reactnativenavigation.views.titlebar.TitleBarReactView;
21 14
 
22 15
 import org.junit.Test;
23
-import org.mockito.ArgumentCaptor;
24 16
 
25 17
 import java.util.ArrayList;
26 18
 import java.util.Arrays;
@@ -30,7 +22,6 @@ import java.util.List;
30 22
 import java.util.Map;
31 23
 
32 24
 import static org.assertj.core.api.Java6Assertions.assertThat;
33
-import static org.mockito.ArgumentMatchers.any;
34 25
 import static org.mockito.Mockito.spy;
35 26
 import static org.mockito.Mockito.times;
36 27
 import static org.mockito.Mockito.verify;
@@ -42,15 +33,15 @@ public class TitleBarTest extends BaseTest {
42 33
     private Button textButton;
43 34
     private Button customButton;
44 35
     private Map<String, TopBarButtonController> buttonControllers;
36
+    private Activity activity;
45 37
 
46 38
     @Override
47 39
     public void beforeEach() {
48 40
         final TopBarButtonCreatorMock buttonCreator = new TopBarButtonCreatorMock();
49
-        final Activity activity = newActivity();
41
+        activity = newActivity();
50 42
         createButtons();
51 43
         buttonControllers = new HashMap<>();
52
-        TitleBarReactViewCreatorMock reactViewCreator = new TitleBarReactViewCreatorMock();
53
-        uut = spy(new TitleBar(activity, buttonCreator, reactViewCreator, (buttonId -> {}), ImageLoaderMock.mock()) {
44
+        uut = spy(new TitleBar(activity, buttonCreator, buttonId -> {}, ImageLoaderMock.mock()) {
54 45
             @Override
55 46
             public TopBarButtonController createButtonController(Button button) {
56 47
                 TopBarButtonController controller = spy(super.createButtonController(button));
@@ -146,47 +137,22 @@ public class TitleBarTest extends BaseTest {
146 137
 
147 138
     @Test
148 139
     public void setComponent_addsComponentToTitleBar() {
149
-        uut.setComponent(component("com.rnn.CustomView", Alignment.Center));
150
-        verify(uut, times(1)).addView(any(TitleBarReactView.class), any(Toolbar.LayoutParams.class));
151
-    }
152
-
153
-    private Component component(String name, Alignment alignment) {
154
-        Component component = new Component();
155
-        component.name = new Text(name);
156
-        component.alignment = alignment;
157
-        component.componentId = new Text("compId");
158
-        return component;
159
-    }
160
-
161
-    @Test
162
-    public void setComponent_alignFill() {
163
-        Component component = component("com.rnn.CustomView", Alignment.Fill);
140
+        View component = new View(activity);
164 141
         uut.setComponent(component);
165
-        verify(uut, times(1)).getComponentLayoutParams(component);
166
-        ArgumentCaptor<Toolbar.LayoutParams> lpCaptor = ArgumentCaptor.forClass(Toolbar.LayoutParams.class);
167
-        verify(uut, times(1)).addView(any(TitleBarReactView.class), lpCaptor.capture());
168
-        assertThat(lpCaptor.getValue().width == ViewGroup.LayoutParams.MATCH_PARENT);
169
-    }
170
-
171
-    @Test
172
-    public void setComponent_alignCenter() {
173
-        Component component = component("com.rnn.CustomView", Alignment.Center);
174
-        uut.setComponent(component);
175
-        verify(uut, times(1)).getComponentLayoutParams(component);
176
-        ArgumentCaptor<Toolbar.LayoutParams> lpCaptor = ArgumentCaptor.forClass(Toolbar.LayoutParams.class);
177
-        verify(uut, times(1)).addView(any(TitleBarReactView.class), lpCaptor.capture());
178
-        assertThat(lpCaptor.getValue().width == ViewGroup.LayoutParams.WRAP_CONTENT);
179
-        assertThat(lpCaptor.getValue().gravity == Gravity.CENTER);
142
+        verify(uut).addView(component);
180 143
     }
181 144
 
182 145
     @Test
183 146
     public void clear() {
184
-        uut.setComponent(component("someComponent", Alignment.Center));
147
+        View title = new View(activity);
148
+        uut.setComponent(title);
149
+        verify(uut).addView(title);
150
+
185 151
         uut.clear();
186 152
         assertThat(uut.getTitle()).isNullOrEmpty();
187 153
         assertThat(uut.getMenu().size()).isZero();
188 154
         assertThat(uut.getNavigationIcon()).isNull();
189
-        assertThat(ViewUtils.findChildrenByClassRecursive(uut, TitleBarReactView.class).size()).isZero();
155
+        verify(uut).removeView(title);
190 156
     }
191 157
 
192 158
     private List<Button> leftButton(Button leftButton) {

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

@@ -5,7 +5,6 @@ import android.content.Context;
5 5
 import android.support.annotation.NonNull;
6 6
 
7 7
 import com.reactnativenavigation.BaseTest;
8
-import com.reactnativenavigation.mocks.TitleBarReactViewCreatorMock;
9 8
 import com.reactnativenavigation.mocks.TopBarBackgroundViewCreatorMock;
10 9
 import com.reactnativenavigation.mocks.TopBarButtonCreatorMock;
11 10
 import com.reactnativenavigation.utils.ImageLoader;
@@ -13,7 +12,6 @@ import com.reactnativenavigation.viewcontrollers.topbar.TopBarBackgroundViewCont
13 12
 import com.reactnativenavigation.viewcontrollers.topbar.TopBarController;
14 13
 import com.reactnativenavigation.views.StackLayout;
15 14
 import com.reactnativenavigation.views.titlebar.TitleBar;
16
-import com.reactnativenavigation.views.titlebar.TitleBarReactViewCreator;
17 15
 import com.reactnativenavigation.views.topbar.TopBar;
18 16
 
19 17
 import org.junit.Test;
@@ -38,18 +36,18 @@ public class TopBarControllerTest extends BaseTest {
38 36
         uut = new TopBarController() {
39 37
             @NonNull
40 38
             @Override
41
-            protected TopBar createTopBar(Context context, ReactViewCreator buttonCreator, TitleBarReactViewCreator titleBarReactViewCreator, TopBarBackgroundViewController topBarBackgroundViewController, TopBarButtonController.OnClickListener topBarButtonClickListener, StackLayout stackLayout, ImageLoader imageLoader) {
42
-                return new TopBar(context, buttonCreator, titleBarReactViewCreator, topBarBackgroundViewController, topBarButtonClickListener, stackLayout, imageLoader) {
39
+            protected TopBar createTopBar(Context context, ReactViewCreator buttonCreator, TopBarBackgroundViewController topBarBackgroundViewController, TopBarButtonController.OnClickListener topBarButtonClickListener, StackLayout stackLayout, ImageLoader imageLoader) {
40
+                return new TopBar(context, buttonCreator, topBarBackgroundViewController, topBarButtonClickListener, stackLayout, imageLoader) {
43 41
                     @Override
44
-                    protected TitleBar createTitleBar(Context context, ReactViewCreator buttonCreator, TitleBarReactViewCreator reactViewCreator, TopBarButtonController.OnClickListener onClickListener, ImageLoader imageLoader) {
45
-                        titleBar[0] = spy(super.createTitleBar(context, buttonCreator, reactViewCreator, onClickListener, imageLoader));
42
+                    protected TitleBar createTitleBar(Context context, ReactViewCreator buttonCreator, TopBarButtonController.OnClickListener onClickListener, ImageLoader imageLoader) {
43
+                        titleBar[0] = spy(super.createTitleBar(context, buttonCreator, onClickListener, imageLoader));
46 44
                         return titleBar[0];
47 45
                     }
48 46
                 };
49 47
             }
50 48
         };
51 49
         Activity activity = newActivity();
52
-        uut.createView(activity, new TopBarButtonCreatorMock(), new TitleBarReactViewCreatorMock(), new TopBarBackgroundViewController(activity, new TopBarBackgroundViewCreatorMock()), buttonId -> { }, Mockito.mock(StackLayout.class));
50
+        uut.createView(activity, new TopBarButtonCreatorMock(), new TopBarBackgroundViewController(activity, new TopBarBackgroundViewCreatorMock()), buttonId -> {}, Mockito.mock(StackLayout.class));
53 51
         uut.clear();
54 52
         verify(titleBar[0], times(1)).clear();
55 53
     }

+ 13
- 10
lib/android/app/src/test/java/com/reactnativenavigation/viewcontrollers/stack/StackControllerTest.java View File

@@ -32,7 +32,6 @@ import com.reactnativenavigation.viewcontrollers.topbar.TopBarController;
32 32
 import com.reactnativenavigation.views.Component;
33 33
 import com.reactnativenavigation.views.ReactComponent;
34 34
 import com.reactnativenavigation.views.StackLayout;
35
-import com.reactnativenavigation.views.titlebar.TitleBarReactViewCreator;
36 35
 import com.reactnativenavigation.views.topbar.TopBar;
37 36
 
38 37
 import org.assertj.core.api.iterable.Extractor;
@@ -73,7 +72,7 @@ public class StackControllerTest extends BaseTest {
73 72
         animator = Mockito.mock(NavigationAnimator.class);
74 73
         activity = newActivity();
75 74
         childRegistry = new ChildControllersRegistry();
76
-        presenter = new StackOptionsPresenter(activity, new Options());
75
+        presenter = spy(new StackOptionsPresenter(activity, new TitleBarReactViewCreatorMock(), new Options()));
77 76
         child1 = spy(new SimpleViewController(activity, childRegistry, "child1", new Options()));
78 77
         child2 = spy(new SimpleViewController(activity, childRegistry, "child2", new Options()));
79 78
         child3 = spy(new SimpleViewController(activity, childRegistry, "child3", new Options()));
@@ -231,12 +230,11 @@ public class StackControllerTest extends BaseTest {
231 230
     public void pop_layoutHandlesChildWillDisappear() {
232 231
         uut = new StackControllerBuilder(activity)
233 232
                         .setTopBarButtonCreator(new TopBarButtonCreatorMock())
234
-                        .setTitleBarReactViewCreator(new TitleBarReactViewCreatorMock())
235 233
                         .setTopBarBackgroundViewController(new TopBarBackgroundViewController(activity, new TopBarBackgroundViewCreatorMock()))
236 234
                         .setTopBarController(new TopBarController())
237 235
                         .setId("uut")
238 236
                         .setInitialOptions(new Options())
239
-                        .setStackPresenter(new StackOptionsPresenter(activity, new Options()))
237
+                        .setStackPresenter(new StackOptionsPresenter(activity, new TitleBarReactViewCreatorMock(), new Options()))
240 238
                         .build();
241 239
         uut.ensureViewIsCreated();
242 240
         uut.push(child1, new CommandListenerAdapter());
@@ -264,6 +262,13 @@ public class StackControllerTest extends BaseTest {
264 262
         assertThat(uut.isEmpty()).isFalse();
265 263
     }
266 264
 
265
+    @Test
266
+    public void onChildDestroyed() {
267
+        Component childView = (Component) child2.getView();
268
+        uut.onChildDestroyed(childView);
269
+        verify(presenter).onChildDestroyed(childView);
270
+    }
271
+
267 272
     @Test
268 273
     public void handleBack_PopsUnlessSingleChild() {
269 274
         assertThat(uut.isEmpty()).isTrue();
@@ -750,12 +755,11 @@ public class StackControllerTest extends BaseTest {
750 755
     public void mergeChildOptions_updatesViewWithNewOptions() {
751 756
         StackController uut = spy(new StackControllerBuilder(activity)
752 757
                         .setTopBarButtonCreator(new TopBarButtonCreatorMock())
753
-                        .setTitleBarReactViewCreator(new TitleBarReactViewCreatorMock())
754 758
                         .setTopBarBackgroundViewController(new TopBarBackgroundViewController(activity, new TopBarBackgroundViewCreatorMock()))
755 759
                         .setTopBarController(new TopBarController())
756 760
                         .setId("stack")
757 761
                         .setInitialOptions(new Options())
758
-                        .setStackPresenter(new StackOptionsPresenter(activity, new Options()))
762
+                        .setStackPresenter(new StackOptionsPresenter(activity, new TitleBarReactViewCreatorMock(), new Options()))
759 763
                         .build());
760 764
         Options optionsToMerge = new Options();
761 765
         Component component = mock(Component.class);
@@ -767,12 +771,11 @@ public class StackControllerTest extends BaseTest {
767 771
     public void mergeChildOptions_updatesParentControllerWithNewOptions() {
768 772
         StackController uut = new StackControllerBuilder(activity)
769 773
                         .setTopBarButtonCreator(new TopBarButtonCreatorMock())
770
-                        .setTitleBarReactViewCreator(new TitleBarReactViewCreatorMock())
771 774
                         .setTopBarBackgroundViewController(new TopBarBackgroundViewController(activity, new TopBarBackgroundViewCreatorMock()))
772 775
                         .setTopBarController(new TopBarController())
773 776
                         .setId("stack")
774 777
                         .setInitialOptions(new Options())
775
-                        .setStackPresenter(new StackOptionsPresenter(activity, new Options()))
778
+                        .setStackPresenter(new StackOptionsPresenter(activity, new TitleBarReactViewCreatorMock(), new Options()))
776 779
                         .build();
777 780
         ParentController parentController = Mockito.mock(ParentController.class);
778 781
         uut.setParentController(parentController);
@@ -848,8 +851,8 @@ public class StackControllerTest extends BaseTest {
848 851
     private void createTopBarController() {
849 852
         topBarController = spy(new TopBarController() {
850 853
             @Override
851
-            protected TopBar createTopBar(Context context, ReactViewCreator buttonCreator, TitleBarReactViewCreator titleBarReactViewCreator, TopBarBackgroundViewController topBarBackgroundViewController, TopBarButtonController.OnClickListener topBarButtonClickListener, StackLayout stackLayout, ImageLoader imageLoader) {
852
-                TopBar spy = spy(super.createTopBar(context, buttonCreator, titleBarReactViewCreator, topBarBackgroundViewController, topBarButtonClickListener, stackLayout, ImageLoaderMock.mock()));
854
+            protected TopBar createTopBar(Context context, ReactViewCreator buttonCreator, TopBarBackgroundViewController topBarBackgroundViewController, TopBarButtonController.OnClickListener topBarButtonClickListener, StackLayout stackLayout, ImageLoader imageLoader) {
855
+                TopBar spy = spy(super.createTopBar(context, buttonCreator, topBarBackgroundViewController, topBarButtonClickListener, stackLayout, ImageLoaderMock.mock()));
853 856
                 spy.layout(0, 0, 1000, 100);
854 857
                 return spy;
855 858
             }

+ 2
- 3
lib/android/app/src/test/java/com/reactnativenavigation/views/TopBarBackgroundComponentTest.java View File

@@ -8,7 +8,6 @@ import android.view.ViewGroup;
8 8
 import com.reactnativenavigation.BaseTest;
9 9
 import com.reactnativenavigation.R;
10 10
 import com.reactnativenavigation.mocks.ImageLoaderMock;
11
-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.Component;
@@ -42,8 +41,8 @@ public class TopBarBackgroundComponentTest extends BaseTest {
42 41
         });
43 42
         Activity activity = newActivity();
44 43
         topBarBackgroundViewController = spy(new TopBarBackgroundViewController(activity, new TopBarBackgroundViewCreatorMock()));
45
-        StackLayout parent = new StackLayout(activity, new TopBarButtonCreatorMock(), new TitleBarReactViewCreatorMock(), topBarBackgroundViewController, new TopBarController(), onClickListener, null);
46
-        uut = new TopBar(activity, new TopBarButtonCreatorMock(), new TitleBarReactViewCreatorMock(), topBarBackgroundViewController, onClickListener, parent, ImageLoaderMock.mock());
44
+        StackLayout parent = new StackLayout(activity, new TopBarButtonCreatorMock(), topBarBackgroundViewController, new TopBarController(), onClickListener, null);
45
+        uut = new TopBar(activity, new TopBarButtonCreatorMock(), topBarBackgroundViewController, onClickListener, parent, ImageLoaderMock.mock());
47 46
         parent.addView(uut);
48 47
     }
49 48
 

+ 2
- 14
lib/android/app/src/test/java/com/reactnativenavigation/views/TopBarTest.java View File

@@ -7,7 +7,6 @@ import android.view.MenuItem;
7 7
 import com.reactnativenavigation.BaseTest;
8 8
 import com.reactnativenavigation.anim.TopBarAnimator;
9 9
 import com.reactnativenavigation.mocks.ImageLoaderMock;
10
-import com.reactnativenavigation.mocks.TitleBarReactViewCreatorMock;
11 10
 import com.reactnativenavigation.mocks.TopBarBackgroundViewCreatorMock;
12 11
 import com.reactnativenavigation.mocks.TopBarButtonCreatorMock;
13 12
 import com.reactnativenavigation.parse.AnimationOptions;
@@ -35,7 +34,6 @@ public class TopBarTest extends BaseTest {
35 34
 
36 35
     private TopBar uut;
37 36
     private TopBarAnimator animator;
38
-    private ArrayList<Button> leftButton;
39 37
     private ArrayList<Button> rightButtons;
40 38
     private TopBarButtonController.OnClickListener onClickListener;
41 39
 
@@ -50,24 +48,14 @@ public class TopBarTest extends BaseTest {
50 48
         });
51 49
         Activity activity = newActivity();
52 50
         TopBarBackgroundViewController topBarBackgroundViewController = new TopBarBackgroundViewController(activity, new TopBarBackgroundViewCreatorMock());
53
-        StackLayout parent = new StackLayout(activity, new TopBarButtonCreatorMock(), new TitleBarReactViewCreatorMock(), topBarBackgroundViewController, new TopBarController(), this.onClickListener, null);
54
-        uut = new TopBar(activity, new TopBarButtonCreatorMock(), new TitleBarReactViewCreatorMock(), topBarBackgroundViewController, this.onClickListener, parent, ImageLoaderMock.mock());
51
+        StackLayout parent = new StackLayout(activity, new TopBarButtonCreatorMock(), topBarBackgroundViewController, new TopBarController(), this.onClickListener, null);
52
+        uut = new TopBar(activity, new TopBarButtonCreatorMock(), topBarBackgroundViewController, this.onClickListener, parent, ImageLoaderMock.mock());
55 53
         animator = spy(new TopBarAnimator(uut));
56 54
         uut.setAnimator(animator);
57
-        leftButton = createLeftButton();
58 55
         rightButtons = createRightButtons();
59 56
         parent.addView(uut);
60 57
     }
61 58
 
62
-    private ArrayList<Button> createLeftButton() {
63
-        ArrayList<Button> result = new ArrayList<>();
64
-        Button leftButton = new Button();
65
-        leftButton.id = "leftButton";
66
-        leftButton.text = new Text("");
67
-        result.add(spy(leftButton));
68
-        return result;
69
-    }
70
-
71 59
     private ArrayList<Button> createRightButtons() {
72 60
         ArrayList<Button> result = new ArrayList<>();
73 61
         for (int i = 0; i < 2; i++) {