Skip to content

Auto-scroll agenda to current day and time on open#419

Open
Copilot wants to merge 1 commit intomainfrom
copilot/scroll-to-date-and-time
Open

Auto-scroll agenda to current day and time on open#419
Copilot wants to merge 1 commit intomainfrom
copilot/scroll-to-date-and-time

Conversation

Copy link
Copy Markdown

Copilot AI commented Apr 9, 2026

When opening the agenda, the app should land on today's tab and scroll the list to the current time slot — e.g. at 13:37 it should show the 13:30 sticky header.

Changes

  • AgendaColumn: Added initialFirstVisibleItemIndex: Int = 0 parameter, passed directly to rememberLazyListState so the list starts at the right position before first render (no scroll animation).

  • AgendaPager: For each page, checks whether it represents today (comparing DaySchedule.date against Clock.System.todayIn(eventTimeZone)). If so, calls currentTimeScrollIndex() and passes the result to AgendaColumn; otherwise defaults to 0.

  • currentTimeScrollIndex(): Walks the Map<String, List<UISession>> accumulating lazy list item indices (1 header + N sessions per slot) and tracks the index of the last slot whose startDate ≤ now. Returns 0 if all slots are in the future.

private fun Map<String, List<UISession>>.currentTimeScrollIndex(): Int {
  val now = Clock.System.now()
  var itemIndex = 0
  var targetIndex = 0
  for ((_, sessions) in this) {
    val slotStart = sessions.firstOrNull()?.startDate
    if (slotStart != null && slotStart <= now) targetIndex = itemIndex
    itemIndex += 1 + sessions.size
  }
  return targetIndex
}

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Updates the agenda UI so that when the user opens the agenda, it defaults to today’s tab and the session list starts near the current time slot (via an initial lazy list index), avoiding a post-render scroll animation.

Changes:

  • Added an initialFirstVisibleItemIndex parameter to AgendaColumn and wired it into rememberLazyListState.
  • In AgendaPager, detects whether a page corresponds to “today” and computes an initial scroll index for that day.
  • Introduced currentTimeScrollIndex() to compute the lazy-list index of the last started time-slot header.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
shared/ui/src/commonMain/kotlin/com/androidmakers/ui/agenda/AgendaPager.kt Computes “today” per page and derives an initial scroll index; adds currentTimeScrollIndex() helper.
shared/ui/src/commonMain/kotlin/com/androidmakers/ui/agenda/AgendaColumn.kt Accepts an initial list position and passes it into rememberLazyListState for first render positioning.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +87 to +89
val isToday = remember(page) {
days[page].date == Clock.System.todayIn(eventTimeZone)
}
Copy link

Copilot AI Apr 9, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

isToday is memoized only by page, but it depends on days[page].date and on Clock.System.todayIn(eventTimeZone). With the current remember(page) it can become stale (e.g., if days updates while staying on the same page index, or if the date changes while the screen stays in the back stack). Consider computing isToday directly from day.date (no remember), or at least keying remember on day.date (and avoid indexing back into days since day is already available).

Suggested change
val isToday = remember(page) {
days[page].date == Clock.System.todayIn(eventTimeZone)
}
val isToday = day.date == Clock.System.todayIn(eventTimeZone)

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants