feat: back to top in user detail

This commit is contained in:
Diego Beraldin 2023-10-24 08:54:53 +02:00
parent 745755ff88
commit d89a2169cd
3 changed files with 31 additions and 19 deletions

View File

@ -49,5 +49,6 @@ interface PostDetailMviModel :
sealed interface Effect {
data object Close : Effect
data class ScrollToComment(val index: Int) : Effect
data object BackToTop : Effect
}
}

View File

@ -171,6 +171,12 @@ class PostDetailScreen(
is PostDetailMviModel.Effect.ScrollToComment -> {
lazyListState.scrollToItem(evt.index)
}
PostDetailMviModel.Effect.BackToTop -> {
scope.launch {
lazyListState.scrollToItem(0)
}
}
}
}.launchIn(this)
}
@ -483,26 +489,27 @@ class PostDetailScreen(
)
},
content = {
CommentCard(modifier = Modifier.background(MaterialTheme.colorScheme.background)
.let {
if (comment.id == highlightCommentId) {
it.background(
MaterialTheme.colorScheme.surfaceColorAtElevation(
5.dp
).copy(
alpha = 0.75f
CommentCard(
modifier = Modifier.background(MaterialTheme.colorScheme.background)
.let {
if (comment.id == highlightCommentId) {
it.background(
MaterialTheme.colorScheme.surfaceColorAtElevation(
5.dp
).copy(
alpha = 0.75f
)
)
} else {
it
}
}.onClick {
model.reduce(
PostDetailMviModel.Intent.ToggleExpandComment(
commentId,
)
)
} else {
it
}
}.onClick {
model.reduce(
PostDetailMviModel.Intent.ToggleExpandComment(
commentId,
)
)
},
},
comment = comment,
separateUpAndDownVotes = uiState.separateUpAndDownVotes,
autoLoadImages = uiState.autoLoadImages,
@ -614,7 +621,8 @@ class PostDetailScreen(
)
}
}
})
},
)
},
)
Divider(

View File

@ -295,6 +295,9 @@ class PostDetailViewModel(
private fun applySortType(value: SortType) {
mvi.updateState { it.copy(sortType = value) }
mvi.scope?.launch {
mvi.emitEffect(PostDetailMviModel.Effect.BackToTop)
}
refresh()
}