浏览代码

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 5 年前
父节点
当前提交
a4b2c76a9d
没有帐户链接到提交者的电子邮件

+ 1
- 1
lib/android/app/src/main/java/com/reactnativenavigation/parse/LayoutFactory.java 查看文件

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

+ 6
- 3
lib/android/app/src/main/java/com/reactnativenavigation/viewcontrollers/bottomtabs/BottomTabsAttacher.java 查看文件

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

+ 19
- 3
lib/android/app/src/test/java/com/reactnativenavigation/viewcontrollers/bottomtabs/BottomTabsAttacherTest.java 查看文件

1
 package com.reactnativenavigation.viewcontrollers.bottomtabs;
1
 package com.reactnativenavigation.viewcontrollers.bottomtabs;
2
 
2
 
3
+import android.view.ViewGroup;
4
+
3
 import com.reactnativenavigation.BaseTest;
5
 import com.reactnativenavigation.BaseTest;
6
+import com.reactnativenavigation.parse.Options;
7
+import com.reactnativenavigation.parse.TabsAttachMode;
4
 import com.reactnativenavigation.presentation.BottomTabsPresenter;
8
 import com.reactnativenavigation.presentation.BottomTabsPresenter;
5
-import com.reactnativenavigation.viewcontrollers.*;
9
+import com.reactnativenavigation.viewcontrollers.ViewController;
6
 
10
 
7
 import org.junit.Test;
11
 import org.junit.Test;
8
 import org.mockito.Mockito;
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
 import static org.mockito.Mockito.mock;
18
 import static org.mockito.Mockito.mock;
13
 import static org.mockito.Mockito.verify;
19
 import static org.mockito.Mockito.verify;
14
 
20
 
16
 
22
 
17
     private BottomTabsAttacher uut;
23
     private BottomTabsAttacher uut;
18
     private AttachMode mode;
24
     private AttachMode mode;
25
+    private Options defaultOptions = new Options();
26
+    private List<ViewController> tabs;
19
 
27
 
20
     @Override
28
     @Override
21
     public void beforeEach() {
29
     public void beforeEach() {
22
         mode = Mockito.mock(AttachMode.class);
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
         uut.attachStrategy = mode;
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
     @Test
43
     @Test
28
     public void attach_delegatesToStrategy() {
44
     public void attach_delegatesToStrategy() {
29
         uut.attach();
45
         uut.attach();

+ 2
- 2
lib/android/app/src/test/java/com/reactnativenavigation/viewcontrollers/bottomtabs/BottomTabsControllerTest.java 查看文件

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

+ 1
- 1
lib/android/app/src/test/java/com/reactnativenavigation/viewcontrollers/navigator/NavigatorTest.java 查看文件

389
     @NonNull
389
     @NonNull
390
     private BottomTabsController newTabs(List<ViewController> tabs) {
390
     private BottomTabsController newTabs(List<ViewController> tabs) {
391
         BottomTabsPresenter bottomTabsPresenter = new BottomTabsPresenter(tabs, new Options());
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
             @NonNull
393
             @NonNull
394
             @Override
394
             @Override
395
             protected BottomTabs createBottomTabs() {
395
             protected BottomTabs createBottomTabs() {