From d4a4cb37c73712232c5e6acd64dadd5299ec81ae Mon Sep 17 00:00:00 2001 From: skydoves Date: Thu, 24 Oct 2024 11:23:37 +0900 Subject: [PATCH] Migrate to CMP 1.7.0 --- .../placeholder/shimmer/FlashShimmer.kt | 52 +++++++++---------- .../placeholder/shimmer/ShimmerPlugin.kt | 2 +- 2 files changed, 25 insertions(+), 29 deletions(-) diff --git a/landscapist-placeholder/src/commonMain/kotlin/com/skydoves/landscapist/placeholder/shimmer/FlashShimmer.kt b/landscapist-placeholder/src/commonMain/kotlin/com/skydoves/landscapist/placeholder/shimmer/FlashShimmer.kt index 620501e5..c734a335 100644 --- a/landscapist-placeholder/src/commonMain/kotlin/com/skydoves/landscapist/placeholder/shimmer/FlashShimmer.kt +++ b/landscapist-placeholder/src/commonMain/kotlin/com/skydoves/landscapist/placeholder/shimmer/FlashShimmer.kt @@ -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 @@ -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() } } } diff --git a/landscapist-placeholder/src/commonMain/kotlin/com/skydoves/landscapist/placeholder/shimmer/ShimmerPlugin.kt b/landscapist-placeholder/src/commonMain/kotlin/com/skydoves/landscapist/placeholder/shimmer/ShimmerPlugin.kt index 474a60d9..d852963a 100644 --- a/landscapist-placeholder/src/commonMain/kotlin/com/skydoves/landscapist/placeholder/shimmer/ShimmerPlugin.kt +++ b/landscapist-placeholder/src/commonMain/kotlin/com/skydoves/landscapist/placeholder/shimmer/ShimmerPlugin.kt @@ -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(