Browse Source

Support setting interceptTouchOutside with mergeOptions

Closes $4225
Guy Carmeli 6 years ago
parent
commit
d627608bd2

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

@@ -5,6 +5,7 @@ import android.app.Activity;
5 5
 import com.facebook.react.ReactInstanceManager;
6 6
 import com.reactnativenavigation.presentation.BottomTabPresenter;
7 7
 import com.reactnativenavigation.presentation.BottomTabsPresenter;
8
+import com.reactnativenavigation.presentation.ComponentPresenter;
8 9
 import com.reactnativenavigation.presentation.Presenter;
9 10
 import com.reactnativenavigation.presentation.SideMenuPresenter;
10 11
 import com.reactnativenavigation.presentation.StackPresenter;
@@ -144,7 +145,8 @@ public class LayoutFactory {
144 145
                 name,
145 146
                 new ComponentViewCreator(reactInstanceManager),
146 147
                 parse(typefaceManager, node.getOptions()),
147
-                new Presenter(activity, defaultOptions)
148
+                new Presenter(activity, defaultOptions),
149
+                new ComponentPresenter()
148 150
         );
149 151
 	}
150 152
 

+ 11
- 0
lib/android/app/src/main/java/com/reactnativenavigation/presentation/ComponentPresenter.java View File

@@ -0,0 +1,11 @@
1
+package com.reactnativenavigation.presentation;
2
+
3
+import com.reactnativenavigation.parse.Options;
4
+import com.reactnativenavigation.views.ComponentLayout;
5
+
6
+public class ComponentPresenter {
7
+
8
+    public void mergeOptions(ComponentLayout view, Options options) {
9
+        if (options.overlayOptions.interceptTouchOutside.hasValue()) view.setInterceptTouchOutside(options.overlayOptions.interceptTouchOutside);
10
+    }
11
+}

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

@@ -5,6 +5,7 @@ import android.support.annotation.NonNull;
5 5
 import android.view.View;
6 6
 
7 7
 import com.reactnativenavigation.parse.Options;
8
+import com.reactnativenavigation.presentation.ComponentPresenter;
8 9
 import com.reactnativenavigation.presentation.Presenter;
9 10
 import com.reactnativenavigation.views.ComponentLayout;
10 11
 import com.reactnativenavigation.views.ReactComponent;
@@ -12,7 +13,7 @@ import com.reactnativenavigation.views.ReactComponent;
12 13
 public class ComponentViewController extends ChildController<ComponentLayout> {
13 14
 
14 15
     private final String componentName;
15
-
16
+    private ComponentPresenter presenter;
16 17
     private final ReactViewCreator viewCreator;
17 18
 
18 19
     public ComponentViewController(final Activity activity,
@@ -21,10 +22,12 @@ public class ComponentViewController extends ChildController<ComponentLayout> {
21 22
                                    final String componentName,
22 23
                                    final ReactViewCreator viewCreator,
23 24
                                    final Options initialOptions,
24
-                                   final Presenter presenter) {
25
+                                   final Presenter presenter,
26
+                                   final ComponentPresenter componentPresenter) {
25 27
         super(activity, childRegistry, id, presenter, initialOptions);
26 28
         this.componentName = componentName;
27 29
         this.viewCreator = viewCreator;
30
+        this.presenter = componentPresenter;
28 31
     }
29 32
 
30 33
     @Override
@@ -65,6 +68,7 @@ public class ComponentViewController extends ChildController<ComponentLayout> {
65 68
     @Override
66 69
     public void mergeOptions(Options options) {
67 70
         if (options == Options.EMPTY) return;
71
+        presenter.mergeOptions(getView(), options);
68 72
         performOnParentController(parentController -> parentController.mergeChildOptions(options, this, getView()));
69 73
         super.mergeOptions(options);
70 74
     }

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

@@ -9,6 +9,7 @@ import android.widget.RelativeLayout;
9 9
 
10 10
 import com.reactnativenavigation.interfaces.ScrollEventListener;
11 11
 import com.reactnativenavigation.parse.Options;
12
+import com.reactnativenavigation.parse.params.Bool;
12 13
 import com.reactnativenavigation.utils.ViewUtils;
13 14
 import com.reactnativenavigation.viewcontrollers.IReactView;
14 15
 import com.reactnativenavigation.viewcontrollers.TitleBarButtonController;
@@ -63,6 +64,10 @@ public class ComponentLayout extends FrameLayout implements ReactComponent, Titl
63 64
         touchDelegate.setInterceptTouchOutside(options.overlayOptions.interceptTouchOutside);
64 65
     }
65 66
 
67
+    public void setInterceptTouchOutside(Bool interceptTouchOutside) {
68
+        touchDelegate.setInterceptTouchOutside(interceptTouchOutside);
69
+    }
70
+
66 71
     @Override
67 72
     public void sendOnNavigationButtonPressed(String buttonId) {
68 73
         reactView.sendOnNavigationButtonPressed(buttonId);

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

@@ -3,11 +3,12 @@ package com.reactnativenavigation.mocks;
3 3
 import android.app.*;
4 4
 
5 5
 import com.reactnativenavigation.parse.*;
6
+import com.reactnativenavigation.presentation.ComponentPresenter;
6 7
 import com.reactnativenavigation.presentation.Presenter;
7 8
 import com.reactnativenavigation.viewcontrollers.*;
8 9
 
9 10
 public class SimpleComponentViewController extends ComponentViewController {
10 11
     public SimpleComponentViewController(Activity activity, ChildControllersRegistry childRegistry, String id, Options initialOptions) {
11
-        super(activity, childRegistry,id, "theComponentName", new TestComponentViewCreator(), initialOptions, new Presenter(activity, new Options()));
12
+        super(activity, childRegistry,id, "theComponentName", new TestComponentViewCreator(), initialOptions, new Presenter(activity, new Options()), new ComponentPresenter());
12 13
     }
13 14
 }

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

@@ -7,6 +7,7 @@ import com.reactnativenavigation.TestUtils;
7 7
 import com.reactnativenavigation.mocks.TestComponentLayout;
8 8
 import com.reactnativenavigation.mocks.TestReactView;
9 9
 import com.reactnativenavigation.parse.Options;
10
+import com.reactnativenavigation.presentation.ComponentPresenter;
10 11
 import com.reactnativenavigation.presentation.Presenter;
11 12
 import com.reactnativenavigation.views.StackLayout;
12 13
 
@@ -22,6 +23,7 @@ import static org.mockito.Mockito.when;
22 23
 public class ComponentViewControllerTest extends BaseTest {
23 24
     private ComponentViewController uut;
24 25
     private IReactView view;
26
+    private ComponentPresenter componentPresenter;
25 27
 
26 28
     @Override
27 29
     public void beforeEach() {
@@ -30,7 +32,8 @@ public class ComponentViewControllerTest extends BaseTest {
30 32
         view = spy(new TestComponentLayout(activity, new TestReactView(activity)));
31 33
         ParentController<StackLayout> parentController = TestUtils.newStackController(activity).build();
32 34
         Presenter presenter = new Presenter(activity, new Options());
33
-        uut = new ComponentViewController(activity, new ChildControllersRegistry(), "componentId1", "componentName", (activity1, componentId, componentName) -> view, new Options(), presenter);
35
+        this.componentPresenter = spy(new ComponentPresenter());
36
+        uut = new ComponentViewController(activity, new ChildControllersRegistry(), "componentId1", "componentName", (activity1, componentId, componentName) -> view, new Options(), presenter, this.componentPresenter);
34 37
         uut.setParentController(parentController);
35 38
         parentController.ensureViewIsCreated();
36 39
     }
@@ -85,4 +88,11 @@ public class ComponentViewControllerTest extends BaseTest {
85 88
         spy.mergeOptions(Options.EMPTY);
86 89
         verify(spy, times(0)).performOnParentController(any());
87 90
     }
91
+
92
+    @Test
93
+    public void mergeOptions_delegatesToPresenter() {
94
+        Options options = new Options();
95
+        uut.mergeOptions(options);
96
+        verify(componentPresenter).mergeOptions(uut.getView(), options);
97
+    }
88 98
 }

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

@@ -19,6 +19,7 @@ import com.reactnativenavigation.parse.params.Bool;
19 19
 import com.reactnativenavigation.parse.params.Colour;
20 20
 import com.reactnativenavigation.parse.params.Fraction;
21 21
 import com.reactnativenavigation.parse.params.Text;
22
+import com.reactnativenavigation.presentation.ComponentPresenter;
22 23
 import com.reactnativenavigation.presentation.Presenter;
23 24
 import com.reactnativenavigation.presentation.StackPresenter;
24 25
 import com.reactnativenavigation.utils.CommandListenerAdapter;
@@ -61,7 +62,8 @@ public class OptionsApplyingTest extends BaseTest {
61 62
                 "componentName",
62 63
                 (activity1, componentId, componentName) -> view,
63 64
                 initialNavigationOptions,
64
-                new Presenter(activity, new Options())
65
+                new Presenter(activity, new Options()),
66
+                new ComponentPresenter()
65 67
         ) {
66 68
             @Override
67 69
             public boolean isViewShown() {

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

@@ -12,6 +12,7 @@ import com.reactnativenavigation.mocks.TestReactView;
12 12
 import com.reactnativenavigation.parse.Options;
13 13
 import com.reactnativenavigation.parse.params.Bool;
14 14
 import com.reactnativenavigation.parse.params.Text;
15
+import com.reactnativenavigation.presentation.ComponentPresenter;
15 16
 import com.reactnativenavigation.presentation.Presenter;
16 17
 import com.reactnativenavigation.utils.CommandListenerAdapter;
17 18
 import com.reactnativenavigation.utils.ViewHelper;
@@ -90,7 +91,8 @@ public class TopTabsViewControllerTest extends BaseTest {
90 91
                     "theComponentName",
91 92
                     new TestComponentViewCreator(),
92 93
                     tabOptions.get(i),
93
-                    new Presenter(activity, new Options())
94
+                    new Presenter(activity, new Options()),
95
+                    new ComponentPresenter()
94 96
             );
95 97
             tabControllers.add(spy(viewController));
96 98
         }