Zoltan Demant
12/13/2021, 9:43 AMModifier.onSizeChanged
(in other words, without causing an additional recomposition for the entire screen)? Is this even possible? ๐คท๐ฝโโ๏ธFilip Wiesner
12/13/2021, 9:55 AMScaffold
implementation. It uses SubcomposeLayout
for this.Zoltan Demant
12/13/2021, 9:55 AMZoltan Demant
12/13/2021, 10:23 AMFilip Wiesner
12/13/2021, 10:32 AMColton Idle
12/13/2021, 4:18 PMZoltan Demant
12/13/2021, 6:36 PMSubcomposeLayout { constraints ->
val maxWidth = constraints.maxWidth
val maxHeight = constraints.maxHeight
val looseConstraints = constraints.copy(
minWidth = 0,
minHeight = 0
)
layout(
width = maxWidth,
height = maxHeight,
placementBlock = {
val actionPlaceables = subcompose(
slotId = Action,
content = action
).fastMap { measurable ->
measurable.measure(looseConstraints)
}
val tallestAction = actionPlaceables.fastMaxBy(Placeable::height)
val actionHeight = tallestAction?.height ?: 0
val bodyPlaceables = subcompose(
slotId = Body,
content = {
val innerPadding = remember(
key1 = originalPadding,
key2 = actionHeight
) {
val extraBottomPadding = if (actionHeight > 0) {
actionHeight.toDp() + KeylineSmall * 2
} else {
Zero
}
PaddingValues(
start = originalPadding.calculateStartPadding(layoutDirection),
top = originalPadding.calculateTopPadding(),
end = originalPadding.calculateEndPadding(layoutDirection),
bottom = originalPadding.calculateBottomPadding() + extraBottomPadding
)
}
content(innerPadding)
}
).fastMap { measurable ->
measurable.measure(looseConstraints)
}
bodyPlaceables.fastForEach { placeable ->
placeable.place(
x = 0,
y = 0
)
}
actionPlaceables.fastForEach { placeable ->
placeable.place(
x = 0,
y = maxHeight - actionHeight
)
}
}
)
}
Zoltan Demant
12/14/2021, 12:45 PMScaffold
, but more so with my own implementation for some reason that I dont understand.Filip Wiesner
12/14/2021, 12:49 PMremeasure
๐Filip Wiesner
12/14/2021, 12:50 PM