@@ -48,6 +48,7 @@ import androidx.compose.runtime.mutableIntStateOf
4848import androidx.compose.runtime.mutableStateOf
4949import androidx.compose.runtime.remember
5050import androidx.compose.runtime.rememberCoroutineScope
51+ import androidx.compose.runtime.rememberUpdatedState
5152import androidx.compose.runtime.setValue
5253import androidx.compose.ui.Alignment
5354import androidx.compose.ui.Modifier
@@ -679,19 +680,22 @@ internal fun shouldReturnCalendarFocusToControls(
679680internal enum class CalendarUpFallbackAction {
680681 EnterMenu ,
681682 ReturnToControls ,
683+ StayInContent ,
682684 MoveWithinContent ,
683685}
684686
685687internal fun calendarUpFallbackAction (
686688 focusedShelfIndex : Int? ,
687689 firstFocusableShelfIndex : Int ,
688690 isReturningToControls : Boolean ,
691+ isRepeat : Boolean = false,
689692): CalendarUpFallbackAction = when {
690693 shouldReturnCalendarFocusToControls(
691694 focusedShelfIndex = focusedShelfIndex,
692695 firstFocusableShelfIndex = firstFocusableShelfIndex,
693696 isReturningToControls = isReturningToControls,
694- ) -> CalendarUpFallbackAction .ReturnToControls
697+ ) -> if (isRepeat) CalendarUpFallbackAction .StayInContent else CalendarUpFallbackAction .ReturnToControls
698+ focusedShelfIndex == null && isRepeat -> CalendarUpFallbackAction .StayInContent
695699 focusedShelfIndex == null -> CalendarUpFallbackAction .EnterMenu
696700 else -> CalendarUpFallbackAction .MoveWithinContent
697701}
@@ -754,12 +758,12 @@ private fun CalendarList(
754758 // when focus is already in the controls item, mirror the shell's default
755759 // (moveFocus within content; false -> shell hands off to the menu bar).
756760 var focusedShelfIndex by remember { mutableStateOf<Int ?>(null ) }
757- val calendarUpFallback = remember(firstFocusableDayIndex) {
758- { _: Boolean ->
761+ val currentCalendarUpFallback = rememberUpdatedState< (Boolean ) -> Boolean > { isRepeat ->
759762 when (calendarUpFallbackAction(
760763 focusedShelfIndex = focusedShelfIndex,
761764 firstFocusableShelfIndex = firstFocusableDayIndex,
762765 isReturningToControls = isReturningToControls,
766+ isRepeat = isRepeat,
763767 )
764768 ) {
765769 CalendarUpFallbackAction .EnterMenu -> {
@@ -770,15 +774,21 @@ private fun CalendarList(
770774 onMoveUpToControls()
771775 true
772776 }
777+ CalendarUpFallbackAction .StayInContent -> true
773778 CalendarUpFallbackAction .MoveWithinContent -> {
774779 focusManager.moveFocus(androidx.compose.ui.focus.FocusDirection .Up )
775780 }
776781 }
777- }
778782 }
779- DisposableEffect (onContentUpFallbackChanged) {
780- onContentUpFallbackChanged?.invoke(calendarUpFallback)
781- onDispose { onContentUpFallbackChanged?.invoke(calendarUpFallback) }
783+ // Keep the registered identity stable while its implementation reads the
784+ // current loaded-day state. A new lambda keyed by firstFocusableDayIndex
785+ // would otherwise leave the shell holding the pre-load callback until this
786+ // screen disposes.
787+ val calendarUpFallbackRegistration: (Boolean ) -> Boolean =
788+ remember { { isRepeat -> currentCalendarUpFallback.value(isRepeat) } }
789+ DisposableEffect (onContentUpFallbackChanged, calendarUpFallbackRegistration) {
790+ onContentUpFallbackChanged?.invoke(calendarUpFallbackRegistration)
791+ onDispose { onContentUpFallbackChanged?.invoke(calendarUpFallbackRegistration) }
782792 }
783793
784794 // The day-snap is the ONLY vertical scroller: with the default spec the
0 commit comments