Просмотр исходного кода

TopBar background component lifecycle methods

Guy Carmeli 6 лет назад
Родитель
Сommit
18b5e63756
20 измененных файлов: 150 добавлений и 67 удалений
  1. 2
    1
      lib/android/app/src/main/java/com/reactnativenavigation/parse/LayoutFactory.java
  2. 6
    6
      lib/android/app/src/main/java/com/reactnativenavigation/viewcontrollers/StackController.java
  3. 46
    0
      lib/android/app/src/main/java/com/reactnativenavigation/viewcontrollers/topbar/TopBarBackgroundViewController.java
  4. 4
    5
      lib/android/app/src/main/java/com/reactnativenavigation/viewcontrollers/topbar/TopBarController.java
  5. 5
    5
      lib/android/app/src/main/java/com/reactnativenavigation/views/StackLayout.java
  6. 13
    18
      lib/android/app/src/main/java/com/reactnativenavigation/views/topbar/TopBar.java
  7. 9
    1
      lib/android/app/src/test/java/com/reactnativenavigation/viewcontrollers/BottomTabsControllerTest.java
  8. 2
    1
      lib/android/app/src/test/java/com/reactnativenavigation/viewcontrollers/ComponentViewControllerTest.java
  9. 2
    1
      lib/android/app/src/test/java/com/reactnativenavigation/viewcontrollers/FloatingActionButtonTest.java
  10. 2
    1
      lib/android/app/src/test/java/com/reactnativenavigation/viewcontrollers/NavigatorTest.java
  11. 3
    2
      lib/android/app/src/test/java/com/reactnativenavigation/viewcontrollers/OptionsApplyingTest.java
  12. 10
    1
      lib/android/app/src/test/java/com/reactnativenavigation/viewcontrollers/ParentControllerTest.java
  13. 5
    4
      lib/android/app/src/test/java/com/reactnativenavigation/viewcontrollers/StackControllerTest.java
  14. 2
    1
      lib/android/app/src/test/java/com/reactnativenavigation/viewcontrollers/TopBarButtonControllerTest.java
  15. 6
    4
      lib/android/app/src/test/java/com/reactnativenavigation/viewcontrollers/TopBarControllerTest.java
  16. 2
    1
      lib/android/app/src/test/java/com/reactnativenavigation/viewcontrollers/TopTabsViewControllerTest.java
  17. 2
    1
      lib/android/app/src/test/java/com/reactnativenavigation/viewcontrollers/ViewControllerTest.java
  18. 7
    12
      lib/android/app/src/test/java/com/reactnativenavigation/views/TopBarBackgroundComponentTest.java
  19. 6
    2
      lib/android/app/src/test/java/com/reactnativenavigation/views/TopBarTest.java
  20. 16
    0
      playground/src/screens/TopBarBackground.js

+ 2
- 1
lib/android/app/src/main/java/com/reactnativenavigation/parse/LayoutFactory.java Просмотреть файл

@@ -13,6 +13,7 @@ import com.reactnativenavigation.viewcontrollers.ViewController;
13 13
 import com.reactnativenavigation.viewcontrollers.bottomtabs.BottomTabsController;
14 14
 import com.reactnativenavigation.viewcontrollers.externalcomponent.ExternalComponentCreator;
15 15
 import com.reactnativenavigation.viewcontrollers.externalcomponent.ExternalComponentViewController;
16
+import com.reactnativenavigation.viewcontrollers.topbar.TopBarBackgroundViewController;
16 17
 import com.reactnativenavigation.viewcontrollers.topbar.TopBarController;
17 18
 import com.reactnativenavigation.viewcontrollers.toptabs.TopTabsController;
18 19
 import com.reactnativenavigation.views.ComponentViewCreator;
@@ -124,7 +125,7 @@ public class LayoutFactory {
124 125
         StackController stackController = new StackController(activity,
125 126
                 new TitleBarButtonCreator(reactInstanceManager),
126 127
                 new TitleBarReactViewCreator(reactInstanceManager),
127
-                new TopBarBackgroundViewCreator(reactInstanceManager),
128
+                new TopBarBackgroundViewController(activity, new TopBarBackgroundViewCreator(reactInstanceManager)),
128 129
                 new TopBarController(),
129 130
                 node.id,
130 131
                 getOptions(node)

+ 6
- 6
lib/android/app/src/main/java/com/reactnativenavigation/viewcontrollers/StackController.java Просмотреть файл

@@ -10,13 +10,13 @@ import com.facebook.react.bridge.Promise;
10 10
 import com.reactnativenavigation.anim.NavigationAnimator;
11 11
 import com.reactnativenavigation.parse.Options;
12 12
 import com.reactnativenavigation.utils.NoOpPromise;
13
+import com.reactnativenavigation.viewcontrollers.topbar.TopBarBackgroundViewController;
13 14
 import com.reactnativenavigation.viewcontrollers.topbar.TopBarController;
14 15
 import com.reactnativenavigation.views.Component;
15 16
 import com.reactnativenavigation.views.ReactComponent;
16 17
 import com.reactnativenavigation.views.StackLayout;
17
-import com.reactnativenavigation.views.topbar.TopBar;
18 18
 import com.reactnativenavigation.views.titlebar.TitleBarReactViewCreator;
19
-import com.reactnativenavigation.views.topbar.TopBarBackgroundViewCreator;
19
+import com.reactnativenavigation.views.topbar.TopBar;
20 20
 
21 21
 import java.util.Collection;
22 22
 import java.util.Iterator;
@@ -30,16 +30,16 @@ public class StackController extends ParentController<StackLayout> {
30 30
     private final NavigationAnimator animator;
31 31
     private final ReactViewCreator topBarButtonCreator;
32 32
     private final TitleBarReactViewCreator titleBarReactViewCreator;
33
-    private TopBarBackgroundViewCreator topBarBackgroundViewCreator;
33
+    private TopBarBackgroundViewController topBarBackgroundViewController;
34 34
     private TopBarController topBarController;
35 35
 
36
-    public StackController(final Activity activity, ReactViewCreator topBarButtonCreator, TitleBarReactViewCreator titleBarReactViewCreator, TopBarBackgroundViewCreator topBarBackgroundViewCreator, TopBarController topBarController, String id, Options initialOptions) {
36
+    public StackController(final Activity activity, ReactViewCreator topBarButtonCreator, TitleBarReactViewCreator titleBarReactViewCreator, TopBarBackgroundViewController topBarBackgroundViewController, TopBarController topBarController, String id, Options initialOptions) {
37 37
         super(activity, id, initialOptions);
38 38
         this.topBarController = topBarController;
39 39
         animator = createAnimator();
40 40
         this.topBarButtonCreator = topBarButtonCreator;
41 41
         this.titleBarReactViewCreator = titleBarReactViewCreator;
42
-        this.topBarBackgroundViewCreator = topBarBackgroundViewCreator;
42
+        this.topBarBackgroundViewController = topBarBackgroundViewController;
43 43
     }
44 44
 
45 45
     public void applyOptions(Options options) {
@@ -238,7 +238,7 @@ public class StackController extends ParentController<StackLayout> {
238 238
     @NonNull
239 239
     @Override
240 240
     protected StackLayout createView() {
241
-        return new StackLayout(getActivity(), topBarButtonCreator, titleBarReactViewCreator, topBarBackgroundViewCreator, topBarController, this::sendOnNavigationButtonPressed, getId());
241
+        return new StackLayout(getActivity(), topBarButtonCreator, titleBarReactViewCreator, topBarBackgroundViewController, topBarController, this::sendOnNavigationButtonPressed, getId());
242 242
     }
243 243
 
244 244
     @NonNull

+ 46
- 0
lib/android/app/src/main/java/com/reactnativenavigation/viewcontrollers/topbar/TopBarBackgroundViewController.java Просмотреть файл

@@ -0,0 +1,46 @@
1
+package com.reactnativenavigation.viewcontrollers.topbar;
2
+
3
+import android.app.Activity;
4
+
5
+import com.reactnativenavigation.parse.Options;
6
+import com.reactnativenavigation.utils.CompatUtils;
7
+import com.reactnativenavigation.viewcontrollers.ViewController;
8
+import com.reactnativenavigation.views.topbar.TopBarBackgroundView;
9
+import com.reactnativenavigation.views.topbar.TopBarBackgroundViewCreator;
10
+
11
+public class TopBarBackgroundViewController extends ViewController<TopBarBackgroundView> {
12
+
13
+    private TopBarBackgroundViewCreator viewCreator;
14
+    private String component;
15
+
16
+    public TopBarBackgroundViewController(Activity activity, TopBarBackgroundViewCreator viewCreator) {
17
+        super(activity, CompatUtils.generateViewId() + "", new Options());
18
+        this.viewCreator = viewCreator;
19
+    }
20
+
21
+    @Override
22
+    protected TopBarBackgroundView createView() {
23
+        return viewCreator.create(getActivity(), getId(), component);
24
+    }
25
+
26
+    @Override
27
+    public void onViewAppeared() {
28
+        super.onViewAppeared();
29
+        view.sendComponentStart();
30
+    }
31
+
32
+    @Override
33
+    public void onViewDisappear() {
34
+        view.sendComponentStop();
35
+        super.onViewDisappear();
36
+    }
37
+
38
+    @Override
39
+    public void sendOnNavigationButtonPressed(String buttonId) {
40
+
41
+    }
42
+
43
+    public void setComponent(String component) {
44
+        this.component = component;
45
+    }
46
+}

+ 4
- 5
lib/android/app/src/main/java/com/reactnativenavigation/viewcontrollers/topbar/TopBarController.java Просмотреть файл

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

+ 5
- 5
lib/android/app/src/main/java/com/reactnativenavigation/views/StackLayout.java Просмотреть файл

@@ -9,9 +9,9 @@ import com.reactnativenavigation.parse.Options;
9 9
 import com.reactnativenavigation.presentation.OptionsPresenter;
10 10
 import com.reactnativenavigation.viewcontrollers.ReactViewCreator;
11 11
 import com.reactnativenavigation.viewcontrollers.TopBarButtonController;
12
+import com.reactnativenavigation.viewcontrollers.topbar.TopBarBackgroundViewController;
12 13
 import com.reactnativenavigation.viewcontrollers.topbar.TopBarController;
13 14
 import com.reactnativenavigation.views.titlebar.TitleBarReactViewCreator;
14
-import com.reactnativenavigation.views.topbar.TopBarBackgroundViewCreator;
15 15
 
16 16
 import static android.view.ViewGroup.LayoutParams.MATCH_PARENT;
17 17
 import static android.view.ViewGroup.LayoutParams.WRAP_CONTENT;
@@ -21,16 +21,16 @@ public class StackLayout extends RelativeLayout {
21 21
     private String stackId;
22 22
     private final OptionsPresenter optionsPresenter;
23 23
 
24
-    public StackLayout(Context context, ReactViewCreator topBarButtonCreator, TitleBarReactViewCreator titleBarReactViewCreator, TopBarBackgroundViewCreator topBarBackgroundViewCreator, TopBarController topBarController, TopBarButtonController.OnClickListener topBarButtonClickListener, String stackId) {
24
+    public StackLayout(Context context, ReactViewCreator topBarButtonCreator, TitleBarReactViewCreator titleBarReactViewCreator, TopBarBackgroundViewController topBarBackgroundViewController, TopBarController topBarController, TopBarButtonController.OnClickListener topBarButtonClickListener, String stackId) {
25 25
         super(context);
26 26
         this.stackId = stackId;
27
-        createLayout(topBarButtonCreator, titleBarReactViewCreator, topBarBackgroundViewCreator, topBarController, topBarButtonClickListener);
27
+        createLayout(topBarButtonCreator, titleBarReactViewCreator, topBarBackgroundViewController, topBarController, topBarButtonClickListener);
28 28
         optionsPresenter = new OptionsPresenter(topBarController.getView());
29 29
         setContentDescription("StackLayout");
30 30
     }
31 31
 
32
-    private void createLayout(ReactViewCreator buttonCreator, TitleBarReactViewCreator titleBarReactViewCreator, TopBarBackgroundViewCreator BackgroundViewCreator, TopBarController topBarController, TopBarButtonController.OnClickListener topBarButtonClickListener) {
33
-        addView(topBarController.createView(getContext(), buttonCreator, titleBarReactViewCreator, BackgroundViewCreator, topBarButtonClickListener, this), MATCH_PARENT, WRAP_CONTENT);
32
+    private void createLayout(ReactViewCreator buttonCreator, TitleBarReactViewCreator titleBarReactViewCreator, TopBarBackgroundViewController topBarBackgroundViewController, TopBarController topBarController, TopBarButtonController.OnClickListener topBarButtonClickListener) {
33
+        addView(topBarController.createView(getContext(), buttonCreator, titleBarReactViewCreator, topBarBackgroundViewController, topBarButtonClickListener, this), MATCH_PARENT, WRAP_CONTENT);
34 34
     }
35 35
 
36 36
     public void applyChildOptions(Options options) {

+ 13
- 18
lib/android/app/src/main/java/com/reactnativenavigation/views/topbar/TopBar.java Просмотреть файл

@@ -1,7 +1,6 @@
1 1
 package com.reactnativenavigation.views.topbar;
2 2
 
3 3
 import android.annotation.SuppressLint;
4
-import android.app.Activity;
5 4
 import android.content.Context;
6 5
 import android.graphics.Typeface;
7 6
 import android.support.annotation.RestrictTo;
@@ -27,10 +26,11 @@ import com.reactnativenavigation.parse.params.Text;
27 26
 import com.reactnativenavigation.utils.CompatUtils;
28 27
 import com.reactnativenavigation.viewcontrollers.ReactViewCreator;
29 28
 import com.reactnativenavigation.viewcontrollers.TopBarButtonController;
29
+import com.reactnativenavigation.viewcontrollers.topbar.TopBarBackgroundViewController;
30 30
 import com.reactnativenavigation.views.StackLayout;
31
-import com.reactnativenavigation.views.toptabs.TopTabs;
32 31
 import com.reactnativenavigation.views.titlebar.TitleBar;
33 32
 import com.reactnativenavigation.views.titlebar.TitleBarReactViewCreator;
33
+import com.reactnativenavigation.views.toptabs.TopTabs;
34 34
 
35 35
 import java.util.List;
36 36
 
@@ -45,13 +45,12 @@ public class TopBar extends AppBarLayout implements ScrollEventListener.ScrollAw
45 45
     private TopTabs topTabs;
46 46
     private RelativeLayout root;
47 47
     private StackLayout parentView;
48
-    private TopBarBackgroundViewCreator topBarBackgroundViewCreator;
49
-    private TopBarBackgroundView backgroundView;
48
+    private TopBarBackgroundViewController topBarBackgroundViewController;
50 49
 
51
-    public TopBar(final Context context, ReactViewCreator buttonCreator, TitleBarReactViewCreator titleBarReactViewCreator, TopBarBackgroundViewCreator topBarBackgroundViewCreator, TopBarButtonController.OnClickListener onClickListener, StackLayout parentView) {
50
+    public TopBar(final Context context, ReactViewCreator buttonCreator, TitleBarReactViewCreator titleBarReactViewCreator, TopBarBackgroundViewController topBarBackgroundViewController, TopBarButtonController.OnClickListener onClickListener, StackLayout parentView) {
52 51
         super(context);
53 52
         collapsingBehavior = new TopBarCollapseBehavior(this);
54
-        this.topBarBackgroundViewCreator = topBarBackgroundViewCreator;
53
+        this.topBarBackgroundViewController = topBarBackgroundViewController;
55 54
         this.parentView = parentView;
56 55
         topTabs = new TopTabs(getContext());
57 56
         animator = new TopBarAnimator(this, parentView.getStackId());
@@ -102,9 +101,9 @@ public class TopBar extends AppBarLayout implements ScrollEventListener.ScrollAw
102 101
 
103 102
     public void setBackgroundComponent(Text component) {
104 103
         if (component.hasValue()) {
105
-            backgroundView = topBarBackgroundViewCreator.create((Activity) getContext(), String.valueOf(CompatUtils.generateViewId()), component.get());
104
+            topBarBackgroundViewController.setComponent(component.get());
106 105
             RelativeLayout.LayoutParams lp = new RelativeLayout.LayoutParams(MATCH_PARENT, getHeight());
107
-            root.addView(backgroundView, 0, lp);
106
+            root.addView(topBarBackgroundViewController.getView(), 0, lp);
108 107
         }
109 108
     }
110 109
 
@@ -132,11 +131,6 @@ public class TopBar extends AppBarLayout implements ScrollEventListener.ScrollAw
132 131
         titleBar.setRightButtons(rightButtons);
133 132
     }
134 133
 
135
-    @RestrictTo(RestrictTo.Scope.TESTS)
136
-    public TextView getTitleTextView() {
137
-        return titleBar.getTitleTextView();
138
-    }
139
-
140 134
     public void setBackgroundColor(Color color) {
141 135
         titleBar.setBackgroundColor(color);
142 136
     }
@@ -198,11 +192,7 @@ public class TopBar extends AppBarLayout implements ScrollEventListener.ScrollAw
198 192
     }
199 193
 
200 194
     public void clear() {
201
-        if (backgroundView != null) {
202
-            backgroundView.destroy();
203
-            root.removeView(backgroundView);
204
-            backgroundView = null;
205
-        }
195
+        topBarBackgroundViewController.destroy();
206 196
         titleBar.clear();
207 197
     }
208 198
 
@@ -219,4 +209,9 @@ public class TopBar extends AppBarLayout implements ScrollEventListener.ScrollAw
219 209
     public void setAnimator(TopBarAnimator animator) {
220 210
         this.animator = animator;
221 211
     }
212
+
213
+    @RestrictTo(RestrictTo.Scope.TESTS)
214
+    public TextView getTitleTextView() {
215
+        return titleBar.getTitleTextView();
216
+    }
222 217
 }

+ 9
- 1
lib/android/app/src/test/java/com/reactnativenavigation/viewcontrollers/BottomTabsControllerTest.java Просмотреть файл

@@ -17,6 +17,7 @@ import com.reactnativenavigation.parse.params.Number;
17 17
 import com.reactnativenavigation.utils.ImageLoader;
18 18
 import com.reactnativenavigation.utils.OptionHelper;
19 19
 import com.reactnativenavigation.viewcontrollers.bottomtabs.BottomTabsController;
20
+import com.reactnativenavigation.viewcontrollers.topbar.TopBarBackgroundViewController;
20 21
 import com.reactnativenavigation.viewcontrollers.topbar.TopBarController;
21 22
 import com.reactnativenavigation.views.BottomTabs;
22 23
 import com.reactnativenavigation.views.ReactComponent;
@@ -174,6 +175,13 @@ public class BottomTabsControllerTest extends BaseTest {
174 175
     }
175 176
 
176 177
     private StackController createStack(String id) {
177
-        return new StackController(activity, new TopBarButtonCreatorMock(), new TitleBarReactViewCreatorMock(), new TopBarBackgroundViewCreatorMock(), new TopBarController(), id, tabOptions);
178
+        return new StackController(activity,
179
+                new TopBarButtonCreatorMock(),
180
+                new TitleBarReactViewCreatorMock(),
181
+                new TopBarBackgroundViewController(activity, new TopBarBackgroundViewCreatorMock()),
182
+                new TopBarController(),
183
+                id,
184
+                tabOptions
185
+        );
178 186
     }
179 187
 }

+ 2
- 1
lib/android/app/src/test/java/com/reactnativenavigation/viewcontrollers/ComponentViewControllerTest.java Просмотреть файл

@@ -9,6 +9,7 @@ import com.reactnativenavigation.mocks.TitleBarReactViewCreatorMock;
9 9
 import com.reactnativenavigation.mocks.TopBarBackgroundViewCreatorMock;
10 10
 import com.reactnativenavigation.mocks.TopBarButtonCreatorMock;
11 11
 import com.reactnativenavigation.parse.Options;
12
+import com.reactnativenavigation.viewcontrollers.topbar.TopBarBackgroundViewController;
12 13
 import com.reactnativenavigation.viewcontrollers.topbar.TopBarController;
13 14
 import com.reactnativenavigation.views.StackLayout;
14 15
 
@@ -29,7 +30,7 @@ public class ComponentViewControllerTest extends BaseTest {
29 30
         super.beforeEach();
30 31
         Activity activity = newActivity();
31 32
         view = spy(new TestComponentLayout(activity, new TestReactView(activity)));
32
-        ParentController<StackLayout> parentController = new StackController(activity, new TopBarButtonCreatorMock(), new TitleBarReactViewCreatorMock(), new TopBarBackgroundViewCreatorMock(), new TopBarController(), "stack", new Options());
33
+        ParentController<StackLayout> parentController = new StackController(activity, new TopBarButtonCreatorMock(), new TitleBarReactViewCreatorMock(), new TopBarBackgroundViewController(activity, new TopBarBackgroundViewCreatorMock()), new TopBarController(), "stack", new Options());
33 34
         uut = new ComponentViewController(activity, "componentId1", "componentName", (activity1, componentId, componentName) -> view, new Options());
34 35
         uut.setParentController(parentController);
35 36
         parentController.ensureViewIsCreated();

+ 2
- 1
lib/android/app/src/test/java/com/reactnativenavigation/viewcontrollers/FloatingActionButtonTest.java Просмотреть файл

@@ -14,6 +14,7 @@ import com.reactnativenavigation.mocks.TopBarButtonCreatorMock;
14 14
 import com.reactnativenavigation.parse.FabOptions;
15 15
 import com.reactnativenavigation.parse.Options;
16 16
 import com.reactnativenavigation.parse.params.Text;
17
+import com.reactnativenavigation.viewcontrollers.topbar.TopBarBackgroundViewController;
17 18
 import com.reactnativenavigation.viewcontrollers.topbar.TopBarController;
18 19
 import com.reactnativenavigation.views.Fab;
19 20
 import com.reactnativenavigation.views.FabMenu;
@@ -36,7 +37,7 @@ public class FloatingActionButtonTest extends BaseTest {
36 37
     public void beforeEach() {
37 38
         super.beforeEach();
38 39
         activity = newActivity();
39
-        stackController = new StackController(activity, new TopBarButtonCreatorMock(), new TitleBarReactViewCreatorMock(), new TopBarBackgroundViewCreatorMock(), new TopBarController(), "stackController", new Options());
40
+        stackController = new StackController(activity, new TopBarButtonCreatorMock(), new TitleBarReactViewCreatorMock(), new TopBarBackgroundViewController(activity, new TopBarBackgroundViewCreatorMock()), new TopBarController(), "stackController", new Options());
40 41
         Options options = getOptionsWithFab();
41 42
         childFab = new SimpleViewController(activity, "child1", options);
42 43
         childNoFab = new SimpleViewController(activity, "child2", new Options());

+ 2
- 1
lib/android/app/src/test/java/com/reactnativenavigation/viewcontrollers/NavigatorTest.java Просмотреть файл

@@ -17,6 +17,7 @@ import com.reactnativenavigation.utils.CompatUtils;
17 17
 import com.reactnativenavigation.utils.ImageLoader;
18 18
 import com.reactnativenavigation.utils.OptionHelper;
19 19
 import com.reactnativenavigation.viewcontrollers.bottomtabs.BottomTabsController;
20
+import com.reactnativenavigation.viewcontrollers.topbar.TopBarBackgroundViewController;
20 21
 import com.reactnativenavigation.viewcontrollers.topbar.TopBarController;
21 22
 
22 23
 import org.junit.Test;
@@ -251,7 +252,7 @@ public class NavigatorTest extends BaseTest {
251 252
 
252 253
     @NonNull
253 254
     private StackController newStack() {
254
-        return new StackController(activity, new TopBarButtonCreatorMock(), new TitleBarReactViewCreatorMock(), new TopBarBackgroundViewCreatorMock(), new TopBarController(),
255
+        return new StackController(activity, new TopBarButtonCreatorMock(), new TitleBarReactViewCreatorMock(), new TopBarBackgroundViewController(activity, new TopBarBackgroundViewCreatorMock()), new TopBarController(),
255 256
                 "stack" + CompatUtils.generateViewId(), tabOptions);
256 257
     }
257 258
 

+ 3
- 2
lib/android/app/src/test/java/com/reactnativenavigation/viewcontrollers/OptionsApplyingTest.java Просмотреть файл

@@ -19,6 +19,7 @@ import com.reactnativenavigation.parse.params.Bool;
19 19
 import com.reactnativenavigation.parse.params.Fraction;
20 20
 import com.reactnativenavigation.parse.params.Text;
21 21
 import com.reactnativenavigation.utils.ViewUtils;
22
+import com.reactnativenavigation.viewcontrollers.topbar.TopBarBackgroundViewController;
22 23
 import com.reactnativenavigation.viewcontrollers.topbar.TopBarController;
23 24
 import com.reactnativenavigation.views.topbar.TopBarBackgroundView;
24 25
 
@@ -52,7 +53,7 @@ public class OptionsApplyingTest extends BaseTest {
52 53
                 (activity1, componentId, componentName) -> view,
53 54
                 initialNavigationOptions
54 55
         );
55
-        stackController = new StackController(activity, new TopBarButtonCreatorMock(), new TitleBarReactViewCreatorMock(), new TopBarBackgroundViewCreatorMock(), new TopBarController(), "stack", new Options());
56
+        stackController = new StackController(activity, new TopBarButtonCreatorMock(), new TitleBarReactViewCreatorMock(), new TopBarBackgroundViewController(activity, new TopBarBackgroundViewCreatorMock()), new TopBarController(), "stack", new Options());
56 57
         stackController.ensureViewIsCreated();
57 58
         uut.setParentController(stackController);
58 59
     }
@@ -69,7 +70,7 @@ public class OptionsApplyingTest extends BaseTest {
69 70
     @Test
70 71
     public void initialOptionsAppliedOnAppear() {
71 72
         uut.options.topBarOptions.title.text = new Text("the title");
72
-        StackController stackController = new StackController(activity, new TopBarButtonCreatorMock(), new TitleBarReactViewCreatorMock(), new TopBarBackgroundViewCreatorMock(), new TopBarController(), "stackId", new Options());
73
+        StackController stackController = new StackController(activity, new TopBarButtonCreatorMock(), new TitleBarReactViewCreatorMock(), new TopBarBackgroundViewController(activity, new TopBarBackgroundViewCreatorMock()), new TopBarController(), "stackId", new Options());
73 74
         stackController.animatePush(uut, new MockPromise() {});
74 75
         assertThat(stackController.getTopBar().getTitle()).isEmpty();
75 76
 

+ 10
- 1
lib/android/app/src/test/java/com/reactnativenavigation/viewcontrollers/ParentControllerTest.java Просмотреть файл

@@ -13,6 +13,7 @@ import com.reactnativenavigation.mocks.TopBarBackgroundViewCreatorMock;
13 13
 import com.reactnativenavigation.mocks.TopBarButtonCreatorMock;
14 14
 import com.reactnativenavigation.parse.Options;
15 15
 import com.reactnativenavigation.parse.params.Text;
16
+import com.reactnativenavigation.viewcontrollers.topbar.TopBarBackgroundViewController;
16 17
 import com.reactnativenavigation.viewcontrollers.topbar.TopBarController;
17 18
 import com.reactnativenavigation.views.ReactComponent;
18 19
 
@@ -154,6 +155,14 @@ public class ParentControllerTest extends BaseTest {
154 155
     }
155 156
 
156 157
     private StackController createStack() {
157
-        return new StackController(activity, new TopBarButtonCreatorMock(), new TitleBarReactViewCreatorMock(), new TopBarBackgroundViewCreatorMock(), new TopBarController(), "stack", new Options());
158
+        return new StackController(
159
+                activity,
160
+                new TopBarButtonCreatorMock(),
161
+                new TitleBarReactViewCreatorMock(),
162
+                new TopBarBackgroundViewController(activity, new TopBarBackgroundViewCreatorMock()),
163
+                new TopBarController(),
164
+                "stack",
165
+                new Options()
166
+        );
158 167
     }
159 168
 }

+ 5
- 4
lib/android/app/src/test/java/com/reactnativenavigation/viewcontrollers/StackControllerTest.java Просмотреть файл

@@ -16,6 +16,7 @@ import com.reactnativenavigation.parse.Options;
16 16
 import com.reactnativenavigation.parse.params.Bool;
17 17
 import com.reactnativenavigation.parse.params.Text;
18 18
 import com.reactnativenavigation.utils.ViewHelper;
19
+import com.reactnativenavigation.viewcontrollers.topbar.TopBarBackgroundViewController;
19 20
 import com.reactnativenavigation.viewcontrollers.topbar.TopBarController;
20 21
 import com.reactnativenavigation.views.Component;
21 22
 import com.reactnativenavigation.views.ReactComponent;
@@ -106,7 +107,7 @@ public class StackControllerTest extends BaseTest {
106 107
     @Test
107 108
     public void pop_layoutHandlesChildWillDisappear() {
108 109
         final StackLayout[] stackLayout = new StackLayout[1];
109
-        uut = new StackController(activity, new TopBarButtonCreatorMock(), new TitleBarReactViewCreatorMock(), new TopBarBackgroundViewCreatorMock(), new TopBarController(), "uut", new Options()) {
110
+        uut = new StackController(activity, new TopBarButtonCreatorMock(), new TitleBarReactViewCreatorMock(), new TopBarBackgroundViewController(activity, new TopBarBackgroundViewCreatorMock()), new TopBarController(), "uut", new Options()) {
110 111
             @NonNull
111 112
             @Override
112 113
             protected StackLayout createView() {
@@ -466,7 +467,7 @@ public class StackControllerTest extends BaseTest {
466 467
     @Test
467 468
     public void mergeChildOptions_updatesViewWithNewOptions() {
468 469
         final StackLayout[] stackLayout = new StackLayout[1];
469
-        StackController uut = new StackController(activity, new TopBarButtonCreatorMock(), new TitleBarReactViewCreatorMock(), new TopBarBackgroundViewCreatorMock(), new TopBarController(), "stack", new Options()) {
470
+        StackController uut = new StackController(activity, new TopBarButtonCreatorMock(), new TitleBarReactViewCreatorMock(), new TopBarBackgroundViewController(activity, new TopBarBackgroundViewCreatorMock()), new TopBarController(), "stack", new Options()) {
470 471
             @NonNull
471 472
             @Override
472 473
             protected StackLayout createView() {
@@ -483,7 +484,7 @@ public class StackControllerTest extends BaseTest {
483 484
     @Test
484 485
     public void mergeChildOptions_updatesParentControllerWithNewOptions() {
485 486
         final StackLayout[] stackLayout = new StackLayout[1];
486
-        StackController uut = new StackController(activity, new TopBarButtonCreatorMock(), new TitleBarReactViewCreatorMock(), new TopBarBackgroundViewCreatorMock(), new TopBarController(), "stack", new Options()) {
487
+        StackController uut = new StackController(activity, new TopBarButtonCreatorMock(), new TitleBarReactViewCreatorMock(), new TopBarBackgroundViewController(activity, new TopBarBackgroundViewCreatorMock()), new TopBarController(), "stack", new Options()) {
487 488
             @NonNull
488 489
             @Override
489 490
             protected StackLayout createView() {
@@ -553,7 +554,7 @@ public class StackControllerTest extends BaseTest {
553 554
     private StackController createStackController(String id) {
554 555
         topBarController = spy(new TopBarController());
555 556
         return new StackController(activity,
556
-                new TopBarButtonCreatorMock(), new TitleBarReactViewCreatorMock(), new TopBarBackgroundViewCreatorMock(),
557
+                new TopBarButtonCreatorMock(), new TitleBarReactViewCreatorMock(), new TopBarBackgroundViewController(activity, new TopBarBackgroundViewCreatorMock()),
557 558
                 topBarController, id, new Options()) {
558 559
             @Override
559 560
             NavigationAnimator createAnimator() {

+ 2
- 1
lib/android/app/src/test/java/com/reactnativenavigation/viewcontrollers/TopBarButtonControllerTest.java Просмотреть файл

@@ -10,6 +10,7 @@ import com.reactnativenavigation.mocks.TopBarButtonCreatorMock;
10 10
 import com.reactnativenavigation.parse.Options;
11 11
 import com.reactnativenavigation.parse.params.Button;
12 12
 import com.reactnativenavigation.parse.params.Text;
13
+import com.reactnativenavigation.viewcontrollers.topbar.TopBarBackgroundViewController;
13 14
 import com.reactnativenavigation.viewcontrollers.topbar.TopBarController;
14 15
 
15 16
 import org.junit.Ignore;
@@ -31,7 +32,7 @@ public class TopBarButtonControllerTest extends BaseTest {
31 32
 
32 33
         TopBarButtonCreatorMock buttonCreatorMock = new TopBarButtonCreatorMock();
33 34
         uut = spy(new TopBarButtonController(activity, button, buttonCreatorMock, (buttonId) -> {}));
34
-        stackController = spy(new StackController(activity, buttonCreatorMock, new TitleBarReactViewCreatorMock(), new TopBarBackgroundViewCreatorMock(), new TopBarController(), "stack", new Options()));
35
+        stackController = spy(new StackController(activity, buttonCreatorMock, new TitleBarReactViewCreatorMock(), new TopBarBackgroundViewController(activity, new TopBarBackgroundViewCreatorMock()), new TopBarController(), "stack", new Options()));
35 36
 
36 37
     }
37 38
 

+ 6
- 4
lib/android/app/src/test/java/com/reactnativenavigation/viewcontrollers/TopBarControllerTest.java Просмотреть файл

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

+ 2
- 1
lib/android/app/src/test/java/com/reactnativenavigation/viewcontrollers/TopTabsViewControllerTest.java Просмотреть файл

@@ -14,6 +14,7 @@ import com.reactnativenavigation.mocks.TopBarButtonCreatorMock;
14 14
 import com.reactnativenavigation.parse.Options;
15 15
 import com.reactnativenavigation.parse.params.Text;
16 16
 import com.reactnativenavigation.utils.ViewHelper;
17
+import com.reactnativenavigation.viewcontrollers.topbar.TopBarBackgroundViewController;
17 18
 import com.reactnativenavigation.viewcontrollers.topbar.TopBarController;
18 19
 import com.reactnativenavigation.viewcontrollers.toptabs.TopTabsAdapter;
19 20
 import com.reactnativenavigation.viewcontrollers.toptabs.TopTabsController;
@@ -70,7 +71,7 @@ public class TopTabsViewControllerTest extends BaseTest {
70 71
 
71 72
     @NonNull
72 73
     private StackController createStackController(String id) {
73
-        return new StackController(activity, new TopBarButtonCreatorMock(), new TitleBarReactViewCreatorMock(), new TopBarBackgroundViewCreatorMock(), new TopBarController(), id, new Options());
74
+        return new StackController(activity, new TopBarButtonCreatorMock(), new TitleBarReactViewCreatorMock(), new TopBarBackgroundViewController(activity, new TopBarBackgroundViewCreatorMock()), new TopBarController(), id, new Options());
74 75
     }
75 76
 
76 77
     @NonNull

+ 2
- 1
lib/android/app/src/test/java/com/reactnativenavigation/viewcontrollers/ViewControllerTest.java Просмотреть файл

@@ -13,6 +13,7 @@ import com.reactnativenavigation.mocks.TitleBarReactViewCreatorMock;
13 13
 import com.reactnativenavigation.mocks.TopBarBackgroundViewCreatorMock;
14 14
 import com.reactnativenavigation.mocks.TopBarButtonCreatorMock;
15 15
 import com.reactnativenavigation.parse.Options;
16
+import com.reactnativenavigation.viewcontrollers.topbar.TopBarBackgroundViewController;
16 17
 import com.reactnativenavigation.viewcontrollers.topbar.TopBarController;
17 18
 
18 19
 import org.assertj.android.api.Assertions;
@@ -69,7 +70,7 @@ public class ViewControllerTest extends BaseTest {
69 70
     @Test
70 71
     public void holdsAReferenceToStackControllerOrNull() {
71 72
         assertThat(uut.getParentController()).isNull();
72
-        StackController nav = new StackController(activity, new TopBarButtonCreatorMock(), new TitleBarReactViewCreatorMock(), new TopBarBackgroundViewCreatorMock(), new TopBarController(), "stack", new Options());
73
+        StackController nav = new StackController(activity, new TopBarButtonCreatorMock(), new TitleBarReactViewCreatorMock(), new TopBarBackgroundViewController(activity, new TopBarBackgroundViewCreatorMock()), new TopBarController(), "stack", new Options());
73 74
         nav.animatePush(uut, new MockPromise());
74 75
         assertThat(uut.getParentController()).isEqualTo(nav);
75 76
     }

+ 7
- 12
lib/android/app/src/test/java/com/reactnativenavigation/views/TopBarBackgroundComponentTest.java Просмотреть файл

@@ -12,6 +12,7 @@ import com.reactnativenavigation.mocks.TopBarButtonCreatorMock;
12 12
 import com.reactnativenavigation.parse.params.Text;
13 13
 import com.reactnativenavigation.utils.ViewUtils;
14 14
 import com.reactnativenavigation.viewcontrollers.TopBarButtonController;
15
+import com.reactnativenavigation.viewcontrollers.topbar.TopBarBackgroundViewController;
15 16
 import com.reactnativenavigation.viewcontrollers.topbar.TopBarController;
16 17
 import com.reactnativenavigation.views.topbar.TopBar;
17 18
 import com.reactnativenavigation.views.topbar.TopBarBackgroundView;
@@ -25,7 +26,7 @@ import static org.mockito.Mockito.verify;
25 26
 
26 27
 public class TopBarBackgroundComponentTest extends BaseTest {
27 28
     private TopBar uut;
28
-    private TopBarBackgroundView backgroundView;
29
+    private TopBarBackgroundViewController topBarBackgroundViewController;
29 30
 
30 31
     @SuppressWarnings("Convert2Lambda")
31 32
     @Override
@@ -36,15 +37,10 @@ public class TopBarBackgroundComponentTest extends BaseTest {
36 37
                 Log.i("TopBarTest", "onPress: " + buttonId);
37 38
             }
38 39
         });
39
-        TopBarBackgroundViewCreatorMock backgroundViewCreator = new TopBarBackgroundViewCreatorMock() {
40
-            @Override
41
-            public TopBarBackgroundView create(Activity activity, String componentId, String componentName) {
42
-                backgroundView = spy(super.create(activity, componentId, componentName));
43
-                return backgroundView;
44
-            }
45
-        };
46
-        StackLayout parent = new StackLayout(newActivity(), new TopBarButtonCreatorMock(), new TitleBarReactViewCreatorMock(), backgroundViewCreator, new TopBarController(), onClickListener, null);
47
-        uut = new TopBar(newActivity(), new TopBarButtonCreatorMock(), new TitleBarReactViewCreatorMock(), backgroundViewCreator, onClickListener, parent);
40
+        Activity activity = newActivity();
41
+        topBarBackgroundViewController = spy(new TopBarBackgroundViewController(activity, new TopBarBackgroundViewCreatorMock()));
42
+        StackLayout parent = new StackLayout(activity, new TopBarButtonCreatorMock(), new TitleBarReactViewCreatorMock(), topBarBackgroundViewController, new TopBarController(), onClickListener, null);
43
+        uut = new TopBar(activity, new TopBarButtonCreatorMock(), new TitleBarReactViewCreatorMock(), topBarBackgroundViewController, onClickListener, parent);
48 44
         parent.addView(uut);
49 45
     }
50 46
 
@@ -68,7 +64,6 @@ public class TopBarBackgroundComponentTest extends BaseTest {
68 64
     public void clear_componentIsDestroyed() {
69 65
         uut.setBackgroundComponent(new Text("someComponent"));
70 66
         uut.clear();
71
-        verify(backgroundView, times(1)).destroy();
72
-        assertThat(backgroundView.getParent()).isNull();
67
+        verify(topBarBackgroundViewController, times(1)).destroy();
73 68
     }
74 69
 }

+ 6
- 2
lib/android/app/src/test/java/com/reactnativenavigation/views/TopBarTest.java Просмотреть файл

@@ -1,5 +1,6 @@
1 1
 package com.reactnativenavigation.views;
2 2
 
3
+import android.app.Activity;
3 4
 import android.util.Log;
4 5
 import android.view.MenuItem;
5 6
 
@@ -13,6 +14,7 @@ import com.reactnativenavigation.parse.params.Button;
13 14
 import com.reactnativenavigation.parse.params.Text;
14 15
 import com.reactnativenavigation.utils.TitleBarHelper;
15 16
 import com.reactnativenavigation.viewcontrollers.TopBarButtonController;
17
+import com.reactnativenavigation.viewcontrollers.topbar.TopBarBackgroundViewController;
16 18
 import com.reactnativenavigation.viewcontrollers.topbar.TopBarController;
17 19
 import com.reactnativenavigation.views.topbar.TopBar;
18 20
 
@@ -42,8 +44,10 @@ public class TopBarTest extends BaseTest {
42 44
                 Log.i("TopBarTest", "onPress: " + buttonId);
43 45
             }
44 46
         });
45
-        StackLayout parent = new StackLayout(newActivity(), new TopBarButtonCreatorMock(), new TitleBarReactViewCreatorMock(), new TopBarBackgroundViewCreatorMock(), new TopBarController(), this.onClickListener, null);
46
-        uut = new TopBar(newActivity(), new TopBarButtonCreatorMock(), new TitleBarReactViewCreatorMock(), new TopBarBackgroundViewCreatorMock(), this.onClickListener, parent);
47
+        Activity activity = newActivity();
48
+        TopBarBackgroundViewController topBarBackgroundViewController = new TopBarBackgroundViewController(activity, new TopBarBackgroundViewCreatorMock());
49
+        StackLayout parent = new StackLayout(activity, new TopBarButtonCreatorMock(), new TitleBarReactViewCreatorMock(), topBarBackgroundViewController, new TopBarController(), this.onClickListener, null);
50
+        uut = new TopBar(activity, new TopBarButtonCreatorMock(), new TitleBarReactViewCreatorMock(), topBarBackgroundViewController, this.onClickListener, parent);
47 51
         animator = spy(new TopBarAnimator(uut));
48 52
         uut.setAnimator(animator);
49 53
         leftButton = createLeftButton();

+ 16
- 0
playground/src/screens/TopBarBackground.js Просмотреть файл

@@ -13,6 +13,22 @@ class TopBarBackground extends Component {
13 13
     this.dots = new Array(55).fill('').map((ignored, i) => <View key={'dot' + i} style={styles.dot}/>);
14 14
   }
15 15
 
16
+  componentDidAppear() {
17
+    console.log('RNN', 'TBB.componentDidAppear');
18
+  }
19
+
20
+  componentDidDisappear() {
21
+    console.log('RNN', `TBB.componentDidDisappear`);
22
+  }
23
+
24
+  componentDidMount() {
25
+    console.log('RNN', `TBB.componentDidMount`);
26
+  }
27
+
28
+  componentWillUnmount() {
29
+    console.log('RNN', `TBB.componentWillUnmount`);
30
+  }
31
+
16 32
   render() {
17 33
     return (
18 34
       <View style={styles.container}>