Browse Source

Resolve tabsAttachMode from default options (#6155)

Default options were not taken into account when resolving tabsAttachMode property.

Co-authored-by: Yogev Ben David <yogev132@gmail.com>
Guy Carmeli 4 years ago
parent
commit
a4b2c76a9d
No account linked to committer's email address

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

@@ -219,7 +219,7 @@ public class LayoutFactory {
219 219
                 node.id,
220 220
                 parse(typefaceManager, node.getOptions()),
221 221
                 new Presenter(activity, defaultOptions),
222
-                new BottomTabsAttacher(tabs, bottomTabsPresenter),
222
+                new BottomTabsAttacher(tabs, bottomTabsPresenter, defaultOptions),
223 223
                 bottomTabsPresenter,
224 224
                 new BottomTabPresenter(activity, tabs, new ImageLoader(), defaultOptions));
225 225
 	}

+ 6
- 3
lib/android/app/src/main/java/com/reactnativenavigation/viewcontrollers/bottomtabs/BottomTabsAttacher.java View File

@@ -1,6 +1,5 @@
1 1
 package com.reactnativenavigation.viewcontrollers.bottomtabs;
2 2
 
3
-import androidx.annotation.VisibleForTesting;
4 3
 import android.view.ViewGroup;
5 4
 
6 5
 import com.reactnativenavigation.parse.Options;
@@ -9,19 +8,23 @@ import com.reactnativenavigation.viewcontrollers.ViewController;
9 8
 
10 9
 import java.util.List;
11 10
 
11
+import androidx.annotation.VisibleForTesting;
12
+
12 13
 public class BottomTabsAttacher {
13 14
     private final List<ViewController> tabs;
14 15
     private final BottomTabsPresenter presenter;
16
+    private Options defaultOptions;
15 17
     @VisibleForTesting
16 18
     AttachMode attachStrategy;
17 19
 
18
-    public BottomTabsAttacher(List<ViewController> tabs, BottomTabsPresenter presenter) {
20
+    public BottomTabsAttacher(List<ViewController> tabs, BottomTabsPresenter presenter, Options defaultOptions) {
19 21
         this.tabs = tabs;
20 22
         this.presenter = presenter;
23
+        this.defaultOptions = defaultOptions;
21 24
     }
22 25
 
23 26
     void init(ViewGroup parent, Options resolved) {
24
-        attachStrategy = AttachMode.get(parent, tabs, presenter, resolved);
27
+        attachStrategy = AttachMode.get(parent, tabs, presenter, resolved.withDefaultOptions(defaultOptions));
25 28
     }
26 29
 
27 30
     void attach() {

+ 19
- 3
lib/android/app/src/test/java/com/reactnativenavigation/viewcontrollers/bottomtabs/BottomTabsAttacherTest.java View File

@@ -1,14 +1,20 @@
1 1
 package com.reactnativenavigation.viewcontrollers.bottomtabs;
2 2
 
3
+import android.view.ViewGroup;
4
+
3 5
 import com.reactnativenavigation.BaseTest;
6
+import com.reactnativenavigation.parse.Options;
7
+import com.reactnativenavigation.parse.TabsAttachMode;
4 8
 import com.reactnativenavigation.presentation.BottomTabsPresenter;
5
-import com.reactnativenavigation.viewcontrollers.*;
9
+import com.reactnativenavigation.viewcontrollers.ViewController;
6 10
 
7 11
 import org.junit.Test;
8 12
 import org.mockito.Mockito;
9 13
 
10
-import java.util.Collections;
14
+import java.util.Arrays;
15
+import java.util.List;
11 16
 
17
+import static org.assertj.core.api.Java6Assertions.assertThat;
12 18
 import static org.mockito.Mockito.mock;
13 19
 import static org.mockito.Mockito.verify;
14 20
 
@@ -16,14 +22,24 @@ public class BottomTabsAttacherTest extends BaseTest {
16 22
 
17 23
     private BottomTabsAttacher uut;
18 24
     private AttachMode mode;
25
+    private Options defaultOptions = new Options();
26
+    private List<ViewController> tabs;
19 27
 
20 28
     @Override
21 29
     public void beforeEach() {
22 30
         mode = Mockito.mock(AttachMode.class);
23
-        uut = new BottomTabsAttacher(Collections.EMPTY_LIST, Mockito.mock(BottomTabsPresenter.class));
31
+        tabs = Arrays.asList(mock(ViewController.class), mock(ViewController.class));
32
+        uut = new BottomTabsAttacher(tabs, Mockito.mock(BottomTabsPresenter.class), defaultOptions);
24 33
         uut.attachStrategy = mode;
25 34
     }
26 35
 
36
+    @Test
37
+    public void init_defaultOptionsAreTakenIntoAccount() {
38
+        defaultOptions.bottomTabsOptions.tabsAttachMode = TabsAttachMode.ON_SWITCH_TO_TAB;
39
+        uut.init(Mockito.mock(ViewGroup.class), Options.EMPTY);
40
+        assertThat(uut.attachStrategy).isInstanceOfAny(OnSwitchToTab.class);
41
+    }
42
+
27 43
     @Test
28 44
     public void attach_delegatesToStrategy() {
29 45
         uut.attach();

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

@@ -251,7 +251,7 @@ public class BottomTabsControllerTest extends BaseTest {
251 251
         child4 = createStack(pushedScreen);
252 252
 
253 253
         tabs = new ArrayList<>(Collections.singletonList(child4));
254
-        tabsAttacher = new BottomTabsAttacher(tabs, presenter);
254
+        tabsAttacher = new BottomTabsAttacher(tabs, presenter, Options.EMPTY);
255 255
 
256 256
         initialOptions.bottomTabsOptions.currentTabIndex = new Number(0);
257 257
         Options resolvedOptions = new Options();
@@ -401,7 +401,7 @@ public class BottomTabsControllerTest extends BaseTest {
401 401
         tabs = createTabs();
402 402
         presenter = spy(new BottomTabsPresenter(tabs, new Options()));
403 403
         bottomTabPresenter = spy(new BottomTabPresenter(activity, tabs, ImageLoaderMock.mock(), new Options()));
404
-        tabsAttacher = spy(new BottomTabsAttacher(tabs, presenter));
404
+        tabsAttacher = spy(new BottomTabsAttacher(tabs, presenter, Options.EMPTY));
405 405
         uut = createBottomTabs();
406 406
 
407 407
         uut.setParentController(Mockito.mock(ParentController.class));

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

@@ -389,7 +389,7 @@ public class NavigatorTest extends BaseTest {
389 389
     @NonNull
390 390
     private BottomTabsController newTabs(List<ViewController> tabs) {
391 391
         BottomTabsPresenter bottomTabsPresenter = new BottomTabsPresenter(tabs, new Options());
392
-        return new BottomTabsController(activity, tabs, childRegistry, eventEmitter, imageLoaderMock, "tabsController", new Options(), new Presenter(activity, new Options()), new BottomTabsAttacher(tabs, bottomTabsPresenter), bottomTabsPresenter, new BottomTabPresenter(activity, tabs, ImageLoaderMock.mock(), new Options())) {
392
+        return new BottomTabsController(activity, tabs, childRegistry, eventEmitter, imageLoaderMock, "tabsController", new Options(), new Presenter(activity, new Options()), new BottomTabsAttacher(tabs, bottomTabsPresenter, Options.EMPTY), bottomTabsPresenter, new BottomTabPresenter(activity, tabs, ImageLoaderMock.mock(), new Options())) {
393 393
             @NonNull
394 394
             @Override
395 395
             protected BottomTabs createBottomTabs() {