From 89e1e20b40f3c4bd0030dca186e7c15d77cabe77 Mon Sep 17 00:00:00 2001 From: Vitor Pamplona Date: Tue, 22 Oct 2024 17:26:53 -0400 Subject: [PATCH] Improves algorithm for placing the clicked note in a visible position when opening a new threads that need to load dynamically --- .../ui/screen/loggedIn/threadview/ThreadFeedView.kt | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/threadview/ThreadFeedView.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/threadview/ThreadFeedView.kt index 77350a7a89..60fb5849c1 100644 --- a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/threadview/ThreadFeedView.kt +++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/threadview/ThreadFeedView.kt @@ -197,7 +197,6 @@ import com.vitorpamplona.quartz.events.TorrentCommentEvent import com.vitorpamplona.quartz.events.TorrentEvent import com.vitorpamplona.quartz.events.VideoEvent import com.vitorpamplona.quartz.events.WikiNoteEvent -import com.vitorpamplona.quartz.utils.TimeUtils import kotlinx.collections.immutable.toImmutableList import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.launch @@ -236,7 +235,6 @@ fun RenderThreadFeed( nav: INav, ) { val items by loaded.feed.collectAsStateWithLifecycle() - val firstTimeScrolled = remember { TimeUtils.now() } LaunchedEffect(noteId, items.list) { // hack to allow multiple scrolls to Item while posts on the screen load. @@ -252,10 +250,15 @@ fun RenderThreadFeed( // records before setting up the position on the feed. // // It jumps around, but it is the best we can do. - if (TimeUtils.now() - firstTimeScrolled < 1000) { + if (listState.firstVisibleItemIndex == 0 && listState.firstVisibleItemScrollOffset == 0 && items.list.size > 3) { val position = items.list.indexOfFirst { it.idHex == noteId } + if (position >= 0) { - listState.scrollToItem(position, -200) + if (position > items.list.size - 3) { + listState.scrollToItem(position, 0) + } else { + listState.scrollToItem(position, -200) + } } } }