Browse Source

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 years ago
parent
commit
fefd96f7e8

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

@@ -57,7 +57,7 @@ public class ComponentLayout extends FrameLayout implements ReactComponent, TopB
57 57
 	}
58 58
 
59 59
     public void applyOptions(Options options) {
60
-        touchDelegate.setInterceptTouchOutside(options.overlayOptions.interceptTouchOutside.isTrue());
60
+        touchDelegate.setInterceptTouchOutside(options.overlayOptions.interceptTouchOutside);
61 61
     }
62 62
 
63 63
     @Override

+ 6
- 3
lib/android/app/src/main/java/com/reactnativenavigation/views/touch/OverlayTouchDelegate.java View File

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

+ 9
- 8
lib/android/app/src/test/java/com/reactnativenavigation/views/TouchDelegateTest.java View File

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