diff --git a/lib/java/com/google/android/material/carousel/KeylineState.java b/lib/java/com/google/android/material/carousel/KeylineState.java index 1a173e800b2..a65e50baf46 100644 --- a/lib/java/com/google/android/material/carousel/KeylineState.java +++ b/lib/java/com/google/android/material/carousel/KeylineState.java @@ -185,13 +185,17 @@ int getCarouselSize() { static KeylineState lerp(KeylineState from, KeylineState to, float progress) { if (from.getItemSize() != to.getItemSize()) { throw new IllegalArgumentException( - "Keylines being linearly interpolated must have the same item size."); + "KeylineStates being linearly interpolated must have the same item size."); + } + if (from.getCarouselSize() != to.getCarouselSize()) { + throw new IllegalArgumentException( + "KeylineStates being linearly interpolated must have the same carousel size."); } List fromKeylines = from.getKeylines(); List toKeylines = to.getKeylines(); if (fromKeylines.size() != toKeylines.size()) { throw new IllegalArgumentException( - "Keylines being linearly interpolated must have the same number of keylines."); + "KeylineStates being linearly interpolated must have the same number of keylines."); } List keylines = new ArrayList<>(); @@ -211,7 +215,7 @@ static KeylineState lerp(KeylineState from, KeylineState to, float progress) { keylines, focalKeylineFirstIndex, focalKeylineLastIndex, - from.carouselSize); + from.getCarouselSize()); } /** @@ -717,11 +721,20 @@ static final class Keyline { /** Linearly interpolates between two keylines and returns the interpolated object. */ static Keyline lerp(Keyline from, Keyline to, @FloatRange(from = 0, to = 1) float progress) { + if (from.isAnchor != to.isAnchor) { + throw new IllegalArgumentException( + "Keylines being linearly interpolated must have the same isAnchor value."); + } + return new Keyline( AnimationUtils.lerp(from.loc, to.loc, progress), AnimationUtils.lerp(from.locOffset, to.locOffset, progress), AnimationUtils.lerp(from.mask, to.mask, progress), - AnimationUtils.lerp(from.maskedItemSize, to.maskedItemSize, progress)); + AnimationUtils.lerp(from.maskedItemSize, to.maskedItemSize, progress), + from.isAnchor, + AnimationUtils.lerp(from.cutoff, to.cutoff, progress), + AnimationUtils.lerp(from.leftOrTopPaddingShift, to.leftOrTopPaddingShift, progress), + AnimationUtils.lerp(from.rightOrBottomPaddingShift, to.rightOrBottomPaddingShift, progress)); } } }