diff options
author | Stanley Wang <stanleytfwang@google.com> | 2021-06-16 17:02:34 +0800 |
---|---|---|
committer | Stanley Wang <stanleytfwang@google.com> | 2021-06-16 18:08:08 +0800 |
commit | 8ded831b9255a5807bc24a1455d332963f333232 (patch) | |
tree | 05fe4bbf03603703931670dfb2e19f7173e88ef9 | |
parent | fa5f3fa23a146fcb7e746c9636a828e655b37a56 (diff) | |
download | lottie-8ded831b9255a5807bc24a1455d332963f333232.tar.gz |
Add the offical patch to solve the LottieAnimationView exception.android-12.0.0_r32android-12.0.0_r29android-12.0.0_r28android-12.0.0_r27android-12.0.0_r26android-12.0.0_r21android-12.0.0_r20android-12.0.0_r19android-12.0.0_r18android-12.0.0_r16android12-qpr1-releaseandroid12-qpr1-d-s3-releaseandroid12-qpr1-d-s2-releaseandroid12-qpr1-d-s1-releaseandroid12-qpr1-d-releaseandroid12-dev
- When some illustrations are displayed, an exception
"The Path cannot loop back on itself" occurs.
Fix: 191230018
Test: see the illustration
Change-Id: I23e58b1ad62c0c96e174427e9e8f620b2f342cbb
-rw-r--r-- | lottie/src/main/java/com/airbnb/lottie/parser/KeyframeParser.java | 23 |
1 files changed, 21 insertions, 2 deletions
diff --git a/lottie/src/main/java/com/airbnb/lottie/parser/KeyframeParser.java b/lottie/src/main/java/com/airbnb/lottie/parser/KeyframeParser.java index 8cd45bac..5ba38ba6 100644 --- a/lottie/src/main/java/com/airbnb/lottie/parser/KeyframeParser.java +++ b/lottie/src/main/java/com/airbnb/lottie/parser/KeyframeParser.java @@ -137,8 +137,27 @@ class KeyframeParser { interpolator = interpolatorRef.get(); } if (interpolatorRef == null || interpolator == null) { - interpolator = PathInterpolatorCompat.create( - cp1.x / scale, cp1.y / scale, cp2.x / scale, cp2.y / scale); + cp1.x /= scale; + cp1.y /= scale; + cp2.x /= scale; + cp2.y /= scale; + try { + interpolator = PathInterpolatorCompat.create(cp1.x, cp1.y, cp2.x, cp2.y); + } catch (IllegalArgumentException e) { + if (e.getMessage().equals("The Path cannot loop back on itself.")) { + // If a control point extends beyond the previous/next point then it + // will cause the value of the interpolator to no longer monotonously + // increase. This clips the control point bounds to prevent that from + // happening. + // NOTE: this will make the rendered animation behave slightly differently + // than the original. + interpolator = PathInterpolatorCompat.create( + Math.min(cp1.x, 1f), cp1.y, Math.max(cp2.x, 0f), cp2.y); + } else { + // We failed to create the interpolator. Fall back to linear. + interpolator = new LinearInterpolator(); + } + } try { putInterpolator(hash, new WeakReference<>(interpolator)); } catch (ArrayIndexOutOfBoundsException e) { |