Moves notification's scroll to top animation to an IO thread.
This commit is contained in:
@@ -34,6 +34,7 @@ import com.vitorpamplona.amethyst.ui.note.MultiSetCompose
|
|||||||
import com.vitorpamplona.amethyst.ui.note.NoteCompose
|
import com.vitorpamplona.amethyst.ui.note.NoteCompose
|
||||||
import com.vitorpamplona.amethyst.ui.note.ZapUserSetCompose
|
import com.vitorpamplona.amethyst.ui.note.ZapUserSetCompose
|
||||||
import com.vitorpamplona.amethyst.ui.screen.loggedIn.AccountViewModel
|
import com.vitorpamplona.amethyst.ui.screen.loggedIn.AccountViewModel
|
||||||
|
import kotlinx.coroutines.launch
|
||||||
|
|
||||||
@OptIn(ExperimentalMaterialApi::class)
|
@OptIn(ExperimentalMaterialApi::class)
|
||||||
@Composable
|
@Composable
|
||||||
@@ -100,9 +101,11 @@ private fun WatchScrollToTop(
|
|||||||
val scrollToTop by viewModel.scrollToTop.collectAsState()
|
val scrollToTop by viewModel.scrollToTop.collectAsState()
|
||||||
|
|
||||||
LaunchedEffect(scrollToTop) {
|
LaunchedEffect(scrollToTop) {
|
||||||
if (scrollToTop > 0 && viewModel.scrolltoTopPending) {
|
launch {
|
||||||
listState.scrollToItem(index = 0)
|
if (scrollToTop > 0 && viewModel.scrolltoTopPending) {
|
||||||
viewModel.sentToTop()
|
listState.scrollToItem(index = 0)
|
||||||
|
viewModel.sentToTop()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -118,11 +121,10 @@ fun RenderCardFeed(
|
|||||||
val feedState by viewModel.feedContent.collectAsState()
|
val feedState by viewModel.feedContent.collectAsState()
|
||||||
|
|
||||||
Crossfade(
|
Crossfade(
|
||||||
modifier = Modifier.fillMaxSize(),
|
modifier = remember { Modifier.fillMaxSize() },
|
||||||
targetState = feedState,
|
targetState = feedState,
|
||||||
animationSpec = tween(durationMillis = 100)
|
animationSpec = tween(durationMillis = 100)
|
||||||
) { state ->
|
) { state ->
|
||||||
|
|
||||||
when (state) {
|
when (state) {
|
||||||
is CardFeedState.Empty -> {
|
is CardFeedState.Empty -> {
|
||||||
FeedEmpty {
|
FeedEmpty {
|
||||||
@@ -176,49 +178,59 @@ private fun FeedLoaded(
|
|||||||
) {
|
) {
|
||||||
itemsIndexed(state.feed.value, key = { _, item -> item.id() }) { _, item ->
|
itemsIndexed(state.feed.value, key = { _, item -> item.id() }) { _, item ->
|
||||||
Row(defaultModifier) {
|
Row(defaultModifier) {
|
||||||
when (item) {
|
RenderCardItem(item, accountViewModel, nav, routeForLastRead)
|
||||||
is NoteCard -> NoteCompose(
|
|
||||||
item,
|
|
||||||
isBoostedNote = false,
|
|
||||||
accountViewModel = accountViewModel,
|
|
||||||
nav = nav,
|
|
||||||
routeForLastRead = routeForLastRead
|
|
||||||
)
|
|
||||||
|
|
||||||
is ZapUserSetCard -> ZapUserSetCompose(
|
|
||||||
item,
|
|
||||||
isInnerNote = false,
|
|
||||||
accountViewModel = accountViewModel,
|
|
||||||
nav = nav,
|
|
||||||
routeForLastRead = routeForLastRead
|
|
||||||
)
|
|
||||||
|
|
||||||
is MultiSetCard -> MultiSetCompose(
|
|
||||||
item,
|
|
||||||
accountViewModel = accountViewModel,
|
|
||||||
nav = nav,
|
|
||||||
routeForLastRead = routeForLastRead
|
|
||||||
)
|
|
||||||
|
|
||||||
is BadgeCard -> BadgeCompose(
|
|
||||||
item,
|
|
||||||
accountViewModel = accountViewModel,
|
|
||||||
nav = nav,
|
|
||||||
routeForLastRead = routeForLastRead
|
|
||||||
)
|
|
||||||
|
|
||||||
is MessageSetCard -> MessageSetCompose(
|
|
||||||
messageSetCard = item,
|
|
||||||
routeForLastRead = routeForLastRead,
|
|
||||||
accountViewModel = accountViewModel,
|
|
||||||
nav = nav
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Composable
|
||||||
|
private fun RenderCardItem(
|
||||||
|
item: Card,
|
||||||
|
accountViewModel: AccountViewModel,
|
||||||
|
nav: (String) -> Unit,
|
||||||
|
routeForLastRead: String
|
||||||
|
) {
|
||||||
|
when (item) {
|
||||||
|
is NoteCard -> NoteCompose(
|
||||||
|
item,
|
||||||
|
isBoostedNote = false,
|
||||||
|
accountViewModel = accountViewModel,
|
||||||
|
nav = nav,
|
||||||
|
routeForLastRead = routeForLastRead
|
||||||
|
)
|
||||||
|
|
||||||
|
is ZapUserSetCard -> ZapUserSetCompose(
|
||||||
|
item,
|
||||||
|
isInnerNote = false,
|
||||||
|
accountViewModel = accountViewModel,
|
||||||
|
nav = nav,
|
||||||
|
routeForLastRead = routeForLastRead
|
||||||
|
)
|
||||||
|
|
||||||
|
is MultiSetCard -> MultiSetCompose(
|
||||||
|
item,
|
||||||
|
accountViewModel = accountViewModel,
|
||||||
|
nav = nav,
|
||||||
|
routeForLastRead = routeForLastRead
|
||||||
|
)
|
||||||
|
|
||||||
|
is BadgeCard -> BadgeCompose(
|
||||||
|
item,
|
||||||
|
accountViewModel = accountViewModel,
|
||||||
|
nav = nav,
|
||||||
|
routeForLastRead = routeForLastRead
|
||||||
|
)
|
||||||
|
|
||||||
|
is MessageSetCard -> MessageSetCompose(
|
||||||
|
messageSetCard = item,
|
||||||
|
routeForLastRead = routeForLastRead,
|
||||||
|
accountViewModel = accountViewModel,
|
||||||
|
nav = nav
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
fun NoteCompose(
|
fun NoteCompose(
|
||||||
baseNote: NoteCard,
|
baseNote: NoteCard,
|
||||||
|
|||||||
Reference in New Issue
Block a user