Skip to content

Commit

Permalink
[Carousel] Update vertical scroll speed to be faster
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 559888221
  • Loading branch information
imhappi committed Aug 25, 2023
1 parent 3d84841 commit c6ea2d4
Showing 1 changed file with 9 additions and 1 deletion.
Expand Up @@ -34,6 +34,10 @@
*/
public class CarouselSnapHelper extends SnapHelper {

private static final float HORIZONTAL_SNAP_SPEED = 100F;

private static final float VERTICAL_SNAP_SPEED = 50F;

private final boolean disableFling;
private RecyclerView recyclerView;

Expand Down Expand Up @@ -245,7 +249,11 @@ protected void onTargetFound(

@Override
protected float calculateSpeedPerPixel(DisplayMetrics displayMetrics) {
return 100.0F / (float) displayMetrics.densityDpi;
// If the carousel orientation is vertical, we want the scroll speed to be faster.
if (layoutManager.canScrollVertically()) {
return VERTICAL_SNAP_SPEED / (float) displayMetrics.densityDpi;
}
return HORIZONTAL_SNAP_SPEED / (float) displayMetrics.densityDpi;
}
}
: null;
Expand Down

0 comments on commit c6ea2d4

Please sign in to comment.