Yaroslav Shuliak
04/03/2025, 10:32 AMYaroslav Shuliak
04/03/2025, 10:37 AM@Composable
fun letterPracticeWritingWordsBottomSheetHeight(
scaffoldCoordinates: SharedFlow<LayoutCoordinates?>,
expressionSectionCoordinates: SharedFlow<LayoutCoordinates?>
): State<Dp> {
val height = remember { mutableStateOf(DefaultHeight) }
val density = LocalDensity.current
val extraBottomSheetHeight = 0.dp// WindowInsets.navigationBars.getBottom(density).let { with(density) { it.toDp() } }
LaunchedEffect(Unit) {
val scaffoldBoundFlow = scaffoldCoordinates
.map { it?.takeIf { it.isAttached }?.boundsInWindow() }
val expressionSectionBoundsFlow = expressionSectionCoordinates
.map { it?.takeIf { it.isAttached }?.boundsInWindow() }
scaffoldBoundFlow.combine(expressionSectionBoundsFlow) { a, b -> a to b }
.map { (scaffold, expressions) ->
Logger.d("scaffold[$scaffold] expressions[$expressions]")
when {
scaffold == null || expressions == null -> DefaultHeight
else -> {
val maxHeight = with(density) {
scaffold.height.toDp().plus(extraBottomSheetHeight)
}
val bottomSheetHeight = scaffold.bottom
.minus(<http://expressions.top|expressions.top>)
.let { with(density) { it.toDp() } }
.plus(extraBottomSheetHeight)
.takeIf { it >= MinHeightThreshold }
?: maxHeight
bottomSheetHeight
}
}
}
.onEach { vocabSheetHeight ->
Logger.d("changing bottom sheet height to ${vocabSheetHeight.value}")
height.value = vocabSheetHeight
}
.launchIn(this)
}
return height
}