Skip to content

Commit

Permalink
Don't allow minFrame > maxFrame in LottieValueAnimator (airbnb#969)
Browse files Browse the repository at this point in the history
  • Loading branch information
Doug Melton authored and gpeal committed Oct 19, 2018
1 parent 65c5ee8 commit 8f8da11
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,9 @@ public void setMaxFrame(int maxFrame) {
}

public void setMinAndMaxFrames(int minFrame, int maxFrame) {
if (minFrame > maxFrame) {
throw new IllegalArgumentException(String.format("minFrame (%s) must be <= maxFrame (%s)", minFrame, maxFrame));
}
float compositionMinFrame = composition == null ? -Float.MAX_VALUE : composition.getStartFrame();
float compositionMaxFrame = composition == null ? Float.MAX_VALUE : composition.getEndFrame();
this.minFrame = MiscUtils.clamp(minFrame, compositionMinFrame, compositionMaxFrame);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,23 @@ public void testMinAndMaxBothSet() {
assertClose(0.8f, animator.getAnimatedValueAbsolute());
}

@Test
public void testSetFrameIntegrity() {
animator.setMinAndMaxFrames(200, 800);

// setFrame < minFrame should clamp to minFrame
animator.setFrame(100);
assertEquals(200, animator.getFrame());

animator.setFrame(900);
assertEquals(800, animator.getFrame());
}

@Test(expected = IllegalArgumentException.class)
public void testMinAndMaxFrameIntegrity() {
animator.setMinAndMaxFrames(800, 200);
}

@Test
public void testDefaultAnimator() {
testAnimator(new VerifyListener() {
Expand Down

0 comments on commit 8f8da11

Please sign in to comment.