From ad1869c214d4cb10fb68833373afbefe1123f64b 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 c9029f1a..e65636e7 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) {