Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Fix transparent background rendering with MULTIPLY Blend mode on Andr…
…oid 34+

The workaround in #2519 for Multiply blend modes doesn't work on Android 34+. This changes the implementation to use `BlemdModeCompat.MULTIPLY` on Android versions Q (29) and higher where it is supported, while retaining the workaround for older versions.

Fixes #2636
and #2593
  • Loading branch information
allenchen1154 committed Sep 13, 2025
commit f119d545f4ec4f46df225cfd6bfe4afb84cdec70
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,15 @@ public BlendModeCompat toNativeBlendMode() {
// any alpha blending. It just does a component-wise multiplication
// of the colors.
//
// For proper results on all platforms, we will map the MULTIPLY
// For proper results on Android versions < Q, we will map the MULTIPLY
// blend mode to MODULATE, and then do a slight adjustment to
// how we render such layers to still achieve the correct result.
// See BaseLayer.draw().
return BlendModeCompat.MODULATE;
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.Q) {
return BlendModeCompat.MULTIPLY;
} else {
return BlendModeCompat.MODULATE;
}
case SCREEN:
return BlendModeCompat.SCREEN;
case OVERLAY:
Expand Down
26 changes: 14 additions & 12 deletions lottie/src/main/java/com/airbnb/lottie/model/layer/BaseLayer.java
Original file line number Diff line number Diff line change
Expand Up @@ -322,19 +322,21 @@ public void draw(Canvas canvas, Matrix parentMatrix, int parentAlpha, @Nullable
if (getBlendMode() != LBlendMode.MULTIPLY) {
clearCanvas(canvas);
} else {
// Due to the difference between PorterDuffMode.MULTIPLY (which we use for compatibility
// with Android < Q) and BlendMode.MULTIPLY (which is the correct, alpha-blended mode),
// we will alpha-blend the contents of this layer on top of a white background before
// we multiply it with the opaque substrate below (with canvas.restore()).
//
// Since white is the identity color for multiplication, this will behave as if we
// had correctly performed an alpha-blended multiply (such as BlendMode.MULTIPLY), but
// will work pre-Q as well.
if (solidWhitePaint == null) {
solidWhitePaint = new LPaint();
solidWhitePaint.setColor(0xffffffff);
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.Q) {
// Due to the difference between PorterDuffMode.MODULATE (which we use for compatibility
// with Android < Q) and BlendMode.MULTIPLY (which is the correct, alpha-blended mode),
// we will alpha-blend the contents of this layer on top of a white background before
// we multiply it with the opaque substrate below (with canvas.restore()).
//
// Since white is the identity color for multiplication, this will behave as if we
// had correctly performed an alpha-blended multiply (such as BlendMode.MULTIPLY), but
// will work pre-Q as well.
if (solidWhitePaint == null) {
solidWhitePaint = new LPaint();
solidWhitePaint.setColor(0xffffffff);
}
canvas.drawRect(rect.left - 1, rect.top - 1, rect.right + 1, rect.bottom + 1, solidWhitePaint);
}
canvas.drawRect(rect.left - 1, rect.top - 1, rect.right + 1, rect.bottom + 1, solidWhitePaint);
}

if (L.isTraceEnabled()) {
Expand Down
Loading
Loading