Skip to content

Commit

Permalink
Fix race conditions for Android Support SDK 27
Browse files Browse the repository at this point in the history
  • Loading branch information
kristfal authored Jul 23, 2018
1 parent 7a5a81e commit 05d16c6
Showing 1 changed file with 15 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -189,9 +189,14 @@ public boolean onLayoutChild( CoordinatorLayout parent, V child, int layoutDirec
toggleHeaderColor(false);
ViewCompat.offsetTopAndBottom(child, mMaxOffset);
}

/**
* Workaround for support SDK 27 race condition
*/
if ( mViewDragHelper == null ) {
mViewDragHelper = ViewDragHelper.create( parent, mDragCallback );
}

mViewRef = new WeakReference<>(child);
mNestedScrollingChildRef = new WeakReference<>( findScrollingChild( child ) );
return true;
Expand Down Expand Up @@ -219,6 +224,7 @@ public boolean onInterceptTouchEvent( CoordinatorLayout parent, V child, MotionE
return false;
}
break;

case MotionEvent.ACTION_DOWN:
int initialX = (int) event.getX();
mInitialY = (int) event.getY();
Expand All @@ -235,6 +241,7 @@ public boolean onInterceptTouchEvent( CoordinatorLayout parent, V child, MotionE
mIgnoreEvents = mActivePointerId == MotionEvent.INVALID_POINTER_ID &&
!parent.isPointInChildBounds(child, initialX, mInitialY);
break;

case MotionEvent.ACTION_MOVE:
break;
}
Expand All @@ -243,7 +250,14 @@ 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;
}
Expand Down

0 comments on commit 05d16c6

Please sign in to comment.