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
 import com.facebook.react.ReactInstanceManager;
5
 import com.facebook.react.ReactInstanceManager;
6
 import com.reactnativenavigation.presentation.BottomTabPresenter;
6
 import com.reactnativenavigation.presentation.BottomTabPresenter;
7
 import com.reactnativenavigation.presentation.BottomTabsPresenter;
7
 import com.reactnativenavigation.presentation.BottomTabsPresenter;
8
+import com.reactnativenavigation.presentation.ComponentPresenter;
8
 import com.reactnativenavigation.presentation.Presenter;
9
 import com.reactnativenavigation.presentation.Presenter;
9
 import com.reactnativenavigation.presentation.SideMenuPresenter;
10
 import com.reactnativenavigation.presentation.SideMenuPresenter;
10
 import com.reactnativenavigation.presentation.StackPresenter;
11
 import com.reactnativenavigation.presentation.StackPresenter;
144
                 name,
145
                 name,
145
                 new ComponentViewCreator(reactInstanceManager),
146
                 new ComponentViewCreator(reactInstanceManager),
146
                 parse(typefaceManager, node.getOptions()),
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

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

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

9
 
9
 
10
 import com.reactnativenavigation.interfaces.ScrollEventListener;
10
 import com.reactnativenavigation.interfaces.ScrollEventListener;
11
 import com.reactnativenavigation.parse.Options;
11
 import com.reactnativenavigation.parse.Options;
12
+import com.reactnativenavigation.parse.params.Bool;
12
 import com.reactnativenavigation.utils.ViewUtils;
13
 import com.reactnativenavigation.utils.ViewUtils;
13
 import com.reactnativenavigation.viewcontrollers.IReactView;
14
 import com.reactnativenavigation.viewcontrollers.IReactView;
14
 import com.reactnativenavigation.viewcontrollers.TitleBarButtonController;
15
 import com.reactnativenavigation.viewcontrollers.TitleBarButtonController;
63
         touchDelegate.setInterceptTouchOutside(options.overlayOptions.interceptTouchOutside);
64
         touchDelegate.setInterceptTouchOutside(options.overlayOptions.interceptTouchOutside);
64
     }
65
     }
65
 
66
 
67
+    public void setInterceptTouchOutside(Bool interceptTouchOutside) {
68
+        touchDelegate.setInterceptTouchOutside(interceptTouchOutside);
69
+    }
70
+
66
     @Override
71
     @Override
67
     public void sendOnNavigationButtonPressed(String buttonId) {
72
     public void sendOnNavigationButtonPressed(String buttonId) {
68
         reactView.sendOnNavigationButtonPressed(buttonId);
73
         reactView.sendOnNavigationButtonPressed(buttonId);

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

3
 import android.app.*;
3
 import android.app.*;
4
 
4
 
5
 import com.reactnativenavigation.parse.*;
5
 import com.reactnativenavigation.parse.*;
6
+import com.reactnativenavigation.presentation.ComponentPresenter;
6
 import com.reactnativenavigation.presentation.Presenter;
7
 import com.reactnativenavigation.presentation.Presenter;
7
 import com.reactnativenavigation.viewcontrollers.*;
8
 import com.reactnativenavigation.viewcontrollers.*;
8
 
9
 
9
 public class SimpleComponentViewController extends ComponentViewController {
10
 public class SimpleComponentViewController extends ComponentViewController {
10
     public SimpleComponentViewController(Activity activity, ChildControllersRegistry childRegistry, String id, Options initialOptions) {
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
 import com.reactnativenavigation.mocks.TestComponentLayout;
7
 import com.reactnativenavigation.mocks.TestComponentLayout;
8
 import com.reactnativenavigation.mocks.TestReactView;
8
 import com.reactnativenavigation.mocks.TestReactView;
9
 import com.reactnativenavigation.parse.Options;
9
 import com.reactnativenavigation.parse.Options;
10
+import com.reactnativenavigation.presentation.ComponentPresenter;
10
 import com.reactnativenavigation.presentation.Presenter;
11
 import com.reactnativenavigation.presentation.Presenter;
11
 import com.reactnativenavigation.views.StackLayout;
12
 import com.reactnativenavigation.views.StackLayout;
12
 
13
 
22
 public class ComponentViewControllerTest extends BaseTest {
23
 public class ComponentViewControllerTest extends BaseTest {
23
     private ComponentViewController uut;
24
     private ComponentViewController uut;
24
     private IReactView view;
25
     private IReactView view;
26
+    private ComponentPresenter componentPresenter;
25
 
27
 
26
     @Override
28
     @Override
27
     public void beforeEach() {
29
     public void beforeEach() {
30
         view = spy(new TestComponentLayout(activity, new TestReactView(activity)));
32
         view = spy(new TestComponentLayout(activity, new TestReactView(activity)));
31
         ParentController<StackLayout> parentController = TestUtils.newStackController(activity).build();
33
         ParentController<StackLayout> parentController = TestUtils.newStackController(activity).build();
32
         Presenter presenter = new Presenter(activity, new Options());
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
         uut.setParentController(parentController);
37
         uut.setParentController(parentController);
35
         parentController.ensureViewIsCreated();
38
         parentController.ensureViewIsCreated();
36
     }
39
     }
85
         spy.mergeOptions(Options.EMPTY);
88
         spy.mergeOptions(Options.EMPTY);
86
         verify(spy, times(0)).performOnParentController(any());
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
 import com.reactnativenavigation.parse.params.Colour;
19
 import com.reactnativenavigation.parse.params.Colour;
20
 import com.reactnativenavigation.parse.params.Fraction;
20
 import com.reactnativenavigation.parse.params.Fraction;
21
 import com.reactnativenavigation.parse.params.Text;
21
 import com.reactnativenavigation.parse.params.Text;
22
+import com.reactnativenavigation.presentation.ComponentPresenter;
22
 import com.reactnativenavigation.presentation.Presenter;
23
 import com.reactnativenavigation.presentation.Presenter;
23
 import com.reactnativenavigation.presentation.StackPresenter;
24
 import com.reactnativenavigation.presentation.StackPresenter;
24
 import com.reactnativenavigation.utils.CommandListenerAdapter;
25
 import com.reactnativenavigation.utils.CommandListenerAdapter;
61
                 "componentName",
62
                 "componentName",
62
                 (activity1, componentId, componentName) -> view,
63
                 (activity1, componentId, componentName) -> view,
63
                 initialNavigationOptions,
64
                 initialNavigationOptions,
64
-                new Presenter(activity, new Options())
65
+                new Presenter(activity, new Options()),
66
+                new ComponentPresenter()
65
         ) {
67
         ) {
66
             @Override
68
             @Override
67
             public boolean isViewShown() {
69
             public boolean isViewShown() {

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

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