Skip to content

Commit

Permalink
Apply left/top bounds before scaling (#2565)
Browse files Browse the repository at this point in the history
  • Loading branch information
qhyuan authored Oct 27, 2024
1 parent d1bf9ed commit 3f4e535
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
2 changes: 1 addition & 1 deletion lottie/src/main/java/com/airbnb/lottie/LottieDrawable.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
}

0 comments on commit 3f4e535

Please sign in to comment.