Browse Source

FIx e2e on Android

* applyOptions is applied in correct order
Guy Carmeli 6 years ago
parent
commit
edf6cc0291

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

@@ -70,4 +70,14 @@ public class Options implements DEFAULT_VALUES {
70 70
         bottomTabsOptions.mergeWithDefault(other.bottomTabsOptions);
71 71
         return this;
72 72
     }
73
+
74
+    public Options clearTopBarOptions() {
75
+        topBarOptions = new TopBarOptions();
76
+        return this;
77
+    }
78
+
79
+    public Options clearBottomTabsOptions() {
80
+        bottomTabsOptions = new BottomTabsOptions();
81
+        return this;
82
+    }
73 83
 }

+ 3
- 0
lib/android/app/src/main/java/com/reactnativenavigation/viewcontrollers/BottomTabsController.java View File

@@ -58,6 +58,9 @@ public class BottomTabsController extends ParentController implements AHBottomNa
58 58
         super.applyOptions(options, childComponent);
59 59
         int tabIndex = findTabContainingComponent(childComponent);
60 60
         if (tabIndex >= 0) new BottomTabOptionsPresenter(bottomTabs).present(options, tabIndex);
61
+        applyOnParentController(parentController ->
62
+                ((ParentController) parentController).applyOptions(this.options.copy().clearBottomTabsOptions(), childComponent)
63
+        );
61 64
     }
62 65
 
63 66
     @Override

+ 0
- 1
lib/android/app/src/main/java/com/reactnativenavigation/viewcontrollers/ParentController.java View File

@@ -59,7 +59,6 @@ public abstract class ParentController<T extends ViewGroup> extends ViewControll
59 59
     @CallSuper
60 60
     public void applyOptions(Options options, ReactComponent childComponent) {
61 61
         mergeChildOptions(options);
62
-        applyOnParentController(parentController -> ((ParentController) parentController).applyOptions(this.options, childComponent));
63 62
     }
64 63
 
65 64
     private void mergeChildOptions(Options options) {

+ 10
- 1
lib/android/app/src/main/java/com/reactnativenavigation/viewcontrollers/SideMenuController.java View File

@@ -8,6 +8,7 @@ import android.view.View;
8 8
 import android.view.ViewGroup;
9 9
 
10 10
 import com.reactnativenavigation.parse.Options;
11
+import com.reactnativenavigation.views.ReactComponent;
11 12
 
12 13
 import java.util.ArrayList;
13 14
 import java.util.Collection;
@@ -41,7 +42,15 @@ public class SideMenuController extends ParentController {
41 42
 		return children;
42 43
 	}
43 44
 
44
-	public void setCenterController(ViewController centerController) {
45
+    @Override
46
+    public void applyOptions(Options options, ReactComponent childComponent) {
47
+        super.applyOptions(options, childComponent);
48
+        applyOnParentController(parentController ->
49
+                ((ParentController) parentController).applyOptions(this.options, childComponent)
50
+        );
51
+    }
52
+
53
+    public void setCenterController(ViewController centerController) {
45 54
 		this.centerController = centerController;
46 55
 		View childView = centerController.getView();
47 56
 		getView().addView(childView);

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

@@ -38,6 +38,9 @@ public class StackController extends ParentController <StackLayout> {
38 38
     public void applyOptions(Options options, ReactComponent component) {
39 39
         super.applyOptions(options, component);
40 40
         stackLayout.applyOptions(this.options, component);
41
+        applyOnParentController(parentController ->
42
+                ((ParentController) parentController).applyOptions(this.options, component)
43
+        );
41 44
     }
42 45
 
43 46
     @Override

+ 3
- 0
lib/android/app/src/main/java/com/reactnativenavigation/viewcontrollers/toptabs/TopTabsController.java View File

@@ -70,6 +70,9 @@ public class TopTabsController extends ParentController<TopTabsViewPager> implem
70 70
     @Override
71 71
     public void applyOptions(Options options, ReactComponent childComponent) {
72 72
         super.applyOptions(options, childComponent);
73
+        applyOnParentController(parentController ->
74
+                ((ParentController) parentController).applyOptions(this.options, childComponent)
75
+        );
73 76
     }
74 77
 
75 78
     @Override

+ 22
- 0
lib/android/app/src/test/java/com/reactnativenavigation/parse/OptionsTest.java View File

@@ -166,4 +166,26 @@ public class OptionsTest extends BaseTest {
166 166
         assertThat(uut.topBarOptions.visible.isFalseOrUndefined()).isTrue();
167 167
         assertThat(uut.topBarOptions.animateHide.isTrueOrUndefined()).isTrue();
168 168
     }
169
+
170
+    @Test
171
+    public void clear_topBarOptions() throws Exception {
172
+        Options uut = new Options();
173
+        uut.topBarOptions.title = new Text("some title");
174
+        uut.clearTopBarOptions();
175
+        assertThat(uut.topBarOptions.title.hasValue()).isFalse();
176
+    }
177
+
178
+    @Test
179
+    public void clear_bottomTabsOptions() throws Exception {
180
+        Options uut = new Options();
181
+        uut.bottomTabsOptions.color = new Color(android.graphics.Color.RED);
182
+        uut.clearBottomTabsOptions();
183
+        assertThat(uut.bottomTabsOptions.color.hasValue()).isFalse();
184
+    }
185
+
186
+//    topBarOptions.mergeWithDefault(other.topBarOptions);
187
+//        topTabOptions.mergeWithDefault(other.topTabOptions);
188
+//        topTabsOptions.mergeWithDefault(other.topTabsOptions);
189
+//        bottomTabOptions.mergeWithDefault(other.bottomTabOptions);
190
+//        bottomTabsOptions.mergeWithDefault(other.bottomTabsOptions);
169 191
 }

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

@@ -8,12 +8,15 @@ import com.reactnativenavigation.BaseTest;
8 8
 import com.reactnativenavigation.mocks.ImageLoaderMock;
9 9
 import com.reactnativenavigation.mocks.MockPromise;
10 10
 import com.reactnativenavigation.mocks.SimpleViewController;
11
+import com.reactnativenavigation.parse.Color;
11 12
 import com.reactnativenavigation.parse.Options;
12 13
 import com.reactnativenavigation.utils.ImageLoader;
13 14
 import com.reactnativenavigation.utils.OptionHelper;
14 15
 import com.reactnativenavigation.views.BottomTabs;
16
+import com.reactnativenavigation.views.ReactComponent;
15 17
 
16 18
 import org.junit.Test;
19
+import org.mockito.ArgumentCaptor;
17 20
 
18 21
 import java.util.Arrays;
19 22
 import java.util.Collections;
@@ -118,6 +121,25 @@ public class BottomTabsControllerTest extends BaseTest {
118 121
         verify(spy, times(1)).handleBack();
119 122
     }
120 123
 
124
+    @Test
125
+    public void applyOptions_bottomTabsOptionsAreClearedAfterApply() throws Exception {
126
+        List<ViewController> tabs = createTabs();
127
+        child1.options.bottomTabsOptions.color = new Color(android.graphics.Color.RED);
128
+        uut.setTabs(tabs);
129
+        uut.ensureViewIsCreated();
130
+
131
+        StackController stack = spy(new StackController(activity, "stack", new Options()));
132
+        stack.ensureViewIsCreated();
133
+        stack.push(uut, new MockPromise());
134
+
135
+        child1.onViewAppeared();
136
+        ArgumentCaptor<Options> optionsCaptor = ArgumentCaptor.forClass(Options.class);
137
+        ArgumentCaptor<ReactComponent> viewCaptor = ArgumentCaptor.forClass(ReactComponent.class);
138
+        verify(stack, times(1)).applyOptions(optionsCaptor.capture(), viewCaptor.capture());
139
+        assertThat(viewCaptor.getValue()).isEqualTo(child1.getView());
140
+        assertThat(optionsCaptor.getValue().bottomTabsOptions.color.hasValue()).isFalse();
141
+    }
142
+
121 143
     @NonNull
122 144
     private List<ViewController> createTabs() {
123 145
         return Arrays.asList(child1, child2, child3, child4, child5);

+ 5
- 2
playground/src/screens/OptionsScreen.js View File

@@ -1,7 +1,7 @@
1 1
 const React = require('react');
2 2
 const { Component } = require('react');
3 3
 
4
-const { View, Text, Button } = require('react-native');
4
+const { View, Text, Button, Platform } = require('react-native');
5 5
 
6 6
 const { Navigation } = require('react-native-navigation');
7 7
 const testIDs = require('../testIDs');
@@ -16,7 +16,10 @@ class OptionsScreen extends Component {
16 16
       topBar: {
17 17
         title: 'Static Title',
18 18
         textColor: 'black',
19
-        drawBehind: false,
19
+        ...Platform.select({
20
+          android: { drawBehind: true },
21
+          ios: { drawBehind: false, }
22
+        }),
20 23
         largeTitle: false,
21 24
         visible: true,
22 25
         textFontSize: 16,