Skip to content

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
alexzhirkevich committed Nov 11, 2024
1 parent 019883b commit 2856117
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 53 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -147,46 +147,45 @@ internal abstract class BaseLayer : Layer {
parentAlpha: Float,
state: AnimationState,
) {
try {
state.onLayer(this) {
state.onLayer(this) {

if (!isActive(state))
return@onLayer
if (!isActive(state))
return@onLayer

buildParentLayerListIfNeeded()
buildParentLayerListIfNeeded()

matrix.fastSetFrom(parentMatrix)
parentLayers?.fastForEachReversed {
matrix.preConcat(it.transform.matrix(state))
}
matrix.fastSetFrom(parentMatrix)
parentLayers?.fastForEachReversed {
matrix.preConcat(it.transform.matrix(state))
}

var alpha = 1f
var alpha = 1f

transform.opacity.interpolatedNorm(state).let {
alpha = (alpha * it).coerceIn(0f, 1f)
}
transform.opacity.interpolatedNorm(state).let {
alpha = (alpha * it).coerceIn(0f, 1f)
}

alpha = (alpha * parentAlpha.coerceIn(0f, 1f))
alpha = (alpha * parentAlpha.coerceIn(0f, 1f))

if (matteLayer == null && !hasMasks() && blendMode == LottieBlendMode.Normal) {
matrix.preConcat(transform.matrix(state))
drawLayer(drawScope, matrix, alpha, state)
return@onLayer
}
if (matteLayer == null && !hasMasks() && blendMode == LottieBlendMode.Normal) {
matrix.preConcat(transform.matrix(state))
drawLayer(drawScope, matrix, alpha, state)
return@onLayer
}

rect.set(0f,0f,0f,0f)
getBounds(drawScope, matrix, false, state, rect)
rect.set(0f, 0f, 0f, 0f)
getBounds(drawScope, matrix, false, state, rect)

intersectBoundsWithMatte(drawScope, rect, parentMatrix, state)
intersectBoundsWithMatte(drawScope, rect, parentMatrix, state)

matrix.preConcat(transform.matrix(state))
intersectBoundsWithMask(rect, matrix, state)
matrix.preConcat(transform.matrix(state))
intersectBoundsWithMask(rect, matrix, state)

// Intersect the mask and matte rect with the canvas bounds.
// If the canvas has a transform, then we need to transform its bounds by its matrix
// so that we know the coordinate space that the canvas is showing.
// Intersect the mask and matte rect with the canvas bounds.
// If the canvas has a transform, then we need to transform its bounds by its matrix
// so that we know the coordinate space that the canvas is showing.
// canvasBounds.set(0f, 0f, drawScope.size.width, drawScope.size.height)
drawScope.drawIntoCanvas { canvas ->
drawScope.drawIntoCanvas { canvas ->

// canvas.getMatrix(canvasMatrix)
// if (!canvasMatrix.isIdentity()) {
Expand All @@ -196,30 +195,30 @@ internal abstract class BaseLayer : Layer {

// rect.intersectOrReset(canvasBounds)
//
// Ensure that what we are drawing is >=1px of width and height.
// On older devices, drawing to an offscreen buffer of <1px would draw back as a black bar.
// https://github.com/airbnb/lottie-android/issues/1625
if (rect.width >= 1f && rect.height >= 1f) {
contentPaint.alpha = 1f
canvas.saveLayer(rect, contentPaint)

clearCanvas(canvas)
drawLayer(drawScope, matrix, alpha, state)

if (hasMasks()) {
applyMasks(canvas, matrix, state)
}
// Ensure that what we are drawing is >=1px of width and height.
// On older devices, drawing to an offscreen buffer of <1px would draw back as a black bar.
// https://github.com/airbnb/lottie-android/issues/1625
if (rect.width >= 1f && rect.height >= 1f) {
contentPaint.alpha = 1f
canvas.saveLayer(rect, contentPaint)

clearCanvas(canvas)
drawLayer(drawScope, matrix, alpha, state)

matteLayer?.let {
canvas.saveLayer(rect, mattePaint, SAVE_FLAGS)
clearCanvas(canvas)
it.draw(drawScope, parentMatrix, alpha, state)
canvas.restore()
}
if (hasMasks()) {
applyMasks(canvas, matrix, state)
}

matteLayer?.let {
canvas.saveLayer(rect, mattePaint, SAVE_FLAGS)
clearCanvas(canvas)
it.draw(drawScope, parentMatrix, alpha, state)
canvas.restore()
}

canvas.restore()
}

// val outlineMasksAndMattesPaint = Paint().apply {
// style = PaintingStyle.Stroke
// strokeWidth = 4f
Expand All @@ -229,10 +228,7 @@ internal abstract class BaseLayer : Layer {
// outlineMasksAndMattesPaint.style = PaintingStyle.Fill
// outlineMasksAndMattesPaint.color = Color(0x50EBEBEB)
// canvas.drawRect(rect, outlineMasksAndMattesPaint)
}
}
} catch (t: Throwable) {
Compottie.logger?.error("Lottie crashed in draw :(", t)
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import gradle.kotlin.dsl.accessors._2502cef48cff830615fe1c6d6ab5e104.ext
import java.io.FileInputStream
import java.util.Properties

Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ android.minSdk=21
#MPP
kotlin.mpp.enableCInteropCommonization=true
kotlin.mpp.androidSourceSetLayoutVersion=2
version=2.0.0-rc01
version=2.0.0-rc02
group=io.github.alexzhirkevich


Expand Down
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#Mon Mar 13 11:02:04 MSK 2023
distributionBase=GRADLE_USER_HOME
distributionUrl=https\://services.gradle.org/distributions/gradle-8.0-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.7-bin.zip
distributionPath=wrapper/dists
zipStorePath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME

0 comments on commit 2856117

Please sign in to comment.