Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow bounce easings along a path to return a position outside of the path #2457

Merged
merged 1 commit into from
Jan 31, 2024

Conversation

idlewan
Copy link
Contributor

@idlewan idlewan commented Jan 31, 2024

Don't clamp interpolated distance along path to 'progress' value between 0 and 1.

Bounce in / Bounce out easings can transform the progress to negative values or values higher than 1. getPosTan unfortunately clamps the input to be between 0 and 1, so we need to handle the t < 0 and t > 1 cases separately.

This is for the same issue I helped fix in the flutter library as well here: xvrh/lottie-flutter#330

Expected result (both bounce-in and bounce out) along linear and curved paths:

android-bounce-easings.mp4

Copy link

Snapshot Tests
API 23: Report Diff
API 31: Report Diff

Copy link
Collaborator

@gpeal gpeal left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for doing this. I didn't know you were a part of the lottielab team!

@gpeal gpeal merged commit a9d3a16 into airbnb:master Jan 31, 2024
6 checks passed
} else {
pathMeasure.getPosTan(keyframeProgress * length, pos, null);
point.set(pos[0], pos[1]);
}
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: since getPosTan() already clamps to end points, you could consolidate some calls

float distance =  keyframeProgress * length;
pathMeasure.getPosTan(distance, pos, tangent);
point.set(pos[0], pos[1]);

if (distance < 0) {
  point.offset(tangent[0] * distance, tangent[1] * distance);
} else if (distance > length) {
  point.offset(tangent[0] * (distance - length), tangent[1] * (distance - length));
}

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @fmalita
@idlewan want to put up another PR for this or would you like me to?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure thing, thanks for proposing a cleaner version!
Here's the PR: #2459

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants