Compare commits
2 Commits
6ab235e1d8
...
052335e842
| Author | SHA1 | Date | |
|---|---|---|---|
| 052335e842 | |||
| 28fb7404d8 |
@@ -239,6 +239,19 @@ fun MonthScreen(
|
||||
.collect { (first, last) -> viewModel.onVisibleMonthsChanged(first, last) }
|
||||
}
|
||||
|
||||
// Keep the paged month tracking the scrolling grid. The scrolling styles
|
||||
// navigate by scroll position and never touch the paged month otherwise, so
|
||||
// without this it stays wherever paged navigation last left it (today's
|
||||
// month, on a fresh open) — and switching to a paged style, or reseeding the
|
||||
// other scrolling style's list state, which both read off it, would snap
|
||||
// back there rather than staying on the month you were looking at.
|
||||
LaunchedEffect(listState, scrolling, dense, weekStart) {
|
||||
if (!scrolling) return@LaunchedEffect
|
||||
snapshotFlow { visibleMonth }
|
||||
.distinctUntilChanged()
|
||||
.collect { viewModel.syncScrollMonth(it) }
|
||||
}
|
||||
|
||||
val isOnCurrentMonth = titleMonth == YearMonth(today.year, today.month)
|
||||
|
||||
// Continuous names the month on the block's own sticky header, so the bar
|
||||
@@ -297,6 +310,15 @@ fun MonthScreen(
|
||||
viewModel.goToDate(target)
|
||||
}
|
||||
}
|
||||
// Selecting a day in the split grid can cross into a neighbour month — a
|
||||
// tapped leading/trailing day follows to its own month. Point the slide the
|
||||
// way the month is actually moving, so the incoming page travels the right
|
||||
// direction instead of reusing whatever the last swipe left in slideDir.
|
||||
val selectDay: (LocalDate) -> Unit = { date ->
|
||||
val target = YearMonth(date.year, date.month)
|
||||
if (target != month) slideDir = if (target < month) -1 else 1
|
||||
viewModel.selectDate(date)
|
||||
}
|
||||
|
||||
ModalNavigationDrawer(
|
||||
drawerState = drawerState,
|
||||
@@ -377,7 +399,7 @@ fun MonthScreen(
|
||||
onSwipeNext = goNext,
|
||||
onSwipePrev = goPrev,
|
||||
onRetry = jumpToToday,
|
||||
onSelectDay = viewModel::selectDate,
|
||||
onSelectDay = selectDay,
|
||||
onOpenDay = onOpenDay,
|
||||
onEventClick = onEventClick,
|
||||
onCreateEvent = { onCreateEvent(it, null) },
|
||||
|
||||
@@ -284,6 +284,21 @@ class MonthViewModel @Inject constructor(
|
||||
_selectedDate.value = todayDate
|
||||
}
|
||||
|
||||
/**
|
||||
* Track [_month] to the month a scrolling style is showing. Those styles
|
||||
* navigate by scroll position and never set [_month] themselves, so it would
|
||||
* otherwise sit wherever paged navigation last left it (today's month, on a
|
||||
* fresh open) — and a switch to a paged style, or a reseed of the other
|
||||
* scrolling style's list, would jump there instead of holding position. The
|
||||
* selection is realigned alongside it so that landing on the Split style
|
||||
* shows a live day in the month on screen rather than a stale, off-month one.
|
||||
*/
|
||||
fun syncScrollMonth(ym: YearMonth) {
|
||||
if (_month.value == ym) return
|
||||
_month.value = ym
|
||||
_selectedDate.value = selectionForMonth(ym, todayDate)
|
||||
}
|
||||
|
||||
/** Jump to the month containing [date] (drawer jump-to-date). */
|
||||
fun goToDate(date: LocalDate) {
|
||||
_month.value = YearMonth(date.year, date.month)
|
||||
|
||||
Reference in New Issue
Block a user