Skip to content

Commit

Permalink
Remove onPlaced again
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisbanes committed Nov 2, 2024
1 parent 4b7bc4b commit 23a2f49
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 38 deletions.
25 changes: 4 additions & 21 deletions haze/src/commonMain/kotlin/dev/chrisbanes/haze/HazeChildNode.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -54,7 +54,6 @@ class HazeChildNode(
var block: (HazeChildScope.() -> Unit)? = null,
) : Modifier.Node(),
CompositionLocalConsumerModifierNode,
LayoutAwareModifierNode,
GlobalPositionAwareModifierNode,
ObserverModifierNode,
DrawModifierNode,
Expand Down Expand Up @@ -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)) {
Expand Down
18 changes: 1 addition & 17 deletions haze/src/commonMain/kotlin/dev/chrisbanes/haze/HazeNode.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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()
}

Expand Down

0 comments on commit 23a2f49

Please sign in to comment.