From edf8ea9851730ff7b7194d3ea7edca5b343af3de Mon Sep 17 00:00:00 2001 From: xfy Date: Thu, 14 May 2026 15:27:26 +0800 Subject: [PATCH] Fix first-frame flicker by deferring row height until measured When rowHeightPx is 0 (first frame), use aspectRatio-based natural height instead of collapsing to 0.dp, preventing a visible flash. Co-Authored-By: Claude Opus 4.7 --- .../plus/rua/project/ui/CalendarMonthPage.kt | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/shared/src/commonMain/kotlin/plus/rua/project/ui/CalendarMonthPage.kt b/shared/src/commonMain/kotlin/plus/rua/project/ui/CalendarMonthPage.kt index a895d51..6b5c6d6 100644 --- a/shared/src/commonMain/kotlin/plus/rua/project/ui/CalendarMonthPage.kt +++ b/shared/src/commonMain/kotlin/plus/rua/project/ui/CalendarMonthPage.kt @@ -53,6 +53,7 @@ fun CalendarMonthPage( } var rowHeightPx by remember { mutableIntStateOf(0) } + val rowMeasured = rowHeightPx > 0 Column(modifier = modifier) { weeks.forEachIndexed { weekIndex, week -> @@ -64,19 +65,27 @@ fun CalendarMonthPage( else -> 1f } - val rowHeightDp = if (rowHeightPx > 0 && rowScale > 0.01f) { + val rowHeightDp = if (rowMeasured && rowScale > 0.01f) { with(density) { (rowHeightPx * rowScale).toDp() } + } else if (!rowMeasured) { + // First frame: let aspectRatio determine height naturally + null } else { 0.dp } - if (rowHeightDp > 0.dp) { + val shouldShow = rowHeightDp == null || rowHeightDp > 0.dp + + if (shouldShow) { Row( modifier = Modifier .fillMaxWidth() - .height(rowHeightDp) + .then( + if (rowHeightDp != null) Modifier.height(rowHeightDp) + else Modifier + ) .onSizeChanged { size -> - if (weekIndex == 0 && size.height > 0) { + if (size.height > 0 && !rowMeasured) { rowHeightPx = size.height } }