Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Migrate to CMP 1.7.0 #590

Merged
merged 1 commit into from
Oct 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
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