Ver código fonte

TopBarBackgroundView impl

Guy Carmeli 6 anos atrás
pai
commit
15e184d020
21 arquivos alterados com 182 adições e 26 exclusões
  1. 2
    0
      lib/android/app/src/main/java/com/reactnativenavigation/parse/LayoutFactory.java
  2. 5
    0
      lib/android/app/src/main/java/com/reactnativenavigation/parse/TopBarBackgroundOptions.java
  3. 5
    2
      lib/android/app/src/main/java/com/reactnativenavigation/viewcontrollers/StackController.java
  4. 5
    4
      lib/android/app/src/main/java/com/reactnativenavigation/views/StackLayout.java
  5. 16
    2
      lib/android/app/src/main/java/com/reactnativenavigation/views/TopBar.java
  6. 23
    0
      lib/android/app/src/main/java/com/reactnativenavigation/views/topbar/TopBarBackgroundView.java
  7. 20
    0
      lib/android/app/src/main/java/com/reactnativenavigation/views/topbar/TopBarBackgroundViewCreator.java
  8. 1
    0
      lib/android/app/src/main/res/values/ids.xml
  9. 20
    0
      lib/android/app/src/test/java/com/reactnativenavigation/mocks/TopBarBackgroundViewCreatorMock.java
  10. 2
    1
      lib/android/app/src/test/java/com/reactnativenavigation/viewcontrollers/BottomTabsControllerTest.java
  11. 2
    1
      lib/android/app/src/test/java/com/reactnativenavigation/viewcontrollers/ComponentViewControllerTest.java
  12. 2
    1
      lib/android/app/src/test/java/com/reactnativenavigation/viewcontrollers/FloatingActionButtonTest.java
  13. 2
    1
      lib/android/app/src/test/java/com/reactnativenavigation/viewcontrollers/NavigatorTest.java
  14. 3
    2
      lib/android/app/src/test/java/com/reactnativenavigation/viewcontrollers/OptionsApplyingTest.java
  15. 2
    1
      lib/android/app/src/test/java/com/reactnativenavigation/viewcontrollers/ParentControllerTest.java
  16. 11
    6
      lib/android/app/src/test/java/com/reactnativenavigation/viewcontrollers/StackControllerTest.java
  17. 2
    1
      lib/android/app/src/test/java/com/reactnativenavigation/viewcontrollers/TopBarButtonControllerTest.java
  18. 2
    1
      lib/android/app/src/test/java/com/reactnativenavigation/viewcontrollers/TopTabsViewControllerTest.java
  19. 2
    1
      lib/android/app/src/test/java/com/reactnativenavigation/viewcontrollers/ViewControllerTest.java
  20. 51
    0
      lib/android/app/src/test/java/com/reactnativenavigation/views/TopBarBackgroundComponentTest.java
  21. 4
    2
      lib/android/app/src/test/java/com/reactnativenavigation/views/TopBarTest.java

+ 2
- 0
lib/android/app/src/main/java/com/reactnativenavigation/parse/LayoutFactory.java Ver arquivo

@@ -18,6 +18,7 @@ import com.reactnativenavigation.views.ComponentViewCreator;
18 18
 import com.reactnativenavigation.views.titlebar.TitleBarReactViewCreator;
19 19
 import com.reactnativenavigation.views.TopBarButtonCreator;
20 20
 import com.reactnativenavigation.views.TopTabsLayoutCreator;
21
+import com.reactnativenavigation.views.topbar.TopBarBackgroundViewCreator;
21 22
 
22 23
 import java.util.ArrayList;
23 24
 import java.util.List;
@@ -122,6 +123,7 @@ public class LayoutFactory {
122 123
         StackController stackController = new StackController(activity,
123 124
                 new TopBarButtonCreator(reactInstanceManager),
124 125
                 new TitleBarReactViewCreator(reactInstanceManager),
126
+                new TopBarBackgroundViewCreator(reactInstanceManager),
125 127
                 node.id,
126 128
                 getOptions(node)
127 129
         );

+ 5
- 0
lib/android/app/src/main/java/com/reactnativenavigation/parse/TopBarBackgroundOptions.java Ver arquivo

@@ -2,7 +2,10 @@ package com.reactnativenavigation.parse;
2 2
 
3 3
 import com.reactnativenavigation.parse.params.Color;
4 4
 import com.reactnativenavigation.parse.params.NullColor;
5
+import com.reactnativenavigation.parse.params.NullText;
6
+import com.reactnativenavigation.parse.params.Text;
5 7
 import com.reactnativenavigation.parse.parsers.ColorParser;
8
+import com.reactnativenavigation.parse.parsers.TextParser;
6 9
 
7 10
 import org.json.JSONObject;
8 11
 
@@ -14,11 +17,13 @@ public class TopBarBackgroundOptions {
14 17
         }
15 18
 
16 19
         options.color = ColorParser.parse(json, "color");
20
+        options.component = TextParser.parse(json, "component");
17 21
 
18 22
         return options;
19 23
     }
20 24
 
21 25
     public Color color = new NullColor();
26
+    public Text component = new NullText();
22 27
 
23 28
     void mergeWith(final TopBarBackgroundOptions other) {
24 29
         if (other.color.hasValue()) color = other.color;

+ 5
- 2
lib/android/app/src/main/java/com/reactnativenavigation/viewcontrollers/StackController.java Ver arquivo

@@ -15,6 +15,7 @@ import com.reactnativenavigation.views.ReactComponent;
15 15
 import com.reactnativenavigation.views.StackLayout;
16 16
 import com.reactnativenavigation.views.TopBar;
17 17
 import com.reactnativenavigation.views.titlebar.TitleBarReactViewCreator;
18
+import com.reactnativenavigation.views.topbar.TopBarBackgroundViewCreator;
18 19
 
19 20
 import java.util.Collection;
20 21
 import java.util.Iterator;
@@ -28,12 +29,14 @@ public class StackController extends ParentController<StackLayout> {
28 29
     private final NavigationAnimator animator;
29 30
     private final ReactViewCreator topBarButtonCreator;
30 31
     private final TitleBarReactViewCreator titleBarReactViewCreator;
32
+    private TopBarBackgroundViewCreator topBarBackgroundViewCreator;
31 33
 
32
-    public StackController(final Activity activity, ReactViewCreator topBarButtonCreator, TitleBarReactViewCreator titleBarReactViewCreator, String id, Options initialOptions) {
34
+    public StackController(final Activity activity, ReactViewCreator topBarButtonCreator, TitleBarReactViewCreator titleBarReactViewCreator, TopBarBackgroundViewCreator topBarBackgroundViewCreator, String id, Options initialOptions) {
33 35
         super(activity, id, initialOptions);
34 36
         animator = createAnimator();
35 37
         this.topBarButtonCreator = topBarButtonCreator;
36 38
         this.titleBarReactViewCreator = titleBarReactViewCreator;
39
+        this.topBarBackgroundViewCreator = topBarBackgroundViewCreator;
37 40
     }
38 41
 
39 42
     public void applyOptions(Options options) {
@@ -226,7 +229,7 @@ public class StackController extends ParentController<StackLayout> {
226 229
     @NonNull
227 230
     @Override
228 231
     protected StackLayout createView() {
229
-        return new StackLayout(getActivity(), topBarButtonCreator, titleBarReactViewCreator, this::sendOnNavigationButtonPressed);
232
+        return new StackLayout(getActivity(), topBarButtonCreator, titleBarReactViewCreator, topBarBackgroundViewCreator, this::sendOnNavigationButtonPressed);
230 233
     }
231 234
 
232 235
     @NonNull

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

@@ -13,6 +13,7 @@ import com.reactnativenavigation.utils.CompatUtils;
13 13
 import com.reactnativenavigation.viewcontrollers.ReactViewCreator;
14 14
 import com.reactnativenavigation.viewcontrollers.TopBarButtonController;
15 15
 import com.reactnativenavigation.views.titlebar.TitleBarReactViewCreator;
16
+import com.reactnativenavigation.views.topbar.TopBarBackgroundViewCreator;
16 17
 
17 18
 import static android.view.ViewGroup.LayoutParams.MATCH_PARENT;
18 19
 import static android.view.ViewGroup.LayoutParams.WRAP_CONTENT;
@@ -22,15 +23,15 @@ public class StackLayout extends RelativeLayout {
22 23
     private TopBar topBar;
23 24
     private final OptionsPresenter optionsPresenter;
24 25
 
25
-    public StackLayout(Context context, ReactViewCreator topBarButtonCreator, TitleBarReactViewCreator titleBarReactViewCreator, TopBarButtonController.OnClickListener topBarButtonClickListener) {
26
+    public StackLayout(Context context, ReactViewCreator topBarButtonCreator, TitleBarReactViewCreator titleBarReactViewCreator, TopBarBackgroundViewCreator topBarBackgroundViewCreator, TopBarButtonController.OnClickListener topBarButtonClickListener) {
26 27
         super(context);
27
-        createLayout(topBarButtonCreator, titleBarReactViewCreator, topBarButtonClickListener);
28
+        createLayout(topBarButtonCreator, titleBarReactViewCreator, topBarBackgroundViewCreator, topBarButtonClickListener);
28 29
         optionsPresenter = new OptionsPresenter(topBar);
29 30
         setContentDescription("StackLayout");
30 31
     }
31 32
 
32
-    private void createLayout(ReactViewCreator topBarButtonCreator, TitleBarReactViewCreator titleBarReactViewCreator, TopBarButtonController.OnClickListener topBarButtonClickListener) {
33
-        topBar = new TopBar(getContext(), topBarButtonCreator, titleBarReactViewCreator, topBarButtonClickListener, this);
33
+    private void createLayout(ReactViewCreator buttonCreator, TitleBarReactViewCreator titleBarReactViewCreator, TopBarBackgroundViewCreator BackgroundViewCreator, TopBarButtonController.OnClickListener topBarButtonClickListener) {
34
+        topBar = new TopBar(getContext(), buttonCreator, titleBarReactViewCreator, BackgroundViewCreator, topBarButtonClickListener, this);
34 35
         topBar.setId(CompatUtils.generateViewId());
35 36
         addView(topBar, MATCH_PARENT, WRAP_CONTENT);
36 37
     }

+ 16
- 2
lib/android/app/src/main/java/com/reactnativenavigation/views/TopBar.java Ver arquivo

@@ -13,12 +13,14 @@ import android.view.View;
13 13
 import android.widget.RelativeLayout;
14 14
 import android.widget.TextView;
15 15
 
16
+import com.reactnativenavigation.R;
16 17
 import com.reactnativenavigation.anim.AnimationListener;
17 18
 import com.reactnativenavigation.anim.TopBarAnimator;
18 19
 import com.reactnativenavigation.anim.TopBarCollapseBehavior;
19 20
 import com.reactnativenavigation.interfaces.ScrollEventListener;
20 21
 import com.reactnativenavigation.parse.AnimationOptions;
21 22
 import com.reactnativenavigation.parse.TitleOptions;
23
+import com.reactnativenavigation.parse.TopBarBackgroundOptions;
22 24
 import com.reactnativenavigation.parse.params.Button;
23 25
 import com.reactnativenavigation.parse.params.Color;
24 26
 import com.reactnativenavigation.parse.params.Fraction;
@@ -29,6 +31,8 @@ import com.reactnativenavigation.viewcontrollers.TitleBarReactViewController;
29 31
 import com.reactnativenavigation.viewcontrollers.TopBarButtonController;
30 32
 import com.reactnativenavigation.views.titlebar.TitleBar;
31 33
 import com.reactnativenavigation.views.titlebar.TitleBarReactViewCreator;
34
+import com.reactnativenavigation.views.topbar.TopBarBackgroundView;
35
+import com.reactnativenavigation.views.topbar.TopBarBackgroundViewCreator;
32 36
 
33 37
 import java.util.List;
34 38
 
@@ -43,12 +47,14 @@ public class TopBar extends AppBarLayout implements ScrollEventListener.ScrollAw
43 47
     private TopTabs topTabs;
44 48
     private RelativeLayout root;
45 49
     private StackLayout parentView;
50
+    private TopBarBackgroundViewCreator topBarBackgroundViewCreator;
46 51
 
47
-    public TopBar(final Context context, ReactViewCreator buttonCreator, TitleBarReactViewCreator titleBarReactViewCreator, TopBarButtonController.OnClickListener onClickListener, StackLayout parentView) {
52
+    public TopBar(final Context context, ReactViewCreator buttonCreator, TitleBarReactViewCreator titleBarReactViewCreator, TopBarBackgroundViewCreator topBarBackgroundViewCreator, TopBarButtonController.OnClickListener onClickListener, StackLayout parentView) {
48 53
         super(context);
49 54
         collapsingBehavior = new TopBarCollapseBehavior(this);
50
-        animator = new TopBarAnimator(this);
55
+        this.topBarBackgroundViewCreator = topBarBackgroundViewCreator;
51 56
         this.parentView = parentView;
57
+        animator = new TopBarAnimator(this);
52 58
         createLayout(buttonCreator, titleBarReactViewCreator, onClickListener);
53 59
     }
54 60
 
@@ -98,6 +104,14 @@ public class TopBar extends AppBarLayout implements ScrollEventListener.ScrollAw
98 104
         titleBar.setComponent(componentName, alignment);
99 105
     }
100 106
 
107
+    public void setBackgroundComponent(TopBarBackgroundOptions options) {
108
+        if (options.component.hasValue()) {
109
+            TopBarBackgroundView background = topBarBackgroundViewCreator.create((Activity) getContext(), String.valueOf(CompatUtils.generateViewId()), options.component.get());
110
+            background.setId(R.id.topBarBackgroundComponent);
111
+            root.addView(background);
112
+        }
113
+    }
114
+
101 115
     public void setTopTabFontFamily(int tabIndex, Typeface fontFamily) {
102 116
         topTabs.setFontFamily(tabIndex, fontFamily);
103 117
     }

+ 23
- 0
lib/android/app/src/main/java/com/reactnativenavigation/views/topbar/TopBarBackgroundView.java Ver arquivo

@@ -0,0 +1,23 @@
1
+package com.reactnativenavigation.views.topbar;
2
+
3
+import android.annotation.SuppressLint;
4
+import android.content.Context;
5
+
6
+import com.facebook.react.ReactInstanceManager;
7
+import com.reactnativenavigation.react.ReactView;
8
+
9
+@SuppressLint("ViewConstructor")
10
+public class TopBarBackgroundView extends ReactView {
11
+
12
+    public TopBarBackgroundView(Context context, ReactInstanceManager reactInstanceManager, String componentId, String componentName) {
13
+        super(context, reactInstanceManager, componentId, componentName);
14
+    }
15
+
16
+    @Override
17
+    protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
18
+        super.onMeasure(
19
+                getChildCount() > 0 ? MeasureSpec.makeMeasureSpec(getChildAt(0).getWidth(), MeasureSpec.EXACTLY) : widthMeasureSpec,
20
+                heightMeasureSpec
21
+        );
22
+    }
23
+}

+ 20
- 0
lib/android/app/src/main/java/com/reactnativenavigation/views/topbar/TopBarBackgroundViewCreator.java Ver arquivo

@@ -0,0 +1,20 @@
1
+package com.reactnativenavigation.views.topbar;
2
+
3
+import android.app.Activity;
4
+
5
+import com.facebook.react.ReactInstanceManager;
6
+import com.reactnativenavigation.viewcontrollers.ReactViewCreator;
7
+
8
+public class TopBarBackgroundViewCreator implements ReactViewCreator {
9
+
10
+    protected ReactInstanceManager instanceManager;
11
+
12
+    public TopBarBackgroundViewCreator(ReactInstanceManager instanceManager) {
13
+        this.instanceManager = instanceManager;
14
+	}
15
+
16
+	@Override
17
+	public TopBarBackgroundView create(Activity activity, String componentId, String componentName) {
18
+        return new TopBarBackgroundView(activity, instanceManager, componentId, componentName);
19
+    }
20
+}

+ 1
- 0
lib/android/app/src/main/res/values/ids.xml Ver arquivo

@@ -2,4 +2,5 @@
2 2
 <resources>
3 3
     <item name="react_root_view" type="id"/>
4 4
     <item name="fragment_screen_content" type="id"/>
5
+    <item name="topBarBackgroundComponent" type="id"/>
5 6
 </resources>

+ 20
- 0
lib/android/app/src/test/java/com/reactnativenavigation/mocks/TopBarBackgroundViewCreatorMock.java Ver arquivo

@@ -0,0 +1,20 @@
1
+package com.reactnativenavigation.mocks;
2
+
3
+import android.app.Activity;
4
+
5
+import com.facebook.react.ReactInstanceManager;
6
+import com.reactnativenavigation.views.topbar.TopBarBackgroundView;
7
+import com.reactnativenavigation.views.topbar.TopBarBackgroundViewCreator;
8
+
9
+import static org.mockito.Mockito.mock;
10
+
11
+public class TopBarBackgroundViewCreatorMock extends TopBarBackgroundViewCreator {
12
+    public TopBarBackgroundViewCreatorMock() {
13
+        super(mock(ReactInstanceManager.class));
14
+    }
15
+
16
+    @Override
17
+    public TopBarBackgroundView create(Activity activity, String componentId, String componentName) {
18
+        return new TopBarBackgroundView(activity, instanceManager, componentId, componentName);
19
+    }
20
+}

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

@@ -9,6 +9,7 @@ import com.reactnativenavigation.mocks.ImageLoaderMock;
9 9
 import com.reactnativenavigation.mocks.MockPromise;
10 10
 import com.reactnativenavigation.mocks.SimpleViewController;
11 11
 import com.reactnativenavigation.mocks.TitleBarReactViewCreatorMock;
12
+import com.reactnativenavigation.mocks.TopBarBackgroundViewCreatorMock;
12 13
 import com.reactnativenavigation.mocks.TopBarButtonCreatorMock;
13 14
 import com.reactnativenavigation.parse.Options;
14 15
 import com.reactnativenavigation.parse.params.Color;
@@ -172,6 +173,6 @@ public class BottomTabsControllerTest extends BaseTest {
172 173
     }
173 174
 
174 175
     private StackController createStack(String id) {
175
-        return new StackController(activity, new TopBarButtonCreatorMock(), new TitleBarReactViewCreatorMock(), id, tabOptions);
176
+        return new StackController(activity, new TopBarButtonCreatorMock(), new TitleBarReactViewCreatorMock(), new TopBarBackgroundViewCreatorMock(), id, tabOptions);
176 177
     }
177 178
 }

+ 2
- 1
lib/android/app/src/test/java/com/reactnativenavigation/viewcontrollers/ComponentViewControllerTest.java Ver arquivo

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

+ 2
- 1
lib/android/app/src/test/java/com/reactnativenavigation/viewcontrollers/FloatingActionButtonTest.java Ver arquivo

@@ -9,6 +9,7 @@ import com.reactnativenavigation.BaseTest;
9 9
 import com.reactnativenavigation.mocks.MockPromise;
10 10
 import com.reactnativenavigation.mocks.SimpleViewController;
11 11
 import com.reactnativenavigation.mocks.TitleBarReactViewCreatorMock;
12
+import com.reactnativenavigation.mocks.TopBarBackgroundViewCreatorMock;
12 13
 import com.reactnativenavigation.mocks.TopBarButtonCreatorMock;
13 14
 import com.reactnativenavigation.parse.FabOptions;
14 15
 import com.reactnativenavigation.parse.Options;
@@ -34,7 +35,7 @@ public class FloatingActionButtonTest extends BaseTest {
34 35
     public void beforeEach() {
35 36
         super.beforeEach();
36 37
         activity = newActivity();
37
-        stackController = new StackController(activity, new TopBarButtonCreatorMock(), new TitleBarReactViewCreatorMock(), "stackController", new Options());
38
+        stackController = new StackController(activity, new TopBarButtonCreatorMock(), new TitleBarReactViewCreatorMock(), new TopBarBackgroundViewCreatorMock(),"stackController", new Options());
38 39
         Options options = getOptionsWithFab();
39 40
         childFab = new SimpleViewController(activity, "child1", options);
40 41
         childNoFab = new SimpleViewController(activity, "child2", new Options());

+ 2
- 1
lib/android/app/src/test/java/com/reactnativenavigation/viewcontrollers/NavigatorTest.java Ver arquivo

@@ -9,6 +9,7 @@ import com.reactnativenavigation.mocks.MockPromise;
9 9
 import com.reactnativenavigation.mocks.SimpleComponentViewController;
10 10
 import com.reactnativenavigation.mocks.SimpleViewController;
11 11
 import com.reactnativenavigation.mocks.TitleBarReactViewCreatorMock;
12
+import com.reactnativenavigation.mocks.TopBarBackgroundViewCreatorMock;
12 13
 import com.reactnativenavigation.mocks.TopBarButtonCreatorMock;
13 14
 import com.reactnativenavigation.parse.Options;
14 15
 import com.reactnativenavigation.parse.params.Text;
@@ -249,7 +250,7 @@ public class NavigatorTest extends BaseTest {
249 250
 
250 251
     @NonNull
251 252
     private StackController newStack() {
252
-        return new StackController(activity, new TopBarButtonCreatorMock(), new TitleBarReactViewCreatorMock(), "stack" + CompatUtils.generateViewId(), tabOptions);
253
+        return new StackController(activity, new TopBarButtonCreatorMock(), new TitleBarReactViewCreatorMock(), new TopBarBackgroundViewCreatorMock(), "stack" + CompatUtils.generateViewId(), tabOptions);
253 254
     }
254 255
 
255 256
     @Test

+ 3
- 2
lib/android/app/src/test/java/com/reactnativenavigation/viewcontrollers/OptionsApplyingTest.java Ver arquivo

@@ -11,6 +11,7 @@ import com.reactnativenavigation.mocks.MockPromise;
11 11
 import com.reactnativenavigation.mocks.TestComponentLayout;
12 12
 import com.reactnativenavigation.mocks.TestReactView;
13 13
 import com.reactnativenavigation.mocks.TitleBarReactViewCreatorMock;
14
+import com.reactnativenavigation.mocks.TopBarBackgroundViewCreatorMock;
14 15
 import com.reactnativenavigation.mocks.TopBarButtonCreatorMock;
15 16
 import com.reactnativenavigation.parse.Options;
16 17
 import com.reactnativenavigation.parse.params.Bool;
@@ -46,7 +47,7 @@ public class OptionsApplyingTest extends BaseTest {
46 47
                 (activity1, componentId, componentName) -> view,
47 48
                 initialNavigationOptions
48 49
         );
49
-        stackController = new StackController(activity, new TopBarButtonCreatorMock(), new TitleBarReactViewCreatorMock(), "stack", new Options());
50
+        stackController = new StackController(activity, new TopBarButtonCreatorMock(), new TitleBarReactViewCreatorMock(), new TopBarBackgroundViewCreatorMock(), "stack", new Options());
50 51
         stackController.ensureViewIsCreated();
51 52
         uut.setParentController(stackController);
52 53
     }
@@ -63,7 +64,7 @@ public class OptionsApplyingTest extends BaseTest {
63 64
     @Test
64 65
     public void initialOptionsAppliedOnAppear() throws Exception {
65 66
         uut.options.topBarOptions.title.text = new Text("the title");
66
-        StackController stackController = new StackController(activity, new TopBarButtonCreatorMock(), new TitleBarReactViewCreatorMock(), "stackId", new Options());
67
+        StackController stackController = new StackController(activity, new TopBarButtonCreatorMock(), new TitleBarReactViewCreatorMock(), new TopBarBackgroundViewCreatorMock(), "stackId", new Options());
67 68
         stackController.animatePush(uut, new MockPromise() {});
68 69
         assertThat(stackController.getTopBar().getTitle()).isEmpty();
69 70
 

+ 2
- 1
lib/android/app/src/test/java/com/reactnativenavigation/viewcontrollers/ParentControllerTest.java Ver arquivo

@@ -9,6 +9,7 @@ import com.reactnativenavigation.BaseTest;
9 9
 import com.reactnativenavigation.mocks.MockPromise;
10 10
 import com.reactnativenavigation.mocks.SimpleViewController;
11 11
 import com.reactnativenavigation.mocks.TitleBarReactViewCreatorMock;
12
+import com.reactnativenavigation.mocks.TopBarBackgroundViewCreatorMock;
12 13
 import com.reactnativenavigation.mocks.TopBarButtonCreatorMock;
13 14
 import com.reactnativenavigation.parse.Options;
14 15
 import com.reactnativenavigation.parse.params.Text;
@@ -152,6 +153,6 @@ public class ParentControllerTest extends BaseTest {
152 153
     }
153 154
 
154 155
     private StackController createStack() {
155
-        return new StackController(activity, new TopBarButtonCreatorMock(), new TitleBarReactViewCreatorMock(), "stack", new Options());
156
+        return new StackController(activity, new TopBarButtonCreatorMock(), new TitleBarReactViewCreatorMock(), new TopBarBackgroundViewCreatorMock(),"stack", new Options());
156 157
     }
157 158
 }

+ 11
- 6
lib/android/app/src/test/java/com/reactnativenavigation/viewcontrollers/StackControllerTest.java Ver arquivo

@@ -9,6 +9,7 @@ import com.reactnativenavigation.anim.NavigationAnimator;
9 9
 import com.reactnativenavigation.mocks.MockPromise;
10 10
 import com.reactnativenavigation.mocks.SimpleViewController;
11 11
 import com.reactnativenavigation.mocks.TitleBarReactViewCreatorMock;
12
+import com.reactnativenavigation.mocks.TopBarBackgroundViewCreatorMock;
12 13
 import com.reactnativenavigation.mocks.TopBarButtonCreatorMock;
13 14
 import com.reactnativenavigation.parse.NestedAnimationsOptions;
14 15
 import com.reactnativenavigation.parse.Options;
@@ -47,7 +48,7 @@ public class StackControllerTest extends BaseTest {
47 48
     public void beforeEach() {
48 49
         super.beforeEach();
49 50
         activity = newActivity();
50
-        uut = createStackController("uut");
51
+        uut = createStackController();
51 52
         child1 = spy(new SimpleViewController(activity, "child1", new Options()));
52 53
         child2 = spy(new SimpleViewController(activity, "child2", new Options()));
53 54
         child3 = spy(new SimpleViewController(activity, "child3", new Options()));
@@ -103,7 +104,7 @@ public class StackControllerTest extends BaseTest {
103 104
     @Test
104 105
     public void pop_layoutHandlesChildWillDisappear() throws Exception {
105 106
         final StackLayout[] stackLayout = new StackLayout[1];
106
-        uut = new StackController(activity, new TopBarButtonCreatorMock(), new TitleBarReactViewCreatorMock(), "uut", new Options()) {
107
+        uut = new StackController(activity, new TopBarButtonCreatorMock(), new TitleBarReactViewCreatorMock(), new TopBarBackgroundViewCreatorMock(), "uut", new Options()) {
107 108
             @NonNull
108 109
             @Override
109 110
             protected StackLayout createView() {
@@ -323,7 +324,7 @@ public class StackControllerTest extends BaseTest {
323 324
 
324 325
     @Test
325 326
     public void findControllerById_Deeply() throws Exception {
326
-        StackController stack = createStackController("stack2");
327
+        StackController stack = createStackController("another");
327 328
         stack.animatePush(child2, new MockPromise());
328 329
         uut.animatePush(stack, new MockPromise());
329 330
         assertThat(uut.findControllerById(child2.getId())).isEqualTo(child2);
@@ -463,7 +464,7 @@ public class StackControllerTest extends BaseTest {
463 464
     @Test
464 465
     public void mergeChildOptions_updatesViewWithNewOptions() throws Exception {
465 466
         final StackLayout[] stackLayout = new StackLayout[1];
466
-        StackController uut = new StackController(activity, new TopBarButtonCreatorMock(), new TitleBarReactViewCreatorMock(), "stack", new Options()) {
467
+        StackController uut = new StackController(activity, new TopBarButtonCreatorMock(), new TitleBarReactViewCreatorMock(), new TopBarBackgroundViewCreatorMock(), "stack", new Options()) {
467 468
             @NonNull
468 469
             @Override
469 470
             protected StackLayout createView() {
@@ -480,7 +481,7 @@ public class StackControllerTest extends BaseTest {
480 481
     @Test
481 482
     public void mergeChildOptions_updatesParentControllerWithNewOptions() throws Exception {
482 483
         final StackLayout[] stackLayout = new StackLayout[1];
483
-        StackController uut = new StackController(activity, new TopBarButtonCreatorMock(), new TitleBarReactViewCreatorMock(), "stack", new Options()) {
484
+        StackController uut = new StackController(activity, new TopBarButtonCreatorMock(), new TitleBarReactViewCreatorMock(), new TopBarBackgroundViewCreatorMock(), "stack", new Options()) {
484 485
             @NonNull
485 486
             @Override
486 487
             protected StackLayout createView() {
@@ -536,8 +537,12 @@ public class StackControllerTest extends BaseTest {
536 537
         assertThat(uut.getChildControllers()).extracting((Extractor<ViewController, String>) ViewController::getId).containsOnly(ids);
537 538
     }
538 539
 
540
+    private StackController createStackController() {
541
+        return createStackController("stackId");
542
+    }
543
+
539 544
     private StackController createStackController(String id) {
540
-        return new StackController(activity, new TopBarButtonCreatorMock(), new TitleBarReactViewCreatorMock(), id, new Options()) {
545
+        return new StackController(activity, new TopBarButtonCreatorMock(), new TitleBarReactViewCreatorMock(), new TopBarBackgroundViewCreatorMock(), id, new Options()) {
541 546
             @Override
542 547
             NavigationAnimator createAnimator() {
543 548
                 animator = Mockito.mock(NavigationAnimator.class);

+ 2
- 1
lib/android/app/src/test/java/com/reactnativenavigation/viewcontrollers/TopBarButtonControllerTest.java Ver arquivo

@@ -5,6 +5,7 @@ import android.support.annotation.NonNull;
5 5
 
6 6
 import com.reactnativenavigation.BaseTest;
7 7
 import com.reactnativenavigation.mocks.TitleBarReactViewCreatorMock;
8
+import com.reactnativenavigation.mocks.TopBarBackgroundViewCreatorMock;
8 9
 import com.reactnativenavigation.mocks.TopBarButtonCreatorMock;
9 10
 import com.reactnativenavigation.parse.Options;
10 11
 import com.reactnativenavigation.parse.params.Button;
@@ -29,7 +30,7 @@ public class TopBarButtonControllerTest extends BaseTest {
29 30
 
30 31
         TopBarButtonCreatorMock buttonCreatorMock = new TopBarButtonCreatorMock();
31 32
         uut = spy(new TopBarButtonController(activity, button, buttonCreatorMock, (buttonId) -> {}));
32
-        stackController = spy(new StackController(activity, buttonCreatorMock, new TitleBarReactViewCreatorMock(), "stack", new Options()));
33
+        stackController = spy(new StackController(activity, buttonCreatorMock, new TitleBarReactViewCreatorMock(), new TopBarBackgroundViewCreatorMock(), "stack", new Options()));
33 34
 
34 35
     }
35 36
 

+ 2
- 1
lib/android/app/src/test/java/com/reactnativenavigation/viewcontrollers/TopTabsViewControllerTest.java Ver arquivo

@@ -9,6 +9,7 @@ import com.reactnativenavigation.mocks.MockPromise;
9 9
 import com.reactnativenavigation.mocks.TestComponentViewCreator;
10 10
 import com.reactnativenavigation.mocks.TestReactView;
11 11
 import com.reactnativenavigation.mocks.TitleBarReactViewCreatorMock;
12
+import com.reactnativenavigation.mocks.TopBarBackgroundViewCreatorMock;
12 13
 import com.reactnativenavigation.mocks.TopBarButtonCreatorMock;
13 14
 import com.reactnativenavigation.parse.Options;
14 15
 import com.reactnativenavigation.parse.params.Text;
@@ -68,7 +69,7 @@ public class TopTabsViewControllerTest extends BaseTest {
68 69
 
69 70
     @NonNull
70 71
     private StackController createStackController(String id) {
71
-        return new StackController(activity, new TopBarButtonCreatorMock(), new TitleBarReactViewCreatorMock(), id, new Options());
72
+        return new StackController(activity, new TopBarButtonCreatorMock(), new TitleBarReactViewCreatorMock(), new TopBarBackgroundViewCreatorMock(), id, new Options());
72 73
     }
73 74
 
74 75
     @NonNull

+ 2
- 1
lib/android/app/src/test/java/com/reactnativenavigation/viewcontrollers/ViewControllerTest.java Ver arquivo

@@ -10,6 +10,7 @@ import com.reactnativenavigation.BaseTest;
10 10
 import com.reactnativenavigation.mocks.MockPromise;
11 11
 import com.reactnativenavigation.mocks.SimpleViewController;
12 12
 import com.reactnativenavigation.mocks.TitleBarReactViewCreatorMock;
13
+import com.reactnativenavigation.mocks.TopBarBackgroundViewCreatorMock;
13 14
 import com.reactnativenavigation.mocks.TopBarButtonCreatorMock;
14 15
 import com.reactnativenavigation.parse.Options;
15 16
 
@@ -67,7 +68,7 @@ public class ViewControllerTest extends BaseTest {
67 68
     @Test
68 69
     public void holdsAReferenceToStackControllerOrNull() throws Exception {
69 70
         assertThat(uut.getParentController()).isNull();
70
-        StackController nav = new StackController(activity, new TopBarButtonCreatorMock(), new TitleBarReactViewCreatorMock(), "stack", new Options());
71
+        StackController nav = new StackController(activity, new TopBarButtonCreatorMock(), new TitleBarReactViewCreatorMock(), new TopBarBackgroundViewCreatorMock(), "stack", new Options());
71 72
         nav.animatePush(uut, new MockPromise());
72 73
         assertThat(uut.getParentController()).isEqualTo(nav);
73 74
     }

+ 51
- 0
lib/android/app/src/test/java/com/reactnativenavigation/views/TopBarBackgroundComponentTest.java Ver arquivo

@@ -0,0 +1,51 @@
1
+package com.reactnativenavigation.views;
2
+
3
+import android.util.Log;
4
+
5
+import com.reactnativenavigation.BaseTest;
6
+import com.reactnativenavigation.R;
7
+import com.reactnativenavigation.mocks.TitleBarReactViewCreatorMock;
8
+import com.reactnativenavigation.mocks.TopBarBackgroundViewCreatorMock;
9
+import com.reactnativenavigation.mocks.TopBarButtonCreatorMock;
10
+import com.reactnativenavigation.parse.TopBarBackgroundOptions;
11
+import com.reactnativenavigation.parse.params.Text;
12
+import com.reactnativenavigation.react.ReactView;
13
+import com.reactnativenavigation.viewcontrollers.TopBarButtonController;
14
+
15
+import org.junit.Test;
16
+
17
+import static org.assertj.core.api.Java6Assertions.assertThat;
18
+import static org.mockito.Mockito.spy;
19
+
20
+public class TopBarBackgroundComponentTest extends BaseTest {
21
+    private TopBar uut;
22
+
23
+    @SuppressWarnings("Convert2Lambda")
24
+    @Override
25
+    public void beforeEach() {
26
+        TopBarButtonController.OnClickListener onClickListener = spy(new TopBarButtonController.OnClickListener() {
27
+            @Override
28
+            public void onPress(String buttonId) {
29
+                Log.i("TopBarTest", "onPress: " + buttonId);
30
+            }
31
+        });
32
+        StackLayout parent = new StackLayout(newActivity(), new TopBarButtonCreatorMock(), new TitleBarReactViewCreatorMock(), new TopBarBackgroundViewCreatorMock(), onClickListener);
33
+        uut = new TopBar(newActivity(), new TopBarButtonCreatorMock(), new TitleBarReactViewCreatorMock(), new TopBarBackgroundViewCreatorMock(), onClickListener, parent);
34
+        parent.addView(uut);
35
+    }
36
+
37
+    @Test
38
+    public void setBackgroundComponent() throws Exception {
39
+        TopBarBackgroundOptions options = new TopBarBackgroundOptions();
40
+        options.component = new Text("someComponent");
41
+        uut.setBackgroundComponent(options);
42
+        assertThat(ReactView.class.isAssignableFrom(uut.findViewById(R.id.topBarBackgroundComponent).getClass())).isTrue();
43
+    }
44
+
45
+    @Test
46
+    public void setBackgroundComponent_doesNotSetIfNoComponentIsDefined() throws Exception {
47
+        TopBarBackgroundOptions options = new TopBarBackgroundOptions();
48
+        uut.setBackgroundComponent(options);
49
+        assertThat(uut.findViewById(R.id.topBarBackgroundComponent)).isNull();
50
+    }
51
+}

+ 4
- 2
lib/android/app/src/test/java/com/reactnativenavigation/views/TopBarTest.java Ver arquivo

@@ -6,6 +6,7 @@ import android.view.MenuItem;
6 6
 import com.reactnativenavigation.BaseTest;
7 7
 import com.reactnativenavigation.anim.TopBarAnimator;
8 8
 import com.reactnativenavigation.mocks.TitleBarReactViewCreatorMock;
9
+import com.reactnativenavigation.mocks.TopBarBackgroundViewCreatorMock;
9 10
 import com.reactnativenavigation.mocks.TopBarButtonCreatorMock;
10 11
 import com.reactnativenavigation.parse.AnimationOptions;
11 12
 import com.reactnativenavigation.parse.params.Button;
@@ -30,6 +31,7 @@ public class TopBarTest extends BaseTest {
30 31
     private ArrayList<Button> rightButtons;
31 32
     private TopBarButtonController.OnClickListener onClickListener;
32 33
 
34
+    @SuppressWarnings("Convert2Lambda")
33 35
     @Override
34 36
     public void beforeEach() {
35 37
         onClickListener = spy(new TopBarButtonController.OnClickListener() {
@@ -38,8 +40,8 @@ public class TopBarTest extends BaseTest {
38 40
                 Log.i("TopBarTest", "onPress: " + buttonId);
39 41
             }
40 42
         });
41
-        StackLayout parent = new StackLayout(newActivity(), new TopBarButtonCreatorMock(), new TitleBarReactViewCreatorMock(), this.onClickListener);
42
-        uut = new TopBar(newActivity(), new TopBarButtonCreatorMock(), new TitleBarReactViewCreatorMock(), this.onClickListener, parent);
43
+        StackLayout parent = new StackLayout(newActivity(), new TopBarButtonCreatorMock(), new TitleBarReactViewCreatorMock(), new TopBarBackgroundViewCreatorMock(), this.onClickListener);
44
+        uut = new TopBar(newActivity(), new TopBarButtonCreatorMock(), new TitleBarReactViewCreatorMock(), new TopBarBackgroundViewCreatorMock(), this.onClickListener, parent);
43 45
         animator = spy(new TopBarAnimator(uut));
44 46
         uut.setAnimator(animator);
45 47
         leftButton = createLeftButton();