diff --git a/haze/api/api.txt b/haze/api/api.txt index ad68b5fc..6d29f9f6 100644 --- a/haze/api/api.txt +++ b/haze/api/api.txt @@ -9,7 +9,7 @@ package dev.chrisbanes.haze { method @androidx.compose.runtime.Stable public static androidx.compose.ui.Modifier hazeChild(androidx.compose.ui.Modifier, dev.chrisbanes.haze.HazeState state, optional dev.chrisbanes.haze.HazeStyle style, optional kotlin.jvm.functions.Function1? block); } - @dev.chrisbanes.haze.ExperimentalHazeApi public final class HazeChildNode extends androidx.compose.ui.Modifier.Node implements androidx.compose.ui.node.CompositionLocalConsumerModifierNode androidx.compose.ui.node.DrawModifierNode androidx.compose.ui.node.GlobalPositionAwareModifierNode dev.chrisbanes.haze.HazeChildScope androidx.compose.ui.node.ObserverModifierNode { + @dev.chrisbanes.haze.ExperimentalHazeApi public final class HazeChildNode extends androidx.compose.ui.Modifier.Node implements androidx.compose.ui.node.CompositionLocalConsumerModifierNode androidx.compose.ui.node.DrawModifierNode androidx.compose.ui.node.GlobalPositionAwareModifierNode dev.chrisbanes.haze.HazeChildScope androidx.compose.ui.node.LayoutAwareModifierNode androidx.compose.ui.node.ObserverModifierNode { ctor public HazeChildNode(dev.chrisbanes.haze.HazeState state, optional dev.chrisbanes.haze.HazeStyle style, optional kotlin.jvm.functions.Function1? block); method public void draw(androidx.compose.ui.graphics.drawscope.ContentDrawScope); method public float getAlpha(); @@ -96,7 +96,7 @@ package dev.chrisbanes.haze { method @androidx.compose.runtime.Stable public static androidx.compose.ui.Modifier haze(androidx.compose.ui.Modifier, dev.chrisbanes.haze.HazeState state); } - @dev.chrisbanes.haze.ExperimentalHazeApi public final class HazeNode extends androidx.compose.ui.Modifier.Node implements androidx.compose.ui.node.CompositionLocalConsumerModifierNode androidx.compose.ui.node.DrawModifierNode androidx.compose.ui.node.GlobalPositionAwareModifierNode { + @dev.chrisbanes.haze.ExperimentalHazeApi public final class HazeNode extends androidx.compose.ui.Modifier.Node implements androidx.compose.ui.node.CompositionLocalConsumerModifierNode androidx.compose.ui.node.DrawModifierNode androidx.compose.ui.node.GlobalPositionAwareModifierNode androidx.compose.ui.node.LayoutAwareModifierNode { ctor public HazeNode(dev.chrisbanes.haze.HazeState state); method public void draw(androidx.compose.ui.graphics.drawscope.ContentDrawScope); method public dev.chrisbanes.haze.HazeState getState(); diff --git a/haze/src/androidMain/kotlin/dev/chrisbanes/haze/Log.android.kt b/haze/src/androidMain/kotlin/dev/chrisbanes/haze/Log.android.kt index 0f89c832..1c307290 100644 --- a/haze/src/androidMain/kotlin/dev/chrisbanes/haze/Log.android.kt +++ b/haze/src/androidMain/kotlin/dev/chrisbanes/haze/Log.android.kt @@ -4,9 +4,12 @@ package dev.chrisbanes.haze import android.util.Log +import androidx.compose.runtime.snapshots.Snapshot internal actual fun log(tag: String, message: () -> String) { if (LOG_ENABLED) { - Log.d(tag, message()) + Snapshot.withoutReadObservation { + Log.d(tag, message()) + } } } diff --git a/haze/src/androidMain/kotlin/dev/chrisbanes/haze/RenderEffect.android.kt b/haze/src/androidMain/kotlin/dev/chrisbanes/haze/RenderEffect.android.kt index f40f4243..39f2105c 100644 --- a/haze/src/androidMain/kotlin/dev/chrisbanes/haze/RenderEffect.android.kt +++ b/haze/src/androidMain/kotlin/dev/chrisbanes/haze/RenderEffect.android.kt @@ -46,7 +46,7 @@ internal actual fun HazeChildNode.createRenderEffect( ): RenderEffect? { if (Build.VERSION.SDK_INT < 31) return null - log("HazeChildNode") { + log(HazeChildNode.TAG) { "createRenderEffect. " + "blurRadiusPx=$blurRadiusPx, " + "noiseFactor=$noiseFactor, " + diff --git a/haze/src/commonMain/kotlin/dev/chrisbanes/haze/HazeChildNode.kt b/haze/src/commonMain/kotlin/dev/chrisbanes/haze/HazeChildNode.kt index 62c73b6b..7c135038 100644 --- a/haze/src/commonMain/kotlin/dev/chrisbanes/haze/HazeChildNode.kt +++ b/haze/src/commonMain/kotlin/dev/chrisbanes/haze/HazeChildNode.kt @@ -28,6 +28,7 @@ import androidx.compose.ui.layout.positionInWindow import androidx.compose.ui.node.CompositionLocalConsumerModifierNode import androidx.compose.ui.node.DrawModifierNode import androidx.compose.ui.node.GlobalPositionAwareModifierNode +import androidx.compose.ui.node.LayoutAwareModifierNode import androidx.compose.ui.node.ObserverModifierNode import androidx.compose.ui.node.currentValueOf import androidx.compose.ui.node.invalidateDraw @@ -53,6 +54,7 @@ class HazeChildNode( var block: (HazeChildScope.() -> Unit)? = null, ) : Modifier.Node(), CompositionLocalConsumerModifierNode, + LayoutAwareModifierNode, GlobalPositionAwareModifierNode, ObserverModifierNode, DrawModifierNode, @@ -217,7 +219,28 @@ class HazeChildNode( } override fun onGloballyPositioned(coordinates: LayoutCoordinates) { - log(TAG) { "onGloballyPositioned: positionInWindow=${coordinates.positionInWindow()}" } + onPlaced(coordinates) + + log(TAG) { + "onGloballyPositioned: " + + "positionInWindow=${coordinates.positionInWindow()}, " + + "positionInContent=$positionInContent, " + + "size=$size" + } + } + + override fun onPlaced(coordinates: LayoutCoordinates) { + onPositioned(coordinates) + + log(TAG) { + "onPlaced: " + + "positionInWindow=${coordinates.positionInWindow()}, " + + "positionInContent=$positionInContent, " + + "size=$size" + } + } + + private fun onPositioned(coordinates: LayoutCoordinates) { positionInContent = coordinates.positionInWindow() + calculateWindowOffset() - state.positionOnScreen size = coordinates.size.toSize() diff --git a/haze/src/commonMain/kotlin/dev/chrisbanes/haze/HazeNode.kt b/haze/src/commonMain/kotlin/dev/chrisbanes/haze/HazeNode.kt index 0186fabb..872cbf5e 100644 --- a/haze/src/commonMain/kotlin/dev/chrisbanes/haze/HazeNode.kt +++ b/haze/src/commonMain/kotlin/dev/chrisbanes/haze/HazeNode.kt @@ -13,6 +13,7 @@ import androidx.compose.ui.layout.positionInWindow import androidx.compose.ui.node.CompositionLocalConsumerModifierNode import androidx.compose.ui.node.DrawModifierNode import androidx.compose.ui.node.GlobalPositionAwareModifierNode +import androidx.compose.ui.node.LayoutAwareModifierNode import androidx.compose.ui.node.currentValueOf import androidx.compose.ui.platform.LocalGraphicsContext import androidx.compose.ui.unit.Dp @@ -33,12 +34,30 @@ class HazeNode( ) : Modifier.Node(), CompositionLocalConsumerModifierNode, GlobalPositionAwareModifierNode, + LayoutAwareModifierNode, DrawModifierNode { override fun onGloballyPositioned(coordinates: LayoutCoordinates) { - log("HazeNode") { - "onPlaced: positionInWindow=${coordinates.positionInWindow()}" + onPlaced(coordinates) + + log(TAG) { + "onGloballyPositioned: " + + "positionInWindow=${coordinates.positionInWindow()}, " + + "positionInContent=${state.positionOnScreen}" } + } + + override fun onPlaced(coordinates: LayoutCoordinates) { + onPositioned(coordinates) + + log(TAG) { + "onPlaced: " + + "positionInWindow=${coordinates.positionInWindow()}, " + + "positionInContent=${state.positionOnScreen}" + } + } + + private fun onPositioned(coordinates: LayoutCoordinates) { state.positionOnScreen = coordinates.positionInWindow() + calculateWindowOffset() } diff --git a/haze/src/iosMain/kotlin/dev/chrisbanes/haze/Log.ios.kt b/haze/src/iosMain/kotlin/dev/chrisbanes/haze/Log.ios.kt index 945525be..da4e33d8 100644 --- a/haze/src/iosMain/kotlin/dev/chrisbanes/haze/Log.ios.kt +++ b/haze/src/iosMain/kotlin/dev/chrisbanes/haze/Log.ios.kt @@ -3,10 +3,13 @@ package dev.chrisbanes.haze +import androidx.compose.runtime.snapshots.Snapshot import platform.Foundation.NSLog internal actual fun log(tag: String, message: () -> String) { if (LOG_ENABLED) { - NSLog("[%s] %s", tag, message()) + Snapshot.withoutReadObservation { + NSLog("[%s] %s", tag, message()) + } } } diff --git a/haze/src/jsMain/kotlin/dev/chrisbanes/haze/Log.js.kt b/haze/src/jsMain/kotlin/dev/chrisbanes/haze/Log.js.kt index 64df5e87..280a5f50 100644 --- a/haze/src/jsMain/kotlin/dev/chrisbanes/haze/Log.js.kt +++ b/haze/src/jsMain/kotlin/dev/chrisbanes/haze/Log.js.kt @@ -3,8 +3,12 @@ package dev.chrisbanes.haze +import androidx.compose.runtime.snapshots.Snapshot + internal actual fun log(tag: String, message: () -> String) { if (LOG_ENABLED) { - println("[$tag] ${message()}") + Snapshot.withoutReadObservation { + println("[$tag] ${message()}") + } } } diff --git a/haze/src/skikoMain/kotlin/dev/chrisbanes/haze/RenderEffect.skiko.kt b/haze/src/skikoMain/kotlin/dev/chrisbanes/haze/RenderEffect.skiko.kt index 2c79557c..697c672a 100644 --- a/haze/src/skikoMain/kotlin/dev/chrisbanes/haze/RenderEffect.skiko.kt +++ b/haze/src/skikoMain/kotlin/dev/chrisbanes/haze/RenderEffect.skiko.kt @@ -36,7 +36,7 @@ internal actual fun HazeChildNode.createRenderEffect( mask: Brush?, progressive: Brush?, ): RenderEffect? { - log("HazeChildNode") { + log(HazeChildNode.TAG) { "createRenderEffect. " + "blurRadiusPx=$blurRadiusPx, " + "noiseFactor=$noiseFactor, " + diff --git a/haze/src/wasmJsMain/kotlin/dev/chrisbanes/haze/Log.wasmJs.kt b/haze/src/wasmJsMain/kotlin/dev/chrisbanes/haze/Log.wasmJs.kt index 64df5e87..280a5f50 100644 --- a/haze/src/wasmJsMain/kotlin/dev/chrisbanes/haze/Log.wasmJs.kt +++ b/haze/src/wasmJsMain/kotlin/dev/chrisbanes/haze/Log.wasmJs.kt @@ -3,8 +3,12 @@ package dev.chrisbanes.haze +import androidx.compose.runtime.snapshots.Snapshot + internal actual fun log(tag: String, message: () -> String) { if (LOG_ENABLED) { - println("[$tag] ${message()}") + Snapshot.withoutReadObservation { + println("[$tag] ${message()}") + } } }