From b9a1e1a5e6a07174e37d3e17d4a7f94755e050a8 Mon Sep 17 00:00:00 2001 From: Alex Vanyo Date: Tue, 16 Jan 2024 11:05:25 -0800 Subject: [PATCH] Replace onSizeChanged with layout --- .../com/example/listdetailcompose/ui/ListDetail.kt | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/CanonicalLayouts/list-detail-compose/app/src/main/java/com/example/listdetailcompose/ui/ListDetail.kt b/CanonicalLayouts/list-detail-compose/app/src/main/java/com/example/listdetailcompose/ui/ListDetail.kt index c9029f1a1..e65636e73 100644 --- a/CanonicalLayouts/list-detail-compose/app/src/main/java/com/example/listdetailcompose/ui/ListDetail.kt +++ b/CanonicalLayouts/list-detail-compose/app/src/main/java/com/example/listdetailcompose/ui/ListDetail.kt @@ -245,16 +245,22 @@ fun ListDetail( val minDetailPaneWidth = 300.dp Box( - modifier = modifier.onSizeChanged { + modifier = modifier.layout { measurable, constraints -> + val placeable = measurable.measure(constraints) + anchoredDraggableState.updateAnchors( newAnchors = DraggableAnchors { - ExpandablePaneState.ListOnly at it.width.toFloat() - ExpandablePaneState.ListAndDetail at it.width.toFloat() / 2f + ExpandablePaneState.ListOnly at placeable.width.toFloat() + ExpandablePaneState.ListAndDetail at placeable.width.toFloat() / 2f ExpandablePaneState.DetailOnly at 0f }, // Keep the current target, even if resizing causes the offset to be closer to a different one newTarget = anchoredDraggableState.targetValue ) + + layout(placeable.width, placeable.height) { + placeable.placeRelative(0, 0) + } } ) { if (showList && showDetail) {