Skip to content

Instantly share code, notes, and snippets.

@pfn
Created December 15, 2015 15:26
Show Gist options
  • Save pfn/4c235ace9cd38937c92a to your computer and use it in GitHub Desktop.
Save pfn/4c235ace9cd38937c92a to your computer and use it in GitHub Desktop.
@Override
public boolean onNestedFling(final CoordinatorLayout coordinatorLayout, final AppBarLayout child, View target, float velocityX, final float velocityY, boolean consumed) {
if (target instanceof RecyclerView && velocityY < 0) {
final RecyclerView recyclerView = (RecyclerView) target;
final long start = System.currentTimeMillis();
recyclerView.addOnScrollListener(new RecyclerView.OnScrollListener() {
@Override
public void onScrollStateChanged(RecyclerView recyclerView, int newState) {
if (newState == RecyclerView.SCROLL_STATE_IDLE) {
recyclerView.removeOnScrollListener(this);
final View firstChild = recyclerView.getChildAt(0);
final int childAdapterPosition = recyclerView.getChildAdapterPosition(firstChild);
final long end = System.currentTimeMillis();
long dT = end - start;
if (childAdapterPosition == 0)
fling(coordinatorLayout, child, -child.getTotalScrollRange(), 0, Cv(dT) * Math.abs(velocityY));
}
}
});
}
return super.onNestedFling(coordinatorLayout, child, target, velocityX, velocityY, true);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment