Skip to content

Commit

Permalink
Remove LayoutModifierNode
Browse files Browse the repository at this point in the history
  • Loading branch information
skydoves committed Dec 30, 2024
1 parent 20b7d88 commit 3cf2222
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 19 deletions.
4 changes: 2 additions & 2 deletions app/src/main/kotlin/com/skydoves/cloudydemo/Main.kt
Original file line number Diff line number Diff line change
Expand Up @@ -75,12 +75,12 @@ fun Main() {
GlideImage(
modifier = Modifier
.size(400.dp)
.cloudy(radius = radius),
.cloudy(radius = 30),
previewPlaceholder = painterResource(id = R.drawable.poster),
imageModel = { poster.image }
)

Column(modifier = Modifier.cloudy(radius = radius)) {
Column(modifier = Modifier.cloudy(radius = 30)) {
Text(
modifier = Modifier
.fillMaxWidth()
Expand Down
20 changes: 3 additions & 17 deletions cloudy/src/main/kotlin/com/skydoves/cloudy/CloudyModifierNode.kt
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ package com.skydoves.cloudy

import android.graphics.Bitmap
import android.renderscript.RenderScript
import android.util.Log
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.blur
Expand All @@ -26,17 +27,11 @@ import androidx.compose.ui.graphics.drawscope.ContentDrawScope
import androidx.compose.ui.graphics.layer.GraphicsLayer
import androidx.compose.ui.graphics.layer.drawLayer
import androidx.compose.ui.graphics.rememberGraphicsLayer
import androidx.compose.ui.layout.Measurable
import androidx.compose.ui.layout.MeasureResult
import androidx.compose.ui.layout.MeasureScope
import androidx.compose.ui.node.DrawModifierNode
import androidx.compose.ui.node.LayoutModifierNode
import androidx.compose.ui.node.ModifierNodeElement
import androidx.compose.ui.platform.InspectorInfo
import androidx.compose.ui.platform.LocalInspectionMode
import androidx.compose.ui.unit.Constraints
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.offset
import com.skydoves.cloudy.internals.render.iterativeBlur
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
Expand Down Expand Up @@ -103,17 +98,7 @@ private class CloudyModifierNode(
val graphicsLayer: GraphicsLayer,
var radius: Int = 10,
private val onStateChanged: (CloudyState) -> Unit = {}
) : LayoutModifierNode, DrawModifierNode, Modifier.Node() {

override fun MeasureScope.measure(
measurable: Measurable,
constraints: Constraints
): MeasureResult {
val placeable = measurable.measure(constraints.offset())
return layout(placeable.width, placeable.height) {
placeable.placeRelative(0, 0)
}
}
) : DrawModifierNode, Modifier.Node() {

override fun ContentDrawScope.draw() {
// call record to capture the content in the graphics layer
Expand All @@ -140,6 +125,7 @@ private class CloudyModifierNode(

onStateChanged.invoke(CloudyState.Success(blurredBitmap))
} catch (e: Exception) {
Log.e("Test", "exception: $e")
onStateChanged.invoke(CloudyState.Error(e))
}
}
Expand Down

0 comments on commit 3cf2222

Please sign in to comment.