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
                 .setChildren(createChildren(node.children))
162
                 .setChildren(createChildren(node.children))
163
                 .setChildRegistry(childRegistry)
163
                 .setChildRegistry(childRegistry)
164
                 .setTopBarButtonCreator(new TitleBarButtonCreator(reactInstanceManager))
164
                 .setTopBarButtonCreator(new TitleBarButtonCreator(reactInstanceManager))
165
-                .setTitleBarReactViewCreator(new TitleBarReactViewCreator(reactInstanceManager))
166
                 .setTopBarBackgroundViewController(new TopBarBackgroundViewController(activity, new TopBarBackgroundViewCreator(reactInstanceManager)))
165
                 .setTopBarBackgroundViewController(new TopBarBackgroundViewController(activity, new TopBarBackgroundViewCreator(reactInstanceManager)))
167
                 .setTopBarController(new TopBarController())
166
                 .setTopBarController(new TopBarController())
168
                 .setId(node.id)
167
                 .setId(node.id)
169
                 .setInitialOptions(parse(typefaceManager, node.getOptions()))
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
                 .build();
170
                 .build();
173
 	}
171
 	}
174
 
172
 

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

1
 package com.reactnativenavigation.presentation;
1
 package com.reactnativenavigation.presentation;
2
 
2
 
3
 import android.app.Activity;
3
 import android.app.Activity;
4
-import android.content.Context;
5
 import android.graphics.Color;
4
 import android.graphics.Color;
6
 import android.support.annotation.Nullable;
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
 import android.view.View;
9
 import android.view.View;
8
 import android.view.ViewGroup.LayoutParams;
10
 import android.view.ViewGroup.LayoutParams;
9
 
11
 
12
+import com.reactnativenavigation.parse.Alignment;
10
 import com.reactnativenavigation.parse.AnimationsOptions;
13
 import com.reactnativenavigation.parse.AnimationsOptions;
11
 import com.reactnativenavigation.parse.Options;
14
 import com.reactnativenavigation.parse.Options;
12
 import com.reactnativenavigation.parse.OrientationOptions;
15
 import com.reactnativenavigation.parse.OrientationOptions;
17
 import com.reactnativenavigation.parse.params.Button;
20
 import com.reactnativenavigation.parse.params.Button;
18
 import com.reactnativenavigation.utils.UiUtils;
21
 import com.reactnativenavigation.utils.UiUtils;
19
 import com.reactnativenavigation.viewcontrollers.IReactView;
22
 import com.reactnativenavigation.viewcontrollers.IReactView;
23
+import com.reactnativenavigation.viewcontrollers.TitleBarReactViewController;
20
 import com.reactnativenavigation.views.Component;
24
 import com.reactnativenavigation.views.Component;
25
+import com.reactnativenavigation.views.titlebar.TitleBarReactViewCreator;
21
 import com.reactnativenavigation.views.topbar.TopBar;
26
 import com.reactnativenavigation.views.topbar.TopBar;
22
 
27
 
23
 import java.util.ArrayList;
28
 import java.util.ArrayList;
29
+import java.util.HashMap;
24
 import java.util.List;
30
 import java.util.List;
31
+import java.util.Map;
25
 
32
 
26
 public class StackOptionsPresenter {
33
 public class StackOptionsPresenter {
27
     private static final int DEFAULT_TITLE_COLOR = Color.BLACK;
34
     private static final int DEFAULT_TITLE_COLOR = Color.BLACK;
30
     private static final double DEFAULT_ELEVATION = 4d;
37
     private static final double DEFAULT_ELEVATION = 4d;
31
     private final double defaultTitleFontSize;
38
     private final double defaultTitleFontSize;
32
     private final double defaultSubtitleFontSize;
39
     private final double defaultSubtitleFontSize;
40
+    private final Activity activity;
33
 
41
 
34
     private TopBar topBar;
42
     private TopBar topBar;
43
+    private TitleBarReactViewCreator titleViewCreator;
35
     private Options defaultOptions;
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
         this.defaultOptions = defaultOptions;
50
         this.defaultOptions = defaultOptions;
51
+        defaultTitleFontSize = UiUtils.dpToSp(activity, 18);
52
+        defaultSubtitleFontSize = UiUtils.dpToSp(activity, 14);
41
     }
53
     }
42
 
54
 
43
     public void setDefaultOptions(Options defaultOptions) {
55
     public void setDefaultOptions(Options defaultOptions) {
78
         ((Activity) topBar.getContext()).setRequestedOrientation(withDefaultOptions.getValue());
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
     private void applyTopBarOptions(TopBarOptions options, AnimationsOptions animationOptions, Component component, Options componentOptions) {
100
     private void applyTopBarOptions(TopBarOptions options, AnimationsOptions animationOptions, Component component, Options componentOptions) {
82
         topBar.setHeight(options.height.get(LayoutParams.WRAP_CONTENT));
101
         topBar.setHeight(options.height.get(LayoutParams.WRAP_CONTENT));
83
         topBar.setElevation(options.elevation.get(DEFAULT_ELEVATION));
102
         topBar.setElevation(options.elevation.get(DEFAULT_ELEVATION));
84
 
103
 
85
         topBar.setTitleHeight(options.title.height.get(LayoutParams.WRAP_CONTENT));
104
         topBar.setTitleHeight(options.title.height.get(LayoutParams.WRAP_CONTENT));
86
         topBar.setTitle(options.title.text.get(""));
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
         topBar.setTitleFontSize(options.title.fontSize.get(defaultTitleFontSize));
119
         topBar.setTitleFontSize(options.title.fontSize.get(defaultTitleFontSize));
89
         topBar.setTitleTextColor(options.title.color.get(DEFAULT_TITLE_COLOR));
120
         topBar.setTitleTextColor(options.title.color.get(DEFAULT_TITLE_COLOR));
90
         topBar.setTitleTypeface(options.title.fontFamily);
121
         topBar.setTitleTypeface(options.title.fontFamily);
210
 
241
 
211
         if (options.title.height.hasValue()) topBar.setTitleHeight(options.title.height.get());
242
         if (options.title.height.hasValue()) topBar.setTitleHeight(options.title.height.get());
212
         if (options.title.text.hasValue()) topBar.setTitle(options.title.text.get());
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
         if (options.title.color.hasValue()) topBar.setTitleTextColor(options.title.color.get());
257
         if (options.title.color.hasValue()) topBar.setTitleTextColor(options.title.color.get());
215
         if (options.title.fontSize.hasValue()) topBar.setTitleFontSize(options.title.fontSize.get());
258
         if (options.title.fontSize.hasValue()) topBar.setTitleFontSize(options.title.fontSize.get());
216
         if (options.title.fontFamily != null) topBar.setTitleTypeface(options.title.fontFamily);
259
         if (options.title.fontFamily != null) topBar.setTitleTypeface(options.title.fontFamily);
262
     private void mergeTopTabOptions(TopTabOptions topTabOptions) {
305
     private void mergeTopTabOptions(TopTabOptions topTabOptions) {
263
         if (topTabOptions.fontFamily != null) topBar.setTopTabFontFamily(topTabOptions.tabIndex, topTabOptions.fontFamily);
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
 
63
 
64
     @Override
64
     @Override
65
     public void mergeOptions(Options options) {
65
     public void mergeOptions(Options options) {
66
-        applyOnParentController(parentController -> parentController.mergeChildOptions(options, getView()));
66
+        performOnParentController(parentController -> parentController.mergeChildOptions(options, getView()));
67
         super.mergeOptions(options);
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
     ReactComponent getComponent() {
76
     ReactComponent getComponent() {
71
         return view;
77
         return view;
72
     }
78
     }

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

117
 
117
 
118
 	@CallSuper
118
 	@CallSuper
119
     protected void clearOptions() {
119
     protected void clearOptions() {
120
-	    applyOnParentController(parent -> ((ParentController) parent).clearOptions());
120
+	    performOnParentController(parent -> ((ParentController) parent).clearOptions());
121
         options = initialOptions.copy().clearOneTimeOptions();
121
         options = initialOptions.copy().clearOneTimeOptions();
122
     }
122
     }
123
 
123
 
133
     public boolean isRendered() {
133
     public boolean isRendered() {
134
         return getCurrentChild() != null && getCurrentChild().isRendered();
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
     @Override
64
     @Override
65
     public void applyChildOptions(Options options, Component child) {
65
     public void applyChildOptions(Options options, Component child) {
66
         super.applyChildOptions(options, child);
66
         super.applyChildOptions(options, child);
67
-        applyOnParentController(parentController ->
67
+        performOnParentController(parentController ->
68
                 ((ParentController) parentController).applyChildOptions(this.options, child)
68
                 ((ParentController) parentController).applyChildOptions(this.options, child)
69
         );
69
         );
70
     }
70
     }
73
     public void mergeChildOptions(Options options, Component child) {
73
     public void mergeChildOptions(Options options, Component child) {
74
         super.mergeChildOptions(options, child);
74
         super.mergeChildOptions(options, child);
75
         new SideMenuOptionsPresenter(getView()).present(options.sideMenuRootOptions);
75
         new SideMenuOptionsPresenter(getView()).present(options.sideMenuRootOptions);
76
-        applyOnParentController(parentController ->
76
+        performOnParentController(parentController ->
77
                 ((ParentController) parentController).mergeChildOptions(options.copy().clearSideMenuOptions(), child)
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
         return activity;
118
         return activity;
119
     }
119
     }
120
 
120
 
121
-    protected void applyOnParentController(Task<ParentController> task) {
121
+    protected void performOnParentController(Task<ParentController> task) {
122
         if (parentController != null) task.run(parentController);
122
         if (parentController != null) task.run(parentController);
123
     }
123
     }
124
 
124
 
193
     public void onViewAppeared() {
193
     public void onViewAppeared() {
194
         isShown = true;
194
         isShown = true;
195
         applyOptions(options);
195
         applyOptions(options);
196
-        applyOnParentController(parentController -> {
196
+        performOnParentController(parentController -> {
197
             parentController.clearOptions();
197
             parentController.clearOptions();
198
             if (getView() instanceof Component) parentController.applyChildOptions(options, (Component) getView());
198
             if (getView() instanceof Component) parentController.applyChildOptions(options, (Component) getView());
199
         });
199
         });
234
         }
234
         }
235
     }
235
     }
236
 
236
 
237
+    protected boolean isDestroyed() {
238
+        return isDestroyed;
239
+    }
240
+
237
     @Override
241
     @Override
238
     public void onGlobalLayout() {
242
     public void onGlobalLayout() {
239
         if (!isShown && isViewShown()) {
243
         if (!isShown && isViewShown()) {

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

84
     public void applyChildOptions(Options options, Component child) {
84
     public void applyChildOptions(Options options, Component child) {
85
         super.applyChildOptions(options, child);
85
         super.applyChildOptions(options, child);
86
         presenter.applyChildOptions(this.options, child);
86
         presenter.applyChildOptions(this.options, child);
87
-        applyOnParentController(parentController ->
87
+        performOnParentController(parentController ->
88
                 ((ParentController) parentController).applyChildOptions(this.options.copy().clearBottomTabsOptions().clearBottomTabOptions(), child)
88
                 ((ParentController) parentController).applyChildOptions(this.options.copy().clearBottomTabsOptions().clearBottomTabOptions(), child)
89
         );
89
         );
90
     }
90
     }
94
         super.mergeChildOptions(options, child);
94
         super.mergeChildOptions(options, child);
95
         presenter.mergeChildOptions(options, child);
95
         presenter.mergeChildOptions(options, child);
96
         tabPresenter.mergeChildOptions(options, child);
96
         tabPresenter.mergeChildOptions(options, child);
97
-        applyOnParentController(parentController ->
97
+        performOnParentController(parentController ->
98
                 ((ParentController) parentController).mergeChildOptions(options.copy().clearBottomTabsOptions(), child)
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
 import com.reactnativenavigation.views.Component;
26
 import com.reactnativenavigation.views.Component;
27
 import com.reactnativenavigation.views.ReactComponent;
27
 import com.reactnativenavigation.views.ReactComponent;
28
 import com.reactnativenavigation.views.StackLayout;
28
 import com.reactnativenavigation.views.StackLayout;
29
-import com.reactnativenavigation.views.titlebar.TitleBarReactViewCreator;
30
 import com.reactnativenavigation.views.topbar.TopBar;
29
 import com.reactnativenavigation.views.topbar.TopBar;
31
 
30
 
32
 import java.util.Collection;
31
 import java.util.Collection;
40
     private final IdStack<ViewController> stack = new IdStack<>();
39
     private final IdStack<ViewController> stack = new IdStack<>();
41
     private final NavigationAnimator animator;
40
     private final NavigationAnimator animator;
42
     private final ReactViewCreator topBarButtonCreator;
41
     private final ReactViewCreator topBarButtonCreator;
43
-    private final TitleBarReactViewCreator titleBarReactViewCreator;
44
     private TopBarBackgroundViewController topBarBackgroundViewController;
42
     private TopBarBackgroundViewController topBarBackgroundViewController;
45
     private TopBarController topBarController;
43
     private TopBarController topBarController;
46
     private BackButtonHelper backButtonHelper;
44
     private BackButtonHelper backButtonHelper;
47
     private final StackOptionsPresenter presenter;
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
         super(activity, childRegistry, id, presenter, initialOptions);
48
         super(activity, childRegistry, id, presenter, initialOptions);
51
         this.topBarController = topBarController;
49
         this.topBarController = topBarController;
52
         this.topBarButtonCreator = topBarButtonCreator;
50
         this.topBarButtonCreator = topBarButtonCreator;
53
-        this.titleBarReactViewCreator = titleBarReactViewCreator;
54
         this.topBarBackgroundViewController = topBarBackgroundViewController;
51
         this.topBarBackgroundViewController = topBarBackgroundViewController;
55
         this.animator = animator;
52
         this.animator = animator;
56
         this.backButtonHelper = backButtonHelper;
53
         this.backButtonHelper = backButtonHelper;
79
         if (child instanceof ReactComponent) {
76
         if (child instanceof ReactComponent) {
80
             fabOptionsPresenter.applyOptions(this.options.fabOptions, (ReactComponent) child, getView());
77
             fabOptionsPresenter.applyOptions(this.options.fabOptions, (ReactComponent) child, getView());
81
         }
78
         }
82
-        applyOnParentController(parentController ->
79
+        performOnParentController(parentController ->
83
                 ((ParentController) parentController).applyChildOptions(
80
                 ((ParentController) parentController).applyChildOptions(
84
                         this.options.copy()
81
                         this.options.copy()
85
                                 .clearTopBarOptions()
82
                                 .clearTopBarOptions()
99
         if (options.fabOptions.hasValue() && child instanceof ReactComponent) {
96
         if (options.fabOptions.hasValue() && child instanceof ReactComponent) {
100
             fabOptionsPresenter.mergeOptions(options.fabOptions, (ReactComponent) child, getView());
97
             fabOptionsPresenter.mergeOptions(options.fabOptions, (ReactComponent) child, getView());
101
         }
98
         }
102
-        applyOnParentController(parentController ->
99
+        performOnParentController(parentController ->
103
                 ((ParentController) parentController).mergeChildOptions(
100
                 ((ParentController) parentController).mergeChildOptions(
104
                         options.copy()
101
                         options.copy()
105
                                 .clearTopBarOptions()
102
                                 .clearTopBarOptions()
124
         topBarController.clear();
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
     public void push(ViewController child, CommandListener listener) {
130
     public void push(ViewController child, CommandListener listener) {
128
         final ViewController toRemove = stack.peek();
131
         final ViewController toRemove = stack.peek();
129
         child.setParentController(this);
132
         child.setParentController(this);
296
     protected StackLayout createView() {
299
     protected StackLayout createView() {
297
         StackLayout stackLayout = new StackLayout(getActivity(),
300
         StackLayout stackLayout = new StackLayout(getActivity(),
298
                 topBarButtonCreator,
301
                 topBarButtonCreator,
299
-                titleBarReactViewCreator,
300
                 topBarBackgroundViewController,
302
                 topBarBackgroundViewController,
301
                 topBarController,
303
                 topBarController,
302
                 this::onNavigationButtonPressed,
304
                 this::onNavigationButtonPressed,

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

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

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

9
 import com.reactnativenavigation.viewcontrollers.ReactViewCreator;
9
 import com.reactnativenavigation.viewcontrollers.ReactViewCreator;
10
 import com.reactnativenavigation.viewcontrollers.TopBarButtonController;
10
 import com.reactnativenavigation.viewcontrollers.TopBarButtonController;
11
 import com.reactnativenavigation.views.StackLayout;
11
 import com.reactnativenavigation.views.StackLayout;
12
-import com.reactnativenavigation.views.titlebar.TitleBarReactViewCreator;
13
 import com.reactnativenavigation.views.topbar.TopBar;
12
 import com.reactnativenavigation.views.topbar.TopBar;
14
 
13
 
15
 
14
 
16
 public class TopBarController {
15
 public class TopBarController {
17
     private TopBar topBar;
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
         if (topBar == null) {
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
             topBar.setId(CompatUtils.generateViewId());
21
             topBar.setId(CompatUtils.generateViewId());
23
         }
22
         }
24
         return topBar;
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
     public void clear() {
30
     public void clear() {

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

60
     @Override
60
     @Override
61
     public void onViewAppeared() {
61
     public void onViewAppeared() {
62
         super.onViewAppeared();
62
         super.onViewAppeared();
63
-        applyOnParentController(parentController -> ((ParentController) parentController).setupTopTabsWithViewPager(getView()));
63
+        performOnParentController(parentController -> ((ParentController) parentController).setupTopTabsWithViewPager(getView()));
64
         performOnCurrentTab(ViewController::onViewAppeared);
64
         performOnCurrentTab(ViewController::onViewAppeared);
65
     }
65
     }
66
 
66
 
73
     public void onViewDisappear() {
73
     public void onViewDisappear() {
74
         super.onViewDisappear();
74
         super.onViewDisappear();
75
         performOnCurrentTab(ViewController::onViewDisappear);
75
         performOnCurrentTab(ViewController::onViewDisappear);
76
-        applyOnParentController(parentController -> ((ParentController) parentController).clearTopTabs());
76
+        performOnParentController(parentController -> ((ParentController) parentController).clearTopTabs());
77
     }
77
     }
78
 
78
 
79
     @Override
79
     @Override
90
     @Override
90
     @Override
91
     public void applyChildOptions(Options options, Component child) {
91
     public void applyChildOptions(Options options, Component child) {
92
         super.applyChildOptions(options, child);
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
     @CallSuper
96
     @CallSuper
97
     public void mergeChildOptions(Options options, Component child) {
97
     public void mergeChildOptions(Options options, Component child) {
98
         super.mergeChildOptions(options, child);
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
     public void switchToTab(int index) {
102
     public void switchToTab(int index) {

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

8
 import com.reactnativenavigation.viewcontrollers.TopBarButtonController;
8
 import com.reactnativenavigation.viewcontrollers.TopBarButtonController;
9
 import com.reactnativenavigation.viewcontrollers.topbar.TopBarBackgroundViewController;
9
 import com.reactnativenavigation.viewcontrollers.topbar.TopBarBackgroundViewController;
10
 import com.reactnativenavigation.viewcontrollers.topbar.TopBarController;
10
 import com.reactnativenavigation.viewcontrollers.topbar.TopBarController;
11
-import com.reactnativenavigation.views.titlebar.TitleBarReactViewCreator;
12
 import com.reactnativenavigation.views.topbar.TopBar;
11
 import com.reactnativenavigation.views.topbar.TopBar;
13
 
12
 
14
 import static android.view.ViewGroup.LayoutParams.MATCH_PARENT;
13
 import static android.view.ViewGroup.LayoutParams.MATCH_PARENT;
18
 public class StackLayout extends RelativeLayout implements Component {
17
 public class StackLayout extends RelativeLayout implements Component {
19
     private String stackId;
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
         super(context);
21
         super(context);
23
         this.stackId = stackId;
22
         this.stackId = stackId;
24
-        createLayout(topBarButtonCreator, titleBarReactViewCreator, topBarBackgroundViewController, topBarController, topBarButtonClickListener);
23
+        createLayout(topBarButtonCreator, topBarBackgroundViewController, topBarController, topBarButtonClickListener);
25
         setContentDescription("StackLayout");
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
     public String getStackId() {
31
     public String getStackId() {

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

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

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

39
 import com.reactnativenavigation.viewcontrollers.topbar.TopBarBackgroundViewController;
39
 import com.reactnativenavigation.viewcontrollers.topbar.TopBarBackgroundViewController;
40
 import com.reactnativenavigation.views.StackLayout;
40
 import com.reactnativenavigation.views.StackLayout;
41
 import com.reactnativenavigation.views.titlebar.TitleBar;
41
 import com.reactnativenavigation.views.titlebar.TitleBar;
42
-import com.reactnativenavigation.views.titlebar.TitleBarReactViewCreator;
43
 import com.reactnativenavigation.views.toptabs.TopTabs;
42
 import com.reactnativenavigation.views.toptabs.TopTabs;
44
 
43
 
45
 import java.util.List;
44
 import java.util.List;
58
     private View border;
57
     private View border;
59
     private ImageLoader imageLoader;
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
         super(context);
61
         super(context);
63
         context.setTheme(R.style.TopBar);
62
         context.setTheme(R.style.TopBar);
64
         this.imageLoader = imageLoader;
63
         this.imageLoader = imageLoader;
66
         this.topBarBackgroundViewController = topBarBackgroundViewController;
65
         this.topBarBackgroundViewController = topBarBackgroundViewController;
67
         topTabs = new TopTabs(getContext());
66
         topTabs = new TopTabs(getContext());
68
         animator = new TopBarAnimator(this, parentView.getStackId());
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
         setId(CompatUtils.generateViewId());
72
         setId(CompatUtils.generateViewId());
74
-        titleBar = createTitleBar(getContext(), buttonCreator, titleBarReactViewCreator, onClickListener, imageLoader);
73
+        titleBar = createTitleBar(getContext(), buttonCreator, onClickListener, imageLoader);
75
         topTabs = createTopTabs();
74
         topTabs = createTopTabs();
76
         border = createBorder();
75
         border = createBorder();
77
         LinearLayout content = createContentLayout();
76
         LinearLayout content = createContentLayout();
111
         return border;
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
         titleBar.setId(CompatUtils.generateViewId());
115
         titleBar.setId(CompatUtils.generateViewId());
117
         return titleBar;
116
         return titleBar;
118
     }
117
     }
176
         titleBar.setTitleAlignment(alignment);
175
         titleBar.setTitleAlignment(alignment);
177
     }
176
     }
178
 
177
 
179
-    public void setTitleComponent(Component component) {
178
+    public void setTitleComponent(View component) {
180
         titleBar.setComponent(component);
179
         titleBar.setComponent(component);
181
     }
180
     }
182
 
181
 

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

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
     protected void disableShowModalAnimation(ViewController... modals) {
69
     protected void disableShowModalAnimation(ViewController... modals) {
64
         for (ViewController modal : modals) {
70
         for (ViewController modal : modals) {
65
             modal.options.animations.showModal.enable = new Bool(false);
71
             modal.options.animations.showModal.enable = new Bool(false);

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

16
 import com.reactnativenavigation.viewcontrollers.topbar.TopBarBackgroundViewController;
16
 import com.reactnativenavigation.viewcontrollers.topbar.TopBarBackgroundViewController;
17
 import com.reactnativenavigation.viewcontrollers.topbar.TopBarController;
17
 import com.reactnativenavigation.viewcontrollers.topbar.TopBarController;
18
 import com.reactnativenavigation.views.StackLayout;
18
 import com.reactnativenavigation.views.StackLayout;
19
-import com.reactnativenavigation.views.titlebar.TitleBarReactViewCreator;
20
 import com.reactnativenavigation.views.topbar.TopBar;
19
 import com.reactnativenavigation.views.topbar.TopBar;
21
 
20
 
22
 public class TestUtils {
21
 public class TestUtils {
25
                 .setId("stack")
24
                 .setId("stack")
26
                 .setChildRegistry(new ChildControllersRegistry())
25
                 .setChildRegistry(new ChildControllersRegistry())
27
                 .setTopBarButtonCreator(new TopBarButtonCreatorMock())
26
                 .setTopBarButtonCreator(new TopBarButtonCreatorMock())
28
-                .setTitleBarReactViewCreator(new TitleBarReactViewCreatorMock())
29
                 .setTopBarBackgroundViewController(new TopBarBackgroundViewController(activity, new TopBarBackgroundViewCreatorMock()))
27
                 .setTopBarBackgroundViewController(new TopBarBackgroundViewController(activity, new TopBarBackgroundViewCreatorMock()))
30
                 .setTopBarController(new TopBarController() {
28
                 .setTopBarController(new TopBarController() {
31
                     @Override
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
                         topBar.layout(0, 0, 1000, 100);
32
                         topBar.layout(0, 0, 1000, 100);
35
                         return topBar;
33
                         return topBar;
36
                     }
34
                     }
37
                 })
35
                 })
38
-                .setStackPresenter(new StackOptionsPresenter(activity, new Options()))
36
+                .setStackPresenter(new StackOptionsPresenter(activity, new TitleBarReactViewCreatorMock(), new Options()))
39
                 .setInitialOptions(new Options());
37
                 .setInitialOptions(new Options());
40
     }
38
     }
41
 }
39
 }

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

40
         getView().sendOnNavigationButtonPressed(buttonId);
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
     @Override
49
     @Override
44
     public String toString() {
50
     public String toString() {
45
         return "SimpleViewController " + getId();
51
         return "SimpleViewController " + getId();
47
 
53
 
48
     @Override
54
     @Override
49
     public void mergeOptions(Options options) {
55
     public void mergeOptions(Options options) {
50
-        applyOnParentController(parentController -> parentController.mergeChildOptions(options, getView()));
56
+        performOnParentController(parentController -> parentController.mergeChildOptions(options, getView()));
51
         super.mergeOptions(options);
57
         super.mergeOptions(options);
52
     }
58
     }
53
 
59
 

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

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

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

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

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

2
 
2
 
3
 import android.app.Activity;
3
 import android.app.Activity;
4
 import android.graphics.Typeface;
4
 import android.graphics.Typeface;
5
+import android.support.v7.widget.Toolbar;
6
+import android.view.Gravity;
5
 import android.view.View;
7
 import android.view.View;
6
 
8
 
7
 import com.reactnativenavigation.BaseTest;
9
 import com.reactnativenavigation.BaseTest;
8
 import com.reactnativenavigation.mocks.TestComponentLayout;
10
 import com.reactnativenavigation.mocks.TestComponentLayout;
9
 import com.reactnativenavigation.mocks.TestReactView;
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
 import com.reactnativenavigation.parse.Options;
15
 import com.reactnativenavigation.parse.Options;
11
 import com.reactnativenavigation.parse.OrientationOptions;
16
 import com.reactnativenavigation.parse.OrientationOptions;
12
 import com.reactnativenavigation.parse.SubtitleOptions;
17
 import com.reactnativenavigation.parse.SubtitleOptions;
18
 import com.reactnativenavigation.parse.params.Number;
23
 import com.reactnativenavigation.parse.params.Number;
19
 import com.reactnativenavigation.parse.params.Text;
24
 import com.reactnativenavigation.parse.params.Text;
20
 import com.reactnativenavigation.presentation.StackOptionsPresenter;
25
 import com.reactnativenavigation.presentation.StackOptionsPresenter;
21
-import com.reactnativenavigation.views.Component;
26
+import com.reactnativenavigation.views.titlebar.TitleBarReactView;
22
 import com.reactnativenavigation.views.topbar.TopBar;
27
 import com.reactnativenavigation.views.topbar.TopBar;
23
 
28
 
24
 import org.json.JSONObject;
29
 import org.json.JSONObject;
45
     private static final Options EMPTY_OPTIONS = new Options();
50
     private static final Options EMPTY_OPTIONS = new Options();
46
     private StackOptionsPresenter uut;
51
     private StackOptionsPresenter uut;
47
     private TestComponentLayout child;
52
     private TestComponentLayout child;
53
+    private TestComponentLayout otherChild;
48
     private Activity activity;
54
     private Activity activity;
49
     private TopBar topBar;
55
     private TopBar topBar;
50
 
56
 
51
     @Override
57
     @Override
52
     public void beforeEach() {
58
     public void beforeEach() {
53
         activity = spy(newActivity());
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
         topBar = mockTopBar();
68
         topBar = mockTopBar();
56
         uut.bindView(topBar);
69
         uut.bindView(topBar);
57
         child = spy(new TestComponentLayout(activity, new TestReactView(activity)));
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
     @Test
119
     @Test
157
         Options options = new Options();
216
         Options options = new Options();
158
         options.topBar.visible = new Bool(false);
217
         options.topBar.visible = new Bool(false);
159
         options.topBar.animate = new Bool(false);
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
         uut.applyLayoutParamsOptions(options, view);
221
         uut.applyLayoutParamsOptions(options, view);
163
         verify(topBar).hide();
222
         verify(topBar).hide();
176
         verify(topBar, times(0)).setBackgroundColor(anyInt());
235
         verify(topBar, times(0)).setBackgroundColor(anyInt());
177
     }
236
     }
178
 
237
 
238
+    @Test
179
     public void applyButtons_buttonColorIsMergedToButtons() {
239
     public void applyButtons_buttonColorIsMergedToButtons() {
180
         Options options = new Options();
240
         Options options = new Options();
181
         Button rightButton1 = new Button();
241
         Button rightButton1 = new Button();
295
         when(topBar.getContext()).then(invocation -> activity);
355
         when(topBar.getContext()).then(invocation -> activity);
296
         return topBar;
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
 package com.reactnativenavigation.viewcontrollers;
1
 package com.reactnativenavigation.viewcontrollers;
2
 
2
 
3
 import android.app.Activity;
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
 import com.reactnativenavigation.BaseTest;
6
 import com.reactnativenavigation.BaseTest;
9
 import com.reactnativenavigation.mocks.ImageLoaderMock;
7
 import com.reactnativenavigation.mocks.ImageLoaderMock;
10
-import com.reactnativenavigation.mocks.TitleBarReactViewCreatorMock;
11
 import com.reactnativenavigation.mocks.TopBarButtonCreatorMock;
8
 import com.reactnativenavigation.mocks.TopBarButtonCreatorMock;
12
-import com.reactnativenavigation.parse.Alignment;
13
-import com.reactnativenavigation.parse.Component;
14
 import com.reactnativenavigation.parse.params.Button;
9
 import com.reactnativenavigation.parse.params.Button;
15
 import com.reactnativenavigation.parse.params.Text;
10
 import com.reactnativenavigation.parse.params.Text;
16
 import com.reactnativenavigation.react.Constants;
11
 import com.reactnativenavigation.react.Constants;
17
 import com.reactnativenavigation.react.ReactView;
12
 import com.reactnativenavigation.react.ReactView;
18
-import com.reactnativenavigation.utils.ViewUtils;
19
 import com.reactnativenavigation.views.titlebar.TitleBar;
13
 import com.reactnativenavigation.views.titlebar.TitleBar;
20
-import com.reactnativenavigation.views.titlebar.TitleBarReactView;
21
 
14
 
22
 import org.junit.Test;
15
 import org.junit.Test;
23
-import org.mockito.ArgumentCaptor;
24
 
16
 
25
 import java.util.ArrayList;
17
 import java.util.ArrayList;
26
 import java.util.Arrays;
18
 import java.util.Arrays;
30
 import java.util.Map;
22
 import java.util.Map;
31
 
23
 
32
 import static org.assertj.core.api.Java6Assertions.assertThat;
24
 import static org.assertj.core.api.Java6Assertions.assertThat;
33
-import static org.mockito.ArgumentMatchers.any;
34
 import static org.mockito.Mockito.spy;
25
 import static org.mockito.Mockito.spy;
35
 import static org.mockito.Mockito.times;
26
 import static org.mockito.Mockito.times;
36
 import static org.mockito.Mockito.verify;
27
 import static org.mockito.Mockito.verify;
42
     private Button textButton;
33
     private Button textButton;
43
     private Button customButton;
34
     private Button customButton;
44
     private Map<String, TopBarButtonController> buttonControllers;
35
     private Map<String, TopBarButtonController> buttonControllers;
36
+    private Activity activity;
45
 
37
 
46
     @Override
38
     @Override
47
     public void beforeEach() {
39
     public void beforeEach() {
48
         final TopBarButtonCreatorMock buttonCreator = new TopBarButtonCreatorMock();
40
         final TopBarButtonCreatorMock buttonCreator = new TopBarButtonCreatorMock();
49
-        final Activity activity = newActivity();
41
+        activity = newActivity();
50
         createButtons();
42
         createButtons();
51
         buttonControllers = new HashMap<>();
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
             @Override
45
             @Override
55
             public TopBarButtonController createButtonController(Button button) {
46
             public TopBarButtonController createButtonController(Button button) {
56
                 TopBarButtonController controller = spy(super.createButtonController(button));
47
                 TopBarButtonController controller = spy(super.createButtonController(button));
146
 
137
 
147
     @Test
138
     @Test
148
     public void setComponent_addsComponentToTitleBar() {
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
         uut.setComponent(component);
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
     @Test
145
     @Test
183
     public void clear() {
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
         uut.clear();
151
         uut.clear();
186
         assertThat(uut.getTitle()).isNullOrEmpty();
152
         assertThat(uut.getTitle()).isNullOrEmpty();
187
         assertThat(uut.getMenu().size()).isZero();
153
         assertThat(uut.getMenu().size()).isZero();
188
         assertThat(uut.getNavigationIcon()).isNull();
154
         assertThat(uut.getNavigationIcon()).isNull();
189
-        assertThat(ViewUtils.findChildrenByClassRecursive(uut, TitleBarReactView.class).size()).isZero();
155
+        verify(uut).removeView(title);
190
     }
156
     }
191
 
157
 
192
     private List<Button> leftButton(Button leftButton) {
158
     private List<Button> leftButton(Button leftButton) {

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

5
 import android.support.annotation.NonNull;
5
 import android.support.annotation.NonNull;
6
 
6
 
7
 import com.reactnativenavigation.BaseTest;
7
 import com.reactnativenavigation.BaseTest;
8
-import com.reactnativenavigation.mocks.TitleBarReactViewCreatorMock;
9
 import com.reactnativenavigation.mocks.TopBarBackgroundViewCreatorMock;
8
 import com.reactnativenavigation.mocks.TopBarBackgroundViewCreatorMock;
10
 import com.reactnativenavigation.mocks.TopBarButtonCreatorMock;
9
 import com.reactnativenavigation.mocks.TopBarButtonCreatorMock;
11
 import com.reactnativenavigation.utils.ImageLoader;
10
 import com.reactnativenavigation.utils.ImageLoader;
13
 import com.reactnativenavigation.viewcontrollers.topbar.TopBarController;
12
 import com.reactnativenavigation.viewcontrollers.topbar.TopBarController;
14
 import com.reactnativenavigation.views.StackLayout;
13
 import com.reactnativenavigation.views.StackLayout;
15
 import com.reactnativenavigation.views.titlebar.TitleBar;
14
 import com.reactnativenavigation.views.titlebar.TitleBar;
16
-import com.reactnativenavigation.views.titlebar.TitleBarReactViewCreator;
17
 import com.reactnativenavigation.views.topbar.TopBar;
15
 import com.reactnativenavigation.views.topbar.TopBar;
18
 
16
 
19
 import org.junit.Test;
17
 import org.junit.Test;
38
         uut = new TopBarController() {
36
         uut = new TopBarController() {
39
             @NonNull
37
             @NonNull
40
             @Override
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
                     @Override
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
                         return titleBar[0];
44
                         return titleBar[0];
47
                     }
45
                     }
48
                 };
46
                 };
49
             }
47
             }
50
         };
48
         };
51
         Activity activity = newActivity();
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
         uut.clear();
51
         uut.clear();
54
         verify(titleBar[0], times(1)).clear();
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
 import com.reactnativenavigation.views.Component;
32
 import com.reactnativenavigation.views.Component;
33
 import com.reactnativenavigation.views.ReactComponent;
33
 import com.reactnativenavigation.views.ReactComponent;
34
 import com.reactnativenavigation.views.StackLayout;
34
 import com.reactnativenavigation.views.StackLayout;
35
-import com.reactnativenavigation.views.titlebar.TitleBarReactViewCreator;
36
 import com.reactnativenavigation.views.topbar.TopBar;
35
 import com.reactnativenavigation.views.topbar.TopBar;
37
 
36
 
38
 import org.assertj.core.api.iterable.Extractor;
37
 import org.assertj.core.api.iterable.Extractor;
73
         animator = Mockito.mock(NavigationAnimator.class);
72
         animator = Mockito.mock(NavigationAnimator.class);
74
         activity = newActivity();
73
         activity = newActivity();
75
         childRegistry = new ChildControllersRegistry();
74
         childRegistry = new ChildControllersRegistry();
76
-        presenter = new StackOptionsPresenter(activity, new Options());
75
+        presenter = spy(new StackOptionsPresenter(activity, new TitleBarReactViewCreatorMock(), new Options()));
77
         child1 = spy(new SimpleViewController(activity, childRegistry, "child1", new Options()));
76
         child1 = spy(new SimpleViewController(activity, childRegistry, "child1", new Options()));
78
         child2 = spy(new SimpleViewController(activity, childRegistry, "child2", new Options()));
77
         child2 = spy(new SimpleViewController(activity, childRegistry, "child2", new Options()));
79
         child3 = spy(new SimpleViewController(activity, childRegistry, "child3", new Options()));
78
         child3 = spy(new SimpleViewController(activity, childRegistry, "child3", new Options()));
231
     public void pop_layoutHandlesChildWillDisappear() {
230
     public void pop_layoutHandlesChildWillDisappear() {
232
         uut = new StackControllerBuilder(activity)
231
         uut = new StackControllerBuilder(activity)
233
                         .setTopBarButtonCreator(new TopBarButtonCreatorMock())
232
                         .setTopBarButtonCreator(new TopBarButtonCreatorMock())
234
-                        .setTitleBarReactViewCreator(new TitleBarReactViewCreatorMock())
235
                         .setTopBarBackgroundViewController(new TopBarBackgroundViewController(activity, new TopBarBackgroundViewCreatorMock()))
233
                         .setTopBarBackgroundViewController(new TopBarBackgroundViewController(activity, new TopBarBackgroundViewCreatorMock()))
236
                         .setTopBarController(new TopBarController())
234
                         .setTopBarController(new TopBarController())
237
                         .setId("uut")
235
                         .setId("uut")
238
                         .setInitialOptions(new Options())
236
                         .setInitialOptions(new Options())
239
-                        .setStackPresenter(new StackOptionsPresenter(activity, new Options()))
237
+                        .setStackPresenter(new StackOptionsPresenter(activity, new TitleBarReactViewCreatorMock(), new Options()))
240
                         .build();
238
                         .build();
241
         uut.ensureViewIsCreated();
239
         uut.ensureViewIsCreated();
242
         uut.push(child1, new CommandListenerAdapter());
240
         uut.push(child1, new CommandListenerAdapter());
264
         assertThat(uut.isEmpty()).isFalse();
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
     @Test
272
     @Test
268
     public void handleBack_PopsUnlessSingleChild() {
273
     public void handleBack_PopsUnlessSingleChild() {
269
         assertThat(uut.isEmpty()).isTrue();
274
         assertThat(uut.isEmpty()).isTrue();
750
     public void mergeChildOptions_updatesViewWithNewOptions() {
755
     public void mergeChildOptions_updatesViewWithNewOptions() {
751
         StackController uut = spy(new StackControllerBuilder(activity)
756
         StackController uut = spy(new StackControllerBuilder(activity)
752
                         .setTopBarButtonCreator(new TopBarButtonCreatorMock())
757
                         .setTopBarButtonCreator(new TopBarButtonCreatorMock())
753
-                        .setTitleBarReactViewCreator(new TitleBarReactViewCreatorMock())
754
                         .setTopBarBackgroundViewController(new TopBarBackgroundViewController(activity, new TopBarBackgroundViewCreatorMock()))
758
                         .setTopBarBackgroundViewController(new TopBarBackgroundViewController(activity, new TopBarBackgroundViewCreatorMock()))
755
                         .setTopBarController(new TopBarController())
759
                         .setTopBarController(new TopBarController())
756
                         .setId("stack")
760
                         .setId("stack")
757
                         .setInitialOptions(new Options())
761
                         .setInitialOptions(new Options())
758
-                        .setStackPresenter(new StackOptionsPresenter(activity, new Options()))
762
+                        .setStackPresenter(new StackOptionsPresenter(activity, new TitleBarReactViewCreatorMock(), new Options()))
759
                         .build());
763
                         .build());
760
         Options optionsToMerge = new Options();
764
         Options optionsToMerge = new Options();
761
         Component component = mock(Component.class);
765
         Component component = mock(Component.class);
767
     public void mergeChildOptions_updatesParentControllerWithNewOptions() {
771
     public void mergeChildOptions_updatesParentControllerWithNewOptions() {
768
         StackController uut = new StackControllerBuilder(activity)
772
         StackController uut = new StackControllerBuilder(activity)
769
                         .setTopBarButtonCreator(new TopBarButtonCreatorMock())
773
                         .setTopBarButtonCreator(new TopBarButtonCreatorMock())
770
-                        .setTitleBarReactViewCreator(new TitleBarReactViewCreatorMock())
771
                         .setTopBarBackgroundViewController(new TopBarBackgroundViewController(activity, new TopBarBackgroundViewCreatorMock()))
774
                         .setTopBarBackgroundViewController(new TopBarBackgroundViewController(activity, new TopBarBackgroundViewCreatorMock()))
772
                         .setTopBarController(new TopBarController())
775
                         .setTopBarController(new TopBarController())
773
                         .setId("stack")
776
                         .setId("stack")
774
                         .setInitialOptions(new Options())
777
                         .setInitialOptions(new Options())
775
-                        .setStackPresenter(new StackOptionsPresenter(activity, new Options()))
778
+                        .setStackPresenter(new StackOptionsPresenter(activity, new TitleBarReactViewCreatorMock(), new Options()))
776
                         .build();
779
                         .build();
777
         ParentController parentController = Mockito.mock(ParentController.class);
780
         ParentController parentController = Mockito.mock(ParentController.class);
778
         uut.setParentController(parentController);
781
         uut.setParentController(parentController);
848
     private void createTopBarController() {
851
     private void createTopBarController() {
849
         topBarController = spy(new TopBarController() {
852
         topBarController = spy(new TopBarController() {
850
             @Override
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
                 spy.layout(0, 0, 1000, 100);
856
                 spy.layout(0, 0, 1000, 100);
854
                 return spy;
857
                 return spy;
855
             }
858
             }

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

8
 import com.reactnativenavigation.BaseTest;
8
 import com.reactnativenavigation.BaseTest;
9
 import com.reactnativenavigation.R;
9
 import com.reactnativenavigation.R;
10
 import com.reactnativenavigation.mocks.ImageLoaderMock;
10
 import com.reactnativenavigation.mocks.ImageLoaderMock;
11
-import com.reactnativenavigation.mocks.TitleBarReactViewCreatorMock;
12
 import com.reactnativenavigation.mocks.TopBarBackgroundViewCreatorMock;
11
 import com.reactnativenavigation.mocks.TopBarBackgroundViewCreatorMock;
13
 import com.reactnativenavigation.mocks.TopBarButtonCreatorMock;
12
 import com.reactnativenavigation.mocks.TopBarButtonCreatorMock;
14
 import com.reactnativenavigation.parse.Component;
13
 import com.reactnativenavigation.parse.Component;
42
         });
41
         });
43
         Activity activity = newActivity();
42
         Activity activity = newActivity();
44
         topBarBackgroundViewController = spy(new TopBarBackgroundViewController(activity, new TopBarBackgroundViewCreatorMock()));
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
         parent.addView(uut);
46
         parent.addView(uut);
48
     }
47
     }
49
 
48
 

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

7
 import com.reactnativenavigation.BaseTest;
7
 import com.reactnativenavigation.BaseTest;
8
 import com.reactnativenavigation.anim.TopBarAnimator;
8
 import com.reactnativenavigation.anim.TopBarAnimator;
9
 import com.reactnativenavigation.mocks.ImageLoaderMock;
9
 import com.reactnativenavigation.mocks.ImageLoaderMock;
10
-import com.reactnativenavigation.mocks.TitleBarReactViewCreatorMock;
11
 import com.reactnativenavigation.mocks.TopBarBackgroundViewCreatorMock;
10
 import com.reactnativenavigation.mocks.TopBarBackgroundViewCreatorMock;
12
 import com.reactnativenavigation.mocks.TopBarButtonCreatorMock;
11
 import com.reactnativenavigation.mocks.TopBarButtonCreatorMock;
13
 import com.reactnativenavigation.parse.AnimationOptions;
12
 import com.reactnativenavigation.parse.AnimationOptions;
35
 
34
 
36
     private TopBar uut;
35
     private TopBar uut;
37
     private TopBarAnimator animator;
36
     private TopBarAnimator animator;
38
-    private ArrayList<Button> leftButton;
39
     private ArrayList<Button> rightButtons;
37
     private ArrayList<Button> rightButtons;
40
     private TopBarButtonController.OnClickListener onClickListener;
38
     private TopBarButtonController.OnClickListener onClickListener;
41
 
39
 
50
         });
48
         });
51
         Activity activity = newActivity();
49
         Activity activity = newActivity();
52
         TopBarBackgroundViewController topBarBackgroundViewController = new TopBarBackgroundViewController(activity, new TopBarBackgroundViewCreatorMock());
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
         animator = spy(new TopBarAnimator(uut));
53
         animator = spy(new TopBarAnimator(uut));
56
         uut.setAnimator(animator);
54
         uut.setAnimator(animator);
57
-        leftButton = createLeftButton();
58
         rightButtons = createRightButtons();
55
         rightButtons = createRightButtons();
59
         parent.addView(uut);
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
     private ArrayList<Button> createRightButtons() {
59
     private ArrayList<Button> createRightButtons() {
72
         ArrayList<Button> result = new ArrayList<>();
60
         ArrayList<Button> result = new ArrayList<>();
73
         for (int i = 0; i < 2; i++) {
61
         for (int i = 0; i < 2; i++) {