mirror of
https://github.com/vitorpamplona/amethyst.git
synced 2025-07-12 23:16:44 +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:
@ -197,7 +197,6 @@ import com.vitorpamplona.quartz.events.TorrentCommentEvent
|
|||||||
import com.vitorpamplona.quartz.events.TorrentEvent
|
import com.vitorpamplona.quartz.events.TorrentEvent
|
||||||
import com.vitorpamplona.quartz.events.VideoEvent
|
import com.vitorpamplona.quartz.events.VideoEvent
|
||||||
import com.vitorpamplona.quartz.events.WikiNoteEvent
|
import com.vitorpamplona.quartz.events.WikiNoteEvent
|
||||||
import com.vitorpamplona.quartz.utils.TimeUtils
|
|
||||||
import kotlinx.collections.immutable.toImmutableList
|
import kotlinx.collections.immutable.toImmutableList
|
||||||
import kotlinx.coroutines.Dispatchers
|
import kotlinx.coroutines.Dispatchers
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
@ -236,7 +235,6 @@ fun RenderThreadFeed(
|
|||||||
nav: INav,
|
nav: INav,
|
||||||
) {
|
) {
|
||||||
val items by loaded.feed.collectAsStateWithLifecycle()
|
val items by loaded.feed.collectAsStateWithLifecycle()
|
||||||
val firstTimeScrolled = remember { TimeUtils.now() }
|
|
||||||
|
|
||||||
LaunchedEffect(noteId, items.list) {
|
LaunchedEffect(noteId, items.list) {
|
||||||
// hack to allow multiple scrolls to Item while posts on the screen load.
|
// 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.
|
// records before setting up the position on the feed.
|
||||||
//
|
//
|
||||||
// It jumps around, but it is the best we can do.
|
// 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 }
|
val position = items.list.indexOfFirst { it.idHex == noteId }
|
||||||
|
|
||||||
if (position >= 0) {
|
if (position >= 0) {
|
||||||
listState.scrollToItem(position, -200)
|
if (position > items.list.size - 3) {
|
||||||
|
listState.scrollToItem(position, 0)
|
||||||
|
} else {
|
||||||
|
listState.scrollToItem(position, -200)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user