From cf598b8158062fe875234b5ee8a1c1ac9e8fc808 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kristian=20Fallr=C3=B8?= Date: Fri, 27 Jul 2018 15:14:11 +0200 Subject: [PATCH] Fix race conditions for Support SDK 27 New stab at fixing it. --- .../RNBottomSheetBehavior.java | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/android/src/main/java/com/bottomsheetbehavior/RNBottomSheetBehavior.java b/android/src/main/java/com/bottomsheetbehavior/RNBottomSheetBehavior.java index 8df7d33..e29313e 100644 --- a/android/src/main/java/com/bottomsheetbehavior/RNBottomSheetBehavior.java +++ b/android/src/main/java/com/bottomsheetbehavior/RNBottomSheetBehavior.java @@ -208,6 +208,13 @@ public boolean onInterceptTouchEvent( CoordinatorLayout parent, V child, MotionE return false; } + /** + * Workaround for Support SDK 27 race condition. We'll wait until mViewDragHelper is available + */ + if ( mViewDragHelper == null ) { + return false; + } + int action = MotionEventCompat.getActionMasked( event ); if ( action == MotionEvent.ACTION_DOWN ) { reset(); @@ -250,14 +257,7 @@ public boolean onInterceptTouchEvent( CoordinatorLayout parent, V child, MotionE // We don't want to trigger a BottomSheet fling as a result of a Cancel MotionEvent (e.g., parent horizontal scroll view taking over touch events) mScrollVelocityTracker.clear(); } - - /** - * Workaround for Support SDK 27 race condition - */ - if ( mViewDragHelper == null ) { - mViewDragHelper = ViewDragHelper.create( parent, mDragCallback ); - } - + if ( ! mIgnoreEvents && mViewDragHelper.shouldInterceptTouchEvent( event ) ) { return true; }