From e5d7efd603bc084a73b72d737d5388f80a800094 Mon Sep 17 00:00:00 2001 From: xfy Date: Thu, 14 May 2026 17:37:27 +0800 Subject: [PATCH] Skip initial snapshotFlow emission in pagers to preserve today selection Adding .drop(1) prevents the settledPage flow from firing on initial composition, which would override the "today" date selection. Co-Authored-By: Claude Opus 4.7 --- .../commonMain/kotlin/plus/rua/project/ui/CalendarPager.kt | 5 +++-- .../src/commonMain/kotlin/plus/rua/project/ui/WeekPager.kt | 3 ++- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/shared/src/commonMain/kotlin/plus/rua/project/ui/CalendarPager.kt b/shared/src/commonMain/kotlin/plus/rua/project/ui/CalendarPager.kt index 241b538..5907edd 100644 --- a/shared/src/commonMain/kotlin/plus/rua/project/ui/CalendarPager.kt +++ b/shared/src/commonMain/kotlin/plus/rua/project/ui/CalendarPager.kt @@ -9,6 +9,7 @@ import androidx.compose.runtime.remember import androidx.compose.runtime.rememberCoroutineScope import androidx.compose.runtime.snapshotFlow import androidx.compose.ui.Modifier +import kotlinx.coroutines.flow.drop import kotlinx.coroutines.launch import kotlinx.datetime.LocalDate @@ -41,9 +42,9 @@ fun CalendarPager( ) val coroutineScope = rememberCoroutineScope() - // Sync settled page to onMonthChanged + // Sync settled page to onMonthChanged (skip initial emission to preserve "today" selection) LaunchedEffect(pagerState) { - snapshotFlow { pagerState.settledPage }.collect { page -> + snapshotFlow { pagerState.settledPage }.drop(1).collect { page -> val yearMonth = pageToYearMonth(page, initialYearMonth) onMonthChanged(yearMonth.first, yearMonth.second) } diff --git a/shared/src/commonMain/kotlin/plus/rua/project/ui/WeekPager.kt b/shared/src/commonMain/kotlin/plus/rua/project/ui/WeekPager.kt index 022f673..6c75cac 100644 --- a/shared/src/commonMain/kotlin/plus/rua/project/ui/WeekPager.kt +++ b/shared/src/commonMain/kotlin/plus/rua/project/ui/WeekPager.kt @@ -13,6 +13,7 @@ import androidx.compose.runtime.rememberCoroutineScope import androidx.compose.runtime.snapshotFlow import androidx.compose.ui.Modifier import androidx.compose.ui.unit.dp +import kotlinx.coroutines.flow.drop import kotlinx.coroutines.launch import kotlinx.datetime.DatePeriod import kotlinx.datetime.LocalDate @@ -46,7 +47,7 @@ fun WeekPager( ) LaunchedEffect(pagerState) { - snapshotFlow { pagerState.settledPage }.collect { page -> + snapshotFlow { pagerState.settledPage }.drop(1).collect { page -> val weekMonday = pageToWeekMonday(page, initialWeekMonday) onWeekChanged(weekMonday) }