Skip to content

Commit c6ea2d4

Browse files
committedAug 25, 2023
[Carousel] Update vertical scroll speed to be faster
PiperOrigin-RevId: 559888221
1 parent 3d84841 commit c6ea2d4

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed
 

‎lib/java/com/google/android/material/carousel/CarouselSnapHelper.java

+9-1
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,10 @@
3434
*/
3535
public class CarouselSnapHelper extends SnapHelper {
3636

37+
private static final float HORIZONTAL_SNAP_SPEED = 100F;
38+
39+
private static final float VERTICAL_SNAP_SPEED = 50F;
40+
3741
private final boolean disableFling;
3842
private RecyclerView recyclerView;
3943

@@ -245,7 +249,11 @@ protected void onTargetFound(
245249

246250
@Override
247251
protected float calculateSpeedPerPixel(DisplayMetrics displayMetrics) {
248-
return 100.0F / (float) displayMetrics.densityDpi;
252+
// If the carousel orientation is vertical, we want the scroll speed to be faster.
253+
if (layoutManager.canScrollVertically()) {
254+
return VERTICAL_SNAP_SPEED / (float) displayMetrics.densityDpi;
255+
}
256+
return HORIZONTAL_SNAP_SPEED / (float) displayMetrics.densityDpi;
249257
}
250258
}
251259
: null;

0 commit comments

Comments
 (0)