Skip to content

Commit 2d35e33

Browse files
committed
[Carousel] Fix Keyline and KeylineState lerp functions
Resolves material-components#5073
1 parent 6654514 commit 2d35e33

1 file changed

Lines changed: 17 additions & 4 deletions

File tree

lib/java/com/google/android/material/carousel/KeylineState.java

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -185,13 +185,17 @@ int getCarouselSize() {
185185
static KeylineState lerp(KeylineState from, KeylineState to, float progress) {
186186
if (from.getItemSize() != to.getItemSize()) {
187187
throw new IllegalArgumentException(
188-
"Keylines being linearly interpolated must have the same item size.");
188+
"KeylineStates being linearly interpolated must have the same item size.");
189+
}
190+
if (from.getCarouselSize() != to.getCarouselSize()) {
191+
throw new IllegalArgumentException(
192+
"KeylineStates being linearly interpolated must have the same carousel size.");
189193
}
190194
List<Keyline> fromKeylines = from.getKeylines();
191195
List<Keyline> toKeylines = to.getKeylines();
192196
if (fromKeylines.size() != toKeylines.size()) {
193197
throw new IllegalArgumentException(
194-
"Keylines being linearly interpolated must have the same number of keylines.");
198+
"KeylineStates being linearly interpolated must have the same number of keylines.");
195199
}
196200

197201
List<Keyline> keylines = new ArrayList<>();
@@ -211,7 +215,7 @@ static KeylineState lerp(KeylineState from, KeylineState to, float progress) {
211215
keylines,
212216
focalKeylineFirstIndex,
213217
focalKeylineLastIndex,
214-
from.carouselSize);
218+
from.getCarouselSize());
215219
}
216220

217221
/**
@@ -717,11 +721,20 @@ static final class Keyline {
717721

718722
/** Linearly interpolates between two keylines and returns the interpolated object. */
719723
static Keyline lerp(Keyline from, Keyline to, @FloatRange(from = 0, to = 1) float progress) {
724+
if (from.isAnchor != to.isAnchor) {
725+
throw new IllegalArgumentException(
726+
"Keylines being linearly interpolated must have the same isAnchor value.");
727+
}
728+
720729
return new Keyline(
721730
AnimationUtils.lerp(from.loc, to.loc, progress),
722731
AnimationUtils.lerp(from.locOffset, to.locOffset, progress),
723732
AnimationUtils.lerp(from.mask, to.mask, progress),
724-
AnimationUtils.lerp(from.maskedItemSize, to.maskedItemSize, progress));
733+
AnimationUtils.lerp(from.maskedItemSize, to.maskedItemSize, progress),
734+
from.isAnchor,
735+
AnimationUtils.lerp(from.cutoff, to.cutoff, progress),
736+
AnimationUtils.lerp(from.leftOrTopPaddingShift, to.leftOrTopPaddingShift, progress),
737+
AnimationUtils.lerp(from.rightOrBottomPaddingShift, to.rightOrBottomPaddingShift, progress));
725738
}
726739
}
727740
}

0 commit comments

Comments
 (0)