Browse Source

FIx e2e on Android

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

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

70
         bottomTabsOptions.mergeWithDefault(other.bottomTabsOptions);
70
         bottomTabsOptions.mergeWithDefault(other.bottomTabsOptions);
71
         return this;
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
         super.applyOptions(options, childComponent);
58
         super.applyOptions(options, childComponent);
59
         int tabIndex = findTabContainingComponent(childComponent);
59
         int tabIndex = findTabContainingComponent(childComponent);
60
         if (tabIndex >= 0) new BottomTabOptionsPresenter(bottomTabs).present(options, tabIndex);
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
     @Override
66
     @Override

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

59
     @CallSuper
59
     @CallSuper
60
     public void applyOptions(Options options, ReactComponent childComponent) {
60
     public void applyOptions(Options options, ReactComponent childComponent) {
61
         mergeChildOptions(options);
61
         mergeChildOptions(options);
62
-        applyOnParentController(parentController -> ((ParentController) parentController).applyOptions(this.options, childComponent));
63
     }
62
     }
64
 
63
 
65
     private void mergeChildOptions(Options options) {
64
     private void mergeChildOptions(Options options) {

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

8
 import android.view.ViewGroup;
8
 import android.view.ViewGroup;
9
 
9
 
10
 import com.reactnativenavigation.parse.Options;
10
 import com.reactnativenavigation.parse.Options;
11
+import com.reactnativenavigation.views.ReactComponent;
11
 
12
 
12
 import java.util.ArrayList;
13
 import java.util.ArrayList;
13
 import java.util.Collection;
14
 import java.util.Collection;
41
 		return children;
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
 		this.centerController = centerController;
54
 		this.centerController = centerController;
46
 		View childView = centerController.getView();
55
 		View childView = centerController.getView();
47
 		getView().addView(childView);
56
 		getView().addView(childView);

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

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

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

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

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

166
         assertThat(uut.topBarOptions.visible.isFalseOrUndefined()).isTrue();
166
         assertThat(uut.topBarOptions.visible.isFalseOrUndefined()).isTrue();
167
         assertThat(uut.topBarOptions.animateHide.isTrueOrUndefined()).isTrue();
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
 import com.reactnativenavigation.mocks.ImageLoaderMock;
8
 import com.reactnativenavigation.mocks.ImageLoaderMock;
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.parse.Color;
11
 import com.reactnativenavigation.parse.Options;
12
 import com.reactnativenavigation.parse.Options;
12
 import com.reactnativenavigation.utils.ImageLoader;
13
 import com.reactnativenavigation.utils.ImageLoader;
13
 import com.reactnativenavigation.utils.OptionHelper;
14
 import com.reactnativenavigation.utils.OptionHelper;
14
 import com.reactnativenavigation.views.BottomTabs;
15
 import com.reactnativenavigation.views.BottomTabs;
16
+import com.reactnativenavigation.views.ReactComponent;
15
 
17
 
16
 import org.junit.Test;
18
 import org.junit.Test;
19
+import org.mockito.ArgumentCaptor;
17
 
20
 
18
 import java.util.Arrays;
21
 import java.util.Arrays;
19
 import java.util.Collections;
22
 import java.util.Collections;
118
         verify(spy, times(1)).handleBack();
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
     @NonNull
143
     @NonNull
122
     private List<ViewController> createTabs() {
144
     private List<ViewController> createTabs() {
123
         return Arrays.asList(child1, child2, child3, child4, child5);
145
         return Arrays.asList(child1, child2, child3, child4, child5);

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

1
 const React = require('react');
1
 const React = require('react');
2
 const { Component } = require('react');
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
 const { Navigation } = require('react-native-navigation');
6
 const { Navigation } = require('react-native-navigation');
7
 const testIDs = require('../testIDs');
7
 const testIDs = require('../testIDs');
16
       topBar: {
16
       topBar: {
17
         title: 'Static Title',
17
         title: 'Static Title',
18
         textColor: 'black',
18
         textColor: 'black',
19
-        drawBehind: false,
19
+        ...Platform.select({
20
+          android: { drawBehind: true },
21
+          ios: { drawBehind: false, }
22
+        }),
20
         largeTitle: false,
23
         largeTitle: false,
21
         visible: true,
24
         visible: true,
22
         textFontSize: 16,
25
         textFontSize: 16,