Browse Source

Fix crash when user tapped on screen before initial meaningful render

Guy Carmeli 6 years ago
parent
commit
48b7d60bf7

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

3
 import android.graphics.Rect;
3
 import android.graphics.Rect;
4
 import android.support.annotation.VisibleForTesting;
4
 import android.support.annotation.VisibleForTesting;
5
 import android.view.MotionEvent;
5
 import android.view.MotionEvent;
6
+import android.view.View;
6
 import android.view.ViewGroup;
7
 import android.view.ViewGroup;
7
 
8
 
8
 import com.reactnativenavigation.parse.params.Bool;
9
 import com.reactnativenavigation.parse.params.Bool;
16
     private IReactView reactView;
17
     private IReactView reactView;
17
     private Bool interceptTouchOutside = new NullBool();
18
     private Bool interceptTouchOutside = new NullBool();
18
 
19
 
20
+    public void setInterceptTouchOutside(Bool interceptTouchOutside) {
21
+        this.interceptTouchOutside = interceptTouchOutside;
22
+    }
23
+
19
     public OverlayTouchDelegate(IReactView reactView) {
24
     public OverlayTouchDelegate(IReactView reactView) {
20
         this.reactView = reactView;
25
         this.reactView = reactView;
21
     }
26
     }
45
     }
50
     }
46
 
51
 
47
     private TouchLocation getTouchLocation(MotionEvent ev) {
52
     private TouchLocation getTouchLocation(MotionEvent ev) {
48
-        ((ViewGroup) reactView.asView()).getChildAt(0).getHitRect(hitRect);
53
+        getView((ViewGroup) reactView.asView()).getHitRect(hitRect);
49
         return hitRect.contains((int) ev.getRawX(), (int) ev.getRawY() - UiUtils.getStatusBarHeight(reactView.asView().getContext())) ?
54
         return hitRect.contains((int) ev.getRawX(), (int) ev.getRawY() - UiUtils.getStatusBarHeight(reactView.asView().getContext())) ?
50
                 TouchLocation.Inside :
55
                 TouchLocation.Inside :
51
                 TouchLocation.Outside;
56
                 TouchLocation.Outside;
52
     }
57
     }
53
 
58
 
54
-    public void setInterceptTouchOutside(Bool interceptTouchOutside) {
55
-        this.interceptTouchOutside = interceptTouchOutside;
59
+    private View getView(ViewGroup view) {
60
+        return view.getChildCount() > 0 ? view.getChildAt(0) : view;
56
     }
61
     }
57
 }
62
 }