|
@@ -5,9 +5,11 @@ import android.support.annotation.VisibleForTesting;
|
5
|
5
|
import android.view.MotionEvent;
|
6
|
6
|
import android.view.ViewGroup;
|
7
|
7
|
|
|
8
|
+import com.reactnativenavigation.utils.UiUtils;
|
8
|
9
|
import com.reactnativenavigation.viewcontrollers.IReactView;
|
9
|
10
|
|
10
|
11
|
public class OverlayTouchDelegate {
|
|
12
|
+ private enum TouchLocation {Outside, Inside}
|
11
|
13
|
private final Rect hitRect = new Rect();
|
12
|
14
|
private IReactView reactView;
|
13
|
15
|
private boolean interceptTouchOutside;
|
|
@@ -17,22 +19,33 @@ public class OverlayTouchDelegate {
|
17
|
19
|
}
|
18
|
20
|
|
19
|
21
|
public boolean onInterceptTouchEvent(MotionEvent event) {
|
20
|
|
- return interceptTouchOutside && isDown(event) && handleDown(event);
|
21
|
|
- }
|
22
|
|
-
|
23
|
|
- private boolean isDown(MotionEvent event) {
|
24
|
|
- return event.getActionMasked() == MotionEvent.ACTION_DOWN;
|
|
22
|
+ switch (event.getActionMasked()) {
|
|
23
|
+ case MotionEvent.ACTION_DOWN:
|
|
24
|
+ return handleDown(event);
|
|
25
|
+ default:
|
|
26
|
+ reactView.dispatchTouchEventToJs(event);
|
|
27
|
+ return false;
|
|
28
|
+
|
|
29
|
+ }
|
25
|
30
|
}
|
26
|
31
|
|
27
|
32
|
@VisibleForTesting
|
28
|
33
|
public boolean handleDown(MotionEvent event) {
|
29
|
|
- ((ViewGroup) reactView.asView()).getChildAt(0).getHitRect(hitRect);
|
30
|
|
- reactView.dispatchTouchEventToJs(event);
|
31
|
|
- return isTouchOutside(event);
|
|
34
|
+ TouchLocation location = getTouchLocation(event);
|
|
35
|
+ if (location == TouchLocation.Inside) {
|
|
36
|
+ reactView.dispatchTouchEventToJs(event);
|
|
37
|
+ }
|
|
38
|
+ if (interceptTouchOutside) {
|
|
39
|
+ return location == TouchLocation.Inside;
|
|
40
|
+ }
|
|
41
|
+ return location == TouchLocation.Outside;
|
32
|
42
|
}
|
33
|
43
|
|
34
|
|
- private boolean isTouchOutside(MotionEvent ev) {
|
35
|
|
- return !hitRect.contains((int) ev.getRawX(), (int) ev.getRawY());
|
|
44
|
+ private TouchLocation getTouchLocation(MotionEvent ev) {
|
|
45
|
+ ((ViewGroup) reactView.asView()).getChildAt(0).getHitRect(hitRect);
|
|
46
|
+ return hitRect.contains((int) ev.getRawX(), (int) ev.getRawY() - UiUtils.getStatusBarHeight(reactView.asView().getContext())) ?
|
|
47
|
+ TouchLocation.Inside :
|
|
48
|
+ TouchLocation.Outside;
|
36
|
49
|
}
|
37
|
50
|
|
38
|
51
|
public void setInterceptTouchOutside(boolean interceptTouchOutside) {
|