diff --git a/core/ui/src/main/java/org/signal/core/ui/compose/keyboard/KeyboardSheetScaffold.kt b/core/ui/src/main/java/org/signal/core/ui/compose/keyboard/KeyboardSheetScaffold.kt index 0dbc8f29e0..f983cc2745 100644 --- a/core/ui/src/main/java/org/signal/core/ui/compose/keyboard/KeyboardSheetScaffold.kt +++ b/core/ui/src/main/java/org/signal/core/ui/compose/keyboard/KeyboardSheetScaffold.kt @@ -414,13 +414,17 @@ fun KeyboardSheetScaffold( } } - // Picks up drags as well as requests, so the controller reports where the sheet is heading. + // Picks up drags as well as requests, so the controller reports where the sheet is heading. The heights are read + // through rememberUpdatedState because this effect outlives the composition that launched it, which ran before any + // keyboard (and so any expandable height) was known. + val currentSheetHeightPx by rememberUpdatedState(sheetHeightPx) + val currentHeightPx by rememberUpdatedState(heightPx) LaunchedEffect(sheetState) { - snapshotFlow { sheetState.targetValue == SheetAnchor.Expanded } + snapshotFlow { (sheetState.targetValue == SheetAnchor.Expanded) to (currentSheetHeightPx - currentHeightPx) } .distinctUntilChanged() - .collect { expanded -> + .collect { (expanded, overlapPx) -> controller.isExpanded = expanded - controller.expandedOverlapPx = if (expanded) sheetHeightPx - heightPx else 0 + controller.expandedOverlapPx = if (expanded) overlapPx else 0 } }