From dc7b172b90fb9050d96a061e413ca70ec212f98a Mon Sep 17 00:00:00 2001 From: Chris Banes Date: Sat, 2 Nov 2024 14:38:38 +0000 Subject: [PATCH] Remove LayoutAwareModifierNode and onPlaced again (#383) It was added again in #372, to fix some drawing issues. However it has led to some performance issues. I've found the underlying issue from the previous code, therefore this can be disabled again. --- haze/api/api.txt | 4 +-- .../dev/chrisbanes/haze/HazeChildNode.kt | 25 +++---------------- .../kotlin/dev/chrisbanes/haze/HazeNode.kt | 18 +------------ 3 files changed, 7 insertions(+), 40 deletions(-) diff --git a/haze/api/api.txt b/haze/api/api.txt index 6d29f9f..ad68b5f 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.LayoutAwareModifierNode 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.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 androidx.compose.ui.node.LayoutAwareModifierNode { + @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 { 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/commonMain/kotlin/dev/chrisbanes/haze/HazeChildNode.kt b/haze/src/commonMain/kotlin/dev/chrisbanes/haze/HazeChildNode.kt index 3ea70b3..2740acf 100644 --- a/haze/src/commonMain/kotlin/dev/chrisbanes/haze/HazeChildNode.kt +++ b/haze/src/commonMain/kotlin/dev/chrisbanes/haze/HazeChildNode.kt @@ -9,6 +9,7 @@ import androidx.compose.ui.Modifier import androidx.compose.ui.geometry.Offset import androidx.compose.ui.geometry.Size import androidx.compose.ui.geometry.isSpecified +import androidx.compose.ui.geometry.takeOrElse import androidx.compose.ui.geometry.toRect import androidx.compose.ui.graphics.Brush import androidx.compose.ui.graphics.Color @@ -28,7 +29,6 @@ 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 @@ -54,7 +54,6 @@ class HazeChildNode( var block: (HazeChildScope.() -> Unit)? = null, ) : Modifier.Node(), CompositionLocalConsumerModifierNode, - LayoutAwareModifierNode, GlobalPositionAwareModifierNode, ObserverModifierNode, DrawModifierNode, @@ -219,30 +218,14 @@ class HazeChildNode( } override fun onGloballyPositioned(coordinates: LayoutCoordinates) { - 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" + "positionInWindow=${coordinates.positionInWindow()}" } - } - private fun onPositioned(coordinates: LayoutCoordinates) { positionInContent = coordinates.positionInWindow() + - calculateWindowOffset() - state.positionOnScreen + calculateWindowOffset() - state.positionOnScreen.takeOrElse { Offset.Zero } + size = coordinates.size.toSize() val blurRadiusPx = with(currentValueOf(LocalDensity)) { diff --git a/haze/src/commonMain/kotlin/dev/chrisbanes/haze/HazeNode.kt b/haze/src/commonMain/kotlin/dev/chrisbanes/haze/HazeNode.kt index 872cbf5..09dcc5a 100644 --- a/haze/src/commonMain/kotlin/dev/chrisbanes/haze/HazeNode.kt +++ b/haze/src/commonMain/kotlin/dev/chrisbanes/haze/HazeNode.kt @@ -13,7 +13,6 @@ 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 @@ -34,30 +33,15 @@ class HazeNode( ) : Modifier.Node(), CompositionLocalConsumerModifierNode, GlobalPositionAwareModifierNode, - LayoutAwareModifierNode, DrawModifierNode { override fun onGloballyPositioned(coordinates: LayoutCoordinates) { - 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}" + "content positionOnScreens=${state.positionOnScreen}" } - } - private fun onPositioned(coordinates: LayoutCoordinates) { state.positionOnScreen = coordinates.positionInWindow() + calculateWindowOffset() }