From 3f4e535d99523ba0ae634af804f56b8db71b0187 Mon Sep 17 00:00:00 2001 From: walle <914653872@qq.com> Date: Mon, 28 Oct 2024 03:24:47 +0800 Subject: [PATCH] Apply left/top bounds before scaling (#2565) --- .../com/airbnb/lottie/LottieDrawable.java | 2 +- .../lottie/snapshots/tests/SeekBarTestCase.kt | 21 ++++++++++++++++++- 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/lottie/src/main/java/com/airbnb/lottie/LottieDrawable.java b/lottie/src/main/java/com/airbnb/lottie/LottieDrawable.java index f9bc737b49..9c2f424545 100644 --- a/lottie/src/main/java/com/airbnb/lottie/LottieDrawable.java +++ b/lottie/src/main/java/com/airbnb/lottie/LottieDrawable.java @@ -1745,8 +1745,8 @@ private void drawDirectlyToCanvas(Canvas canvas) { float scaleX = bounds.width() / (float) composition.getBounds().width(); float scaleY = bounds.height() / (float) composition.getBounds().height(); - renderingMatrix.preScale(scaleX, scaleY); renderingMatrix.preTranslate(bounds.left, bounds.top); + renderingMatrix.preScale(scaleX, scaleY); } compositionLayer.draw(canvas, renderingMatrix, alpha, null); } diff --git a/snapshot-tests/src/androidTest/java/com/airbnb/lottie/snapshots/tests/SeekBarTestCase.kt b/snapshot-tests/src/androidTest/java/com/airbnb/lottie/snapshots/tests/SeekBarTestCase.kt index 4be13fa5f4..f24ea26ea7 100644 --- a/snapshot-tests/src/androidTest/java/com/airbnb/lottie/snapshots/tests/SeekBarTestCase.kt +++ b/snapshot-tests/src/androidTest/java/com/airbnb/lottie/snapshots/tests/SeekBarTestCase.kt @@ -28,7 +28,26 @@ class SeekBarTestCase : SnapshotTestCase { val canvas = Canvas(bitmap) binding.root.draw(canvas) snapshotter.record(bitmap, "SeekBar", "ThumbDrawable") + + val compositionForScale = LottieCompositionFactory.fromAssetSync(context, "Tests/Thumb.json").value!! + val scaleDrawable = object : LottieDrawable() { + override fun getIntrinsicWidth(): Int { + return compositionForScale.unscaledWidth * 2 + } + + override fun getIntrinsicHeight(): Int { + return compositionForScale.unscaledHeight * 2 + } + } + scaleDrawable.composition = compositionForScale + binding.seekBar.thumb = scaleDrawable + val bitmapForScale = bitmapPool.acquire(binding.root.measuredWidth, binding.root.measuredHeight) + val canvasForScale = Canvas(bitmapForScale) + binding.root.draw(canvasForScale) + snapshotter.record(bitmapForScale, "SeekBar", "ScaleThumbDrawable") + LottieCompositionCache.getInstance().clear() bitmapPool.release(bitmap) + bitmapPool.release(bitmapForScale) } -} \ No newline at end of file +}