From 75977347e73c31c4514f9c997dbff4ef65f87502 Mon Sep 17 00:00:00 2001 From: ganfra Date: Wed, 2 Oct 2024 18:44:38 +0200 Subject: [PATCH] timeline : fix jumpToBottom for not live timeline. --- .../features/messages/impl/timeline/TimelineView.kt | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/timeline/TimelineView.kt b/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/timeline/TimelineView.kt index 59df0cb70d..bce3bb3f5e 100644 --- a/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/timeline/TimelineView.kt +++ b/features/messages/impl/src/main/kotlin/io/element/android/features/messages/impl/timeline/TimelineView.kt @@ -30,9 +30,11 @@ import androidx.compose.runtime.CompositionLocalProvider import androidx.compose.runtime.LaunchedEffect import androidx.compose.runtime.derivedStateOf import androidx.compose.runtime.getValue +import androidx.compose.runtime.mutableStateOf import androidx.compose.runtime.remember import androidx.compose.runtime.rememberCoroutineScope import androidx.compose.runtime.rememberUpdatedState +import androidx.compose.runtime.setValue import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier import androidx.compose.ui.draw.rotate @@ -206,6 +208,7 @@ private fun BoxScope.TimelineScrollHelper( lazyListState.firstVisibleItemIndex < 3 && isLive } } + var jumpToLiveHandled by remember { mutableStateOf(true) } fun scrollToBottom() { coroutineScope.launch { @@ -221,10 +224,18 @@ private fun BoxScope.TimelineScrollHelper( if (isLive) { scrollToBottom() } else { + jumpToLiveHandled = false onJumpToLive() } } + LaunchedEffect(jumpToLiveHandled, isLive) { + if (!jumpToLiveHandled && isLive) { + lazyListState.scrollToItem(0) + jumpToLiveHandled = true + } + } + val latestOnFocusEventRender by rememberUpdatedState(onFocusEventRender) LaunchedEffect(focusRequestState) { if (focusRequestState is FocusRequestState.Success && focusRequestState.isIndexed) {