mirror of
https://github.com/vitorpamplona/amethyst.git
synced 2025-04-04 01:48:14 +02:00
Improves algorithm for placing the clicked note in a visible position when opening a new threads that need to load dynamically
This commit is contained in:
parent
c2e725ef5f
commit
89e1e20b40
@ -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)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user