Alex
08/15/2024, 3:04 PMstickyHeader
is currently sticking?
Edit: I made a Modifier
myself, code in 🧵Alex
08/15/2024, 4:14 PM/**
* Will elevate the composable if it's sticking to the top of the parent.
* Used for drawing shadows on sticky headers when they are at the top.
*/
@Composable
fun Modifier.showShadowIfStickingToTop(
topElevation: Dp = 4.dp,
elevationTransitionLabel: String = "elevate-if-at-top-transition",
): Modifier {
var isAtTop by rememberSaveable { mutableStateOf(false) }
val elevationDp by animateDpAsState(
if (isAtTop) topElevation else 0.dp,
label = elevationTransitionLabel,
)
return onPlaced { layoutCoordinates ->
with(layoutCoordinates) {
val parentRootOffsetY =
(parentLayoutCoordinates?.localToRoot(Offset.Zero) ?: Offset.Zero).y
val ownRootOffset = localToRoot(Offset.Zero).y
val topOffset = ownRootOffset - parentRootOffsetY
isAtTop = topOffset == 0f
}
}.shadow(elevationDp)
}
Stylianos Gakis
08/16/2024, 3:25 PMcomposed {
right?
An extension on modifier also being a composable itself looks odd, never seen it before tbh.sindrenm
08/16/2024, 5:31 PM@Composable fun Modifier.foo()
is recommended now instead of using composed {}
.
https://developer.android.com/develop/ui/compose/custom-modifiers#create_a_custom_modifier_using_a_composable_modifier_factoryStylianos Gakis
08/19/2024, 3:13 PMsindrenm
08/19/2024, 3:36 PM@Composable fun Modifier.foo()
with composed {}
in the past, so it's been kind of a bit back and forth. But anytime! 😀Alex
08/20/2024, 7:17 AMsindrenm
08/20/2024, 8:40 AMModifier.Node
stuff when possible. 😅