Browse Source

TopBarBackgroundView impl

Guy Carmeli 6 years ago
parent
commit
15e184d020
21 changed files with 182 additions and 26 deletions
  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 View File

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

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

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

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

15
 import com.reactnativenavigation.views.StackLayout;
15
 import com.reactnativenavigation.views.StackLayout;
16
 import com.reactnativenavigation.views.TopBar;
16
 import com.reactnativenavigation.views.TopBar;
17
 import com.reactnativenavigation.views.titlebar.TitleBarReactViewCreator;
17
 import com.reactnativenavigation.views.titlebar.TitleBarReactViewCreator;
18
+import com.reactnativenavigation.views.topbar.TopBarBackgroundViewCreator;
18
 
19
 
19
 import java.util.Collection;
20
 import java.util.Collection;
20
 import java.util.Iterator;
21
 import java.util.Iterator;
28
     private final NavigationAnimator animator;
29
     private final NavigationAnimator animator;
29
     private final ReactViewCreator topBarButtonCreator;
30
     private final ReactViewCreator topBarButtonCreator;
30
     private final TitleBarReactViewCreator titleBarReactViewCreator;
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
         super(activity, id, initialOptions);
35
         super(activity, id, initialOptions);
34
         animator = createAnimator();
36
         animator = createAnimator();
35
         this.topBarButtonCreator = topBarButtonCreator;
37
         this.topBarButtonCreator = topBarButtonCreator;
36
         this.titleBarReactViewCreator = titleBarReactViewCreator;
38
         this.titleBarReactViewCreator = titleBarReactViewCreator;
39
+        this.topBarBackgroundViewCreator = topBarBackgroundViewCreator;
37
     }
40
     }
38
 
41
 
39
     public void applyOptions(Options options) {
42
     public void applyOptions(Options options) {
226
     @NonNull
229
     @NonNull
227
     @Override
230
     @Override
228
     protected StackLayout createView() {
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
     @NonNull
235
     @NonNull

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

13
 import com.reactnativenavigation.viewcontrollers.ReactViewCreator;
13
 import com.reactnativenavigation.viewcontrollers.ReactViewCreator;
14
 import com.reactnativenavigation.viewcontrollers.TopBarButtonController;
14
 import com.reactnativenavigation.viewcontrollers.TopBarButtonController;
15
 import com.reactnativenavigation.views.titlebar.TitleBarReactViewCreator;
15
 import com.reactnativenavigation.views.titlebar.TitleBarReactViewCreator;
16
+import com.reactnativenavigation.views.topbar.TopBarBackgroundViewCreator;
16
 
17
 
17
 import static android.view.ViewGroup.LayoutParams.MATCH_PARENT;
18
 import static android.view.ViewGroup.LayoutParams.MATCH_PARENT;
18
 import static android.view.ViewGroup.LayoutParams.WRAP_CONTENT;
19
 import static android.view.ViewGroup.LayoutParams.WRAP_CONTENT;
22
     private TopBar topBar;
23
     private TopBar topBar;
23
     private final OptionsPresenter optionsPresenter;
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
         super(context);
27
         super(context);
27
-        createLayout(topBarButtonCreator, titleBarReactViewCreator, topBarButtonClickListener);
28
+        createLayout(topBarButtonCreator, titleBarReactViewCreator, topBarBackgroundViewCreator, topBarButtonClickListener);
28
         optionsPresenter = new OptionsPresenter(topBar);
29
         optionsPresenter = new OptionsPresenter(topBar);
29
         setContentDescription("StackLayout");
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
         topBar.setId(CompatUtils.generateViewId());
35
         topBar.setId(CompatUtils.generateViewId());
35
         addView(topBar, MATCH_PARENT, WRAP_CONTENT);
36
         addView(topBar, MATCH_PARENT, WRAP_CONTENT);
36
     }
37
     }

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

13
 import android.widget.RelativeLayout;
13
 import android.widget.RelativeLayout;
14
 import android.widget.TextView;
14
 import android.widget.TextView;
15
 
15
 
16
+import com.reactnativenavigation.R;
16
 import com.reactnativenavigation.anim.AnimationListener;
17
 import com.reactnativenavigation.anim.AnimationListener;
17
 import com.reactnativenavigation.anim.TopBarAnimator;
18
 import com.reactnativenavigation.anim.TopBarAnimator;
18
 import com.reactnativenavigation.anim.TopBarCollapseBehavior;
19
 import com.reactnativenavigation.anim.TopBarCollapseBehavior;
19
 import com.reactnativenavigation.interfaces.ScrollEventListener;
20
 import com.reactnativenavigation.interfaces.ScrollEventListener;
20
 import com.reactnativenavigation.parse.AnimationOptions;
21
 import com.reactnativenavigation.parse.AnimationOptions;
21
 import com.reactnativenavigation.parse.TitleOptions;
22
 import com.reactnativenavigation.parse.TitleOptions;
23
+import com.reactnativenavigation.parse.TopBarBackgroundOptions;
22
 import com.reactnativenavigation.parse.params.Button;
24
 import com.reactnativenavigation.parse.params.Button;
23
 import com.reactnativenavigation.parse.params.Color;
25
 import com.reactnativenavigation.parse.params.Color;
24
 import com.reactnativenavigation.parse.params.Fraction;
26
 import com.reactnativenavigation.parse.params.Fraction;
29
 import com.reactnativenavigation.viewcontrollers.TopBarButtonController;
31
 import com.reactnativenavigation.viewcontrollers.TopBarButtonController;
30
 import com.reactnativenavigation.views.titlebar.TitleBar;
32
 import com.reactnativenavigation.views.titlebar.TitleBar;
31
 import com.reactnativenavigation.views.titlebar.TitleBarReactViewCreator;
33
 import com.reactnativenavigation.views.titlebar.TitleBarReactViewCreator;
34
+import com.reactnativenavigation.views.topbar.TopBarBackgroundView;
35
+import com.reactnativenavigation.views.topbar.TopBarBackgroundViewCreator;
32
 
36
 
33
 import java.util.List;
37
 import java.util.List;
34
 
38
 
43
     private TopTabs topTabs;
47
     private TopTabs topTabs;
44
     private RelativeLayout root;
48
     private RelativeLayout root;
45
     private StackLayout parentView;
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
         super(context);
53
         super(context);
49
         collapsingBehavior = new TopBarCollapseBehavior(this);
54
         collapsingBehavior = new TopBarCollapseBehavior(this);
50
-        animator = new TopBarAnimator(this);
55
+        this.topBarBackgroundViewCreator = topBarBackgroundViewCreator;
51
         this.parentView = parentView;
56
         this.parentView = parentView;
57
+        animator = new TopBarAnimator(this);
52
         createLayout(buttonCreator, titleBarReactViewCreator, onClickListener);
58
         createLayout(buttonCreator, titleBarReactViewCreator, onClickListener);
53
     }
59
     }
54
 
60
 
98
         titleBar.setComponent(componentName, alignment);
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
     public void setTopTabFontFamily(int tabIndex, Typeface fontFamily) {
115
     public void setTopTabFontFamily(int tabIndex, Typeface fontFamily) {
102
         topTabs.setFontFamily(tabIndex, fontFamily);
116
         topTabs.setFontFamily(tabIndex, fontFamily);
103
     }
117
     }

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

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 View File

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 View File

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

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

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 View File

9
 import com.reactnativenavigation.mocks.MockPromise;
9
 import com.reactnativenavigation.mocks.MockPromise;
10
 import com.reactnativenavigation.mocks.SimpleViewController;
10
 import com.reactnativenavigation.mocks.SimpleViewController;
11
 import com.reactnativenavigation.mocks.TitleBarReactViewCreatorMock;
11
 import com.reactnativenavigation.mocks.TitleBarReactViewCreatorMock;
12
+import com.reactnativenavigation.mocks.TopBarBackgroundViewCreatorMock;
12
 import com.reactnativenavigation.mocks.TopBarButtonCreatorMock;
13
 import com.reactnativenavigation.mocks.TopBarButtonCreatorMock;
13
 import com.reactnativenavigation.parse.Options;
14
 import com.reactnativenavigation.parse.Options;
14
 import com.reactnativenavigation.parse.params.Color;
15
 import com.reactnativenavigation.parse.params.Color;
172
     }
173
     }
173
 
174
 
174
     private StackController createStack(String id) {
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 View File

6
 import com.reactnativenavigation.mocks.TestComponentLayout;
6
 import com.reactnativenavigation.mocks.TestComponentLayout;
7
 import com.reactnativenavigation.mocks.TestReactView;
7
 import com.reactnativenavigation.mocks.TestReactView;
8
 import com.reactnativenavigation.mocks.TitleBarReactViewCreatorMock;
8
 import com.reactnativenavigation.mocks.TitleBarReactViewCreatorMock;
9
+import com.reactnativenavigation.mocks.TopBarBackgroundViewCreatorMock;
9
 import com.reactnativenavigation.mocks.TopBarButtonCreatorMock;
10
 import com.reactnativenavigation.mocks.TopBarButtonCreatorMock;
10
 import com.reactnativenavigation.parse.Options;
11
 import com.reactnativenavigation.parse.Options;
11
 import com.reactnativenavigation.views.StackLayout;
12
 import com.reactnativenavigation.views.StackLayout;
27
         super.beforeEach();
28
         super.beforeEach();
28
         Activity activity = newActivity();
29
         Activity activity = newActivity();
29
         view = spy(new TestComponentLayout(activity, new TestReactView(activity)));
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
         uut = new ComponentViewController(activity, "componentId1", "componentName", (activity1, componentId, componentName) -> view, new Options());
32
         uut = new ComponentViewController(activity, "componentId1", "componentName", (activity1, componentId, componentName) -> view, new Options());
32
         uut.setParentController(parentController);
33
         uut.setParentController(parentController);
33
         parentController.ensureViewIsCreated();
34
         parentController.ensureViewIsCreated();

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

9
 import com.reactnativenavigation.mocks.MockPromise;
9
 import com.reactnativenavigation.mocks.MockPromise;
10
 import com.reactnativenavigation.mocks.SimpleViewController;
10
 import com.reactnativenavigation.mocks.SimpleViewController;
11
 import com.reactnativenavigation.mocks.TitleBarReactViewCreatorMock;
11
 import com.reactnativenavigation.mocks.TitleBarReactViewCreatorMock;
12
+import com.reactnativenavigation.mocks.TopBarBackgroundViewCreatorMock;
12
 import com.reactnativenavigation.mocks.TopBarButtonCreatorMock;
13
 import com.reactnativenavigation.mocks.TopBarButtonCreatorMock;
13
 import com.reactnativenavigation.parse.FabOptions;
14
 import com.reactnativenavigation.parse.FabOptions;
14
 import com.reactnativenavigation.parse.Options;
15
 import com.reactnativenavigation.parse.Options;
34
     public void beforeEach() {
35
     public void beforeEach() {
35
         super.beforeEach();
36
         super.beforeEach();
36
         activity = newActivity();
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
         Options options = getOptionsWithFab();
39
         Options options = getOptionsWithFab();
39
         childFab = new SimpleViewController(activity, "child1", options);
40
         childFab = new SimpleViewController(activity, "child1", options);
40
         childNoFab = new SimpleViewController(activity, "child2", new Options());
41
         childNoFab = new SimpleViewController(activity, "child2", new Options());

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

9
 import com.reactnativenavigation.mocks.SimpleComponentViewController;
9
 import com.reactnativenavigation.mocks.SimpleComponentViewController;
10
 import com.reactnativenavigation.mocks.SimpleViewController;
10
 import com.reactnativenavigation.mocks.SimpleViewController;
11
 import com.reactnativenavigation.mocks.TitleBarReactViewCreatorMock;
11
 import com.reactnativenavigation.mocks.TitleBarReactViewCreatorMock;
12
+import com.reactnativenavigation.mocks.TopBarBackgroundViewCreatorMock;
12
 import com.reactnativenavigation.mocks.TopBarButtonCreatorMock;
13
 import com.reactnativenavigation.mocks.TopBarButtonCreatorMock;
13
 import com.reactnativenavigation.parse.Options;
14
 import com.reactnativenavigation.parse.Options;
14
 import com.reactnativenavigation.parse.params.Text;
15
 import com.reactnativenavigation.parse.params.Text;
249
 
250
 
250
     @NonNull
251
     @NonNull
251
     private StackController newStack() {
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
     @Test
256
     @Test

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

11
 import com.reactnativenavigation.mocks.TestComponentLayout;
11
 import com.reactnativenavigation.mocks.TestComponentLayout;
12
 import com.reactnativenavigation.mocks.TestReactView;
12
 import com.reactnativenavigation.mocks.TestReactView;
13
 import com.reactnativenavigation.mocks.TitleBarReactViewCreatorMock;
13
 import com.reactnativenavigation.mocks.TitleBarReactViewCreatorMock;
14
+import com.reactnativenavigation.mocks.TopBarBackgroundViewCreatorMock;
14
 import com.reactnativenavigation.mocks.TopBarButtonCreatorMock;
15
 import com.reactnativenavigation.mocks.TopBarButtonCreatorMock;
15
 import com.reactnativenavigation.parse.Options;
16
 import com.reactnativenavigation.parse.Options;
16
 import com.reactnativenavigation.parse.params.Bool;
17
 import com.reactnativenavigation.parse.params.Bool;
46
                 (activity1, componentId, componentName) -> view,
47
                 (activity1, componentId, componentName) -> view,
47
                 initialNavigationOptions
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
         stackController.ensureViewIsCreated();
51
         stackController.ensureViewIsCreated();
51
         uut.setParentController(stackController);
52
         uut.setParentController(stackController);
52
     }
53
     }
63
     @Test
64
     @Test
64
     public void initialOptionsAppliedOnAppear() throws Exception {
65
     public void initialOptionsAppliedOnAppear() throws Exception {
65
         uut.options.topBarOptions.title.text = new Text("the title");
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
         stackController.animatePush(uut, new MockPromise() {});
68
         stackController.animatePush(uut, new MockPromise() {});
68
         assertThat(stackController.getTopBar().getTitle()).isEmpty();
69
         assertThat(stackController.getTopBar().getTitle()).isEmpty();
69
 
70
 

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

9
 import com.reactnativenavigation.mocks.MockPromise;
9
 import com.reactnativenavigation.mocks.MockPromise;
10
 import com.reactnativenavigation.mocks.SimpleViewController;
10
 import com.reactnativenavigation.mocks.SimpleViewController;
11
 import com.reactnativenavigation.mocks.TitleBarReactViewCreatorMock;
11
 import com.reactnativenavigation.mocks.TitleBarReactViewCreatorMock;
12
+import com.reactnativenavigation.mocks.TopBarBackgroundViewCreatorMock;
12
 import com.reactnativenavigation.mocks.TopBarButtonCreatorMock;
13
 import com.reactnativenavigation.mocks.TopBarButtonCreatorMock;
13
 import com.reactnativenavigation.parse.Options;
14
 import com.reactnativenavigation.parse.Options;
14
 import com.reactnativenavigation.parse.params.Text;
15
 import com.reactnativenavigation.parse.params.Text;
152
     }
153
     }
153
 
154
 
154
     private StackController createStack() {
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 View File

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

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

5
 
5
 
6
 import com.reactnativenavigation.BaseTest;
6
 import com.reactnativenavigation.BaseTest;
7
 import com.reactnativenavigation.mocks.TitleBarReactViewCreatorMock;
7
 import com.reactnativenavigation.mocks.TitleBarReactViewCreatorMock;
8
+import com.reactnativenavigation.mocks.TopBarBackgroundViewCreatorMock;
8
 import com.reactnativenavigation.mocks.TopBarButtonCreatorMock;
9
 import com.reactnativenavigation.mocks.TopBarButtonCreatorMock;
9
 import com.reactnativenavigation.parse.Options;
10
 import com.reactnativenavigation.parse.Options;
10
 import com.reactnativenavigation.parse.params.Button;
11
 import com.reactnativenavigation.parse.params.Button;
29
 
30
 
30
         TopBarButtonCreatorMock buttonCreatorMock = new TopBarButtonCreatorMock();
31
         TopBarButtonCreatorMock buttonCreatorMock = new TopBarButtonCreatorMock();
31
         uut = spy(new TopBarButtonController(activity, button, buttonCreatorMock, (buttonId) -> {}));
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 View File

9
 import com.reactnativenavigation.mocks.TestComponentViewCreator;
9
 import com.reactnativenavigation.mocks.TestComponentViewCreator;
10
 import com.reactnativenavigation.mocks.TestReactView;
10
 import com.reactnativenavigation.mocks.TestReactView;
11
 import com.reactnativenavigation.mocks.TitleBarReactViewCreatorMock;
11
 import com.reactnativenavigation.mocks.TitleBarReactViewCreatorMock;
12
+import com.reactnativenavigation.mocks.TopBarBackgroundViewCreatorMock;
12
 import com.reactnativenavigation.mocks.TopBarButtonCreatorMock;
13
 import com.reactnativenavigation.mocks.TopBarButtonCreatorMock;
13
 import com.reactnativenavigation.parse.Options;
14
 import com.reactnativenavigation.parse.Options;
14
 import com.reactnativenavigation.parse.params.Text;
15
 import com.reactnativenavigation.parse.params.Text;
68
 
69
 
69
     @NonNull
70
     @NonNull
70
     private StackController createStackController(String id) {
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
     @NonNull
75
     @NonNull

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

10
 import com.reactnativenavigation.mocks.MockPromise;
10
 import com.reactnativenavigation.mocks.MockPromise;
11
 import com.reactnativenavigation.mocks.SimpleViewController;
11
 import com.reactnativenavigation.mocks.SimpleViewController;
12
 import com.reactnativenavigation.mocks.TitleBarReactViewCreatorMock;
12
 import com.reactnativenavigation.mocks.TitleBarReactViewCreatorMock;
13
+import com.reactnativenavigation.mocks.TopBarBackgroundViewCreatorMock;
13
 import com.reactnativenavigation.mocks.TopBarButtonCreatorMock;
14
 import com.reactnativenavigation.mocks.TopBarButtonCreatorMock;
14
 import com.reactnativenavigation.parse.Options;
15
 import com.reactnativenavigation.parse.Options;
15
 
16
 
67
     @Test
68
     @Test
68
     public void holdsAReferenceToStackControllerOrNull() throws Exception {
69
     public void holdsAReferenceToStackControllerOrNull() throws Exception {
69
         assertThat(uut.getParentController()).isNull();
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
         nav.animatePush(uut, new MockPromise());
72
         nav.animatePush(uut, new MockPromise());
72
         assertThat(uut.getParentController()).isEqualTo(nav);
73
         assertThat(uut.getParentController()).isEqualTo(nav);
73
     }
74
     }

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

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 View File

6
 import com.reactnativenavigation.BaseTest;
6
 import com.reactnativenavigation.BaseTest;
7
 import com.reactnativenavigation.anim.TopBarAnimator;
7
 import com.reactnativenavigation.anim.TopBarAnimator;
8
 import com.reactnativenavigation.mocks.TitleBarReactViewCreatorMock;
8
 import com.reactnativenavigation.mocks.TitleBarReactViewCreatorMock;
9
+import com.reactnativenavigation.mocks.TopBarBackgroundViewCreatorMock;
9
 import com.reactnativenavigation.mocks.TopBarButtonCreatorMock;
10
 import com.reactnativenavigation.mocks.TopBarButtonCreatorMock;
10
 import com.reactnativenavigation.parse.AnimationOptions;
11
 import com.reactnativenavigation.parse.AnimationOptions;
11
 import com.reactnativenavigation.parse.params.Button;
12
 import com.reactnativenavigation.parse.params.Button;
30
     private ArrayList<Button> rightButtons;
31
     private ArrayList<Button> rightButtons;
31
     private TopBarButtonController.OnClickListener onClickListener;
32
     private TopBarButtonController.OnClickListener onClickListener;
32
 
33
 
34
+    @SuppressWarnings("Convert2Lambda")
33
     @Override
35
     @Override
34
     public void beforeEach() {
36
     public void beforeEach() {
35
         onClickListener = spy(new TopBarButtonController.OnClickListener() {
37
         onClickListener = spy(new TopBarButtonController.OnClickListener() {
38
                 Log.i("TopBarTest", "onPress: " + buttonId);
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
         animator = spy(new TopBarAnimator(uut));
45
         animator = spy(new TopBarAnimator(uut));
44
         uut.setAnimator(animator);
46
         uut.setAnimator(animator);
45
         leftButton = createLeftButton();
47
         leftButton = createLeftButton();