Skip to content

Commit

Permalink
Merge pull request #590 from skydoves/cmp/1.7.0
Browse files Browse the repository at this point in the history
Migrate to CMP 1.7.0
  • Loading branch information
skydoves authored Oct 24, 2024
2 parents 20c8ca4 + d4a4cb3 commit 5e6f869
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import androidx.compose.animation.core.infiniteRepeatable
import androidx.compose.animation.core.tween
import androidx.compose.foundation.Canvas
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.remember
Expand Down Expand Up @@ -94,42 +95,37 @@ public fun Shimmer(
min((1f + intensity + dropOff) / 2f, 1f),
)

Box(modifier) {
Canvas(Modifier.matchParentSize()) {
Box(modifier = modifier) {
Canvas(modifier = Modifier.fillMaxSize()) {
val gradientFrom = Offset(-size.width / 2, 0f)
val gradientTo = -gradientFrom
val tiltTan = tan(tilt.toDouble() * DEGREES_TO_RADIANS)
val width = shimmerWidthPx ?: (size.width + tiltTan * size.height).toFloat()

try {
val dx = offset(-width, width * 1.5f, animatedProgress.value)
val shaderMatrix = Matrix().apply {
reset()
rotateX(size.width / 2f)
rotateY(size.height / 2f)
rotateZ(-tilt)
translate(dx, 0f)
}
val dx = offset(-width, width * 1.5f, animatedProgress.value)
val shaderMatrix = Matrix().apply {
reset()
rotateX(size.width / 2f)
rotateY(size.height / 2f)
rotateZ(-tilt)
translate(dx, 0f)
}

paint.shader = LinearGradientShader(
from = shaderMatrix.map(gradientFrom),
to = shaderMatrix.map(gradientTo),
colors = shaderColors,
colorStops = shaderColorStops,
)
paint.shader = LinearGradientShader(
from = shaderMatrix.map(gradientFrom),
to = shaderMatrix.map(gradientTo),
colors = shaderColors,
colorStops = shaderColorStops,
)

val drawArea = Rect(Offset(0f, 0f), size)
drawIntoCanvas { canvas ->
canvas.withSaveLayer(
bounds = drawArea,
paint = emptyPaint,
) {
canvas.drawRect(drawArea, paint)
}
val drawArea = Rect(Offset(0f, 0f), size)
drawIntoCanvas { canvas ->
canvas.withSaveLayer(
bounds = drawArea,
paint = emptyPaint,
) {
canvas.drawRect(drawArea, paint)
}
} finally {
// resets the paint and release to the pool.
paint.asFrameworkPaint().reset()
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import com.skydoves.landscapist.plugins.ImagePlugin
/**
* Shimmer params holds attributes of the [ShimmerContainer] composable.
*
* @property A representation of Shimmer to be used with [ShimmerPlugin].
* @property shimmer A representation of Shimmer to be used with [ShimmerPlugin].
*/
@Immutable
public data class ShimmerPlugin(
Expand Down

0 comments on commit 5e6f869

Please sign in to comment.