Bladeren bron

Fix crash when user tapped on screen before initial meaningful render

Guy Carmeli 6 jaren geleden
bovenliggende
commit
48b7d60bf7

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

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