Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 17 additions & 4 deletions lib/java/com/google/android/material/carousel/KeylineState.java
Original file line number Diff line number Diff line change
Expand Up @@ -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<Keyline> fromKeylines = from.getKeylines();
List<Keyline> 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<Keyline> keylines = new ArrayList<>();
Expand All @@ -211,7 +215,7 @@ static KeylineState lerp(KeylineState from, KeylineState to, float progress) {
keylines,
focalKeylineFirstIndex,
focalKeylineLastIndex,
from.carouselSize);
from.getCarouselSize());
}

/**
Expand Down Expand Up @@ -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));
}
}
}