Преглед изворни кода

InterceptTouchOutside only when requested explicitly by the user

This works around an issue with RN's view reconciliation when the
root component has no background color defined.
Guy Carmeli пре 6 година
родитељ
комит
fefd96f7e8

+ 1
- 1
lib/android/app/src/main/java/com/reactnativenavigation/views/ComponentLayout.java Прегледај датотеку

57
 	}
57
 	}
58
 
58
 
59
     public void applyOptions(Options options) {
59
     public void applyOptions(Options options) {
60
-        touchDelegate.setInterceptTouchOutside(options.overlayOptions.interceptTouchOutside.isTrue());
60
+        touchDelegate.setInterceptTouchOutside(options.overlayOptions.interceptTouchOutside);
61
     }
61
     }
62
 
62
 
63
     @Override
63
     @Override

+ 6
- 3
lib/android/app/src/main/java/com/reactnativenavigation/views/touch/OverlayTouchDelegate.java Прегледај датотеку

5
 import android.view.MotionEvent;
5
 import android.view.MotionEvent;
6
 import android.view.ViewGroup;
6
 import android.view.ViewGroup;
7
 
7
 
8
+import com.reactnativenavigation.parse.params.Bool;
9
+import com.reactnativenavigation.parse.params.NullBool;
8
 import com.reactnativenavigation.utils.UiUtils;
10
 import com.reactnativenavigation.utils.UiUtils;
9
 import com.reactnativenavigation.viewcontrollers.IReactView;
11
 import com.reactnativenavigation.viewcontrollers.IReactView;
10
 
12
 
12
     private enum TouchLocation {Outside, Inside}
14
     private enum TouchLocation {Outside, Inside}
13
     private final Rect hitRect = new Rect();
15
     private final Rect hitRect = new Rect();
14
     private IReactView reactView;
16
     private IReactView reactView;
15
-    private boolean interceptTouchOutside;
17
+    private Bool interceptTouchOutside = new NullBool();
16
 
18
 
17
     public OverlayTouchDelegate(IReactView reactView) {
19
     public OverlayTouchDelegate(IReactView reactView) {
18
         this.reactView = reactView;
20
         this.reactView = reactView;
19
     }
21
     }
20
 
22
 
21
     public boolean onInterceptTouchEvent(MotionEvent event) {
23
     public boolean onInterceptTouchEvent(MotionEvent event) {
24
+        if (interceptTouchOutside instanceof NullBool) return false;
22
         switch (event.getActionMasked()) {
25
         switch (event.getActionMasked()) {
23
             case MotionEvent.ACTION_DOWN:
26
             case MotionEvent.ACTION_DOWN:
24
                 return handleDown(event);
27
                 return handleDown(event);
35
         if (location == TouchLocation.Inside) {
38
         if (location == TouchLocation.Inside) {
36
             reactView.dispatchTouchEventToJs(event);
39
             reactView.dispatchTouchEventToJs(event);
37
         }
40
         }
38
-        if (interceptTouchOutside) {
41
+        if (interceptTouchOutside.isTrue()) {
39
             return location == TouchLocation.Inside;
42
             return location == TouchLocation.Inside;
40
         }
43
         }
41
         return location == TouchLocation.Outside;
44
         return location == TouchLocation.Outside;
48
                 TouchLocation.Outside;
51
                 TouchLocation.Outside;
49
     }
52
     }
50
 
53
 
51
-    public void setInterceptTouchOutside(boolean interceptTouchOutside) {
54
+    public void setInterceptTouchOutside(Bool interceptTouchOutside) {
52
         this.interceptTouchOutside = interceptTouchOutside;
55
         this.interceptTouchOutside = interceptTouchOutside;
53
     }
56
     }
54
 }
57
 }

+ 9
- 8
lib/android/app/src/test/java/com/reactnativenavigation/views/TouchDelegateTest.java Прегледај датотеку

4
 
4
 
5
 import com.reactnativenavigation.BaseTest;
5
 import com.reactnativenavigation.BaseTest;
6
 import com.reactnativenavigation.mocks.SimpleOverlay;
6
 import com.reactnativenavigation.mocks.SimpleOverlay;
7
+import com.reactnativenavigation.parse.params.Bool;
7
 import com.reactnativenavigation.views.touch.OverlayTouchDelegate;
8
 import com.reactnativenavigation.views.touch.OverlayTouchDelegate;
8
 
9
 
9
 import org.junit.Test;
10
 import org.junit.Test;
29
     }
30
     }
30
 
31
 
31
     @Test
32
     @Test
32
-    public void downEventIsHandled() throws Exception {
33
-        uut.setInterceptTouchOutside(true);
33
+    public void downEventIsHandled() {
34
+        uut.setInterceptTouchOutside(new Bool(true));
34
         uut.onInterceptTouchEvent(downEvent);
35
         uut.onInterceptTouchEvent(downEvent);
35
         verify(uut, times(1)).handleDown(downEvent);
36
         verify(uut, times(1)).handleDown(downEvent);
36
     }
37
     }
37
 
38
 
38
     @Test
39
     @Test
39
-    public void onlyDownEventIsHandled() throws Exception {
40
-        uut.setInterceptTouchOutside(true);
40
+    public void onlyDownEventIsHandled() {
41
+        uut.setInterceptTouchOutside(new Bool(true));
41
         uut.onInterceptTouchEvent(upEvent);
42
         uut.onInterceptTouchEvent(upEvent);
42
         verify(uut, times(0)).handleDown(upEvent);
43
         verify(uut, times(0)).handleDown(upEvent);
43
     }
44
     }
44
 
45
 
45
     @Test
46
     @Test
46
-    public void nonDownEventsDontIntercept() throws Exception {
47
-        uut.setInterceptTouchOutside(true);
47
+    public void nonDownEventsDontIntercept() {
48
+        uut.setInterceptTouchOutside(new Bool(true));
48
         assertThat(uut.onInterceptTouchEvent(upEvent)).isFalse();
49
         assertThat(uut.onInterceptTouchEvent(upEvent)).isFalse();
49
     }
50
     }
50
 
51
 
51
     @Test
52
     @Test
52
-    public void nonDownEventsDispatchTouchEventsToJs() throws Exception {
53
-        uut.setInterceptTouchOutside(true);
53
+    public void nonDownEventsDispatchTouchEventsToJs() {
54
+        uut.setInterceptTouchOutside(new Bool(true));
54
         uut.onInterceptTouchEvent(upEvent);
55
         uut.onInterceptTouchEvent(upEvent);
55
         verify(reactView, times(1)).dispatchTouchEventToJs(upEvent);
56
         verify(reactView, times(1)).dispatchTouchEventToJs(upEvent);
56
     }
57
     }