Skip to content

Commit

Permalink
fix(ui): remember swipe actions to avoid recomposition
Browse files Browse the repository at this point in the history
  • Loading branch information
JunkFood02 committed Feb 18, 2024
1 parent 4c7bea9 commit 733c8d0
Showing 1 changed file with 31 additions and 23 deletions.
54 changes: 31 additions & 23 deletions app/src/main/java/me/ash/reader/ui/page/home/flow/FlowPage.kt
Original file line number Diff line number Diff line change
Expand Up @@ -80,35 +80,43 @@ fun FlowPage(
}


val onToggleStarred: State<(ArticleWithFeed) -> Unit> = rememberUpdatedState {
flowViewModel.updateStarredStatus(
articleId = it.article.id,
isStarred = !it.article.isStarred,
withDelay = 300
)
val onToggleStarred: (ArticleWithFeed) -> Unit = remember {
{
flowViewModel.updateStarredStatus(
articleId = it.article.id,
isStarred = !it.article.isStarred,
withDelay = 300
)
}
}

val onToggleRead: State<(ArticleWithFeed) -> Unit> = rememberUpdatedState {
flowViewModel.updateReadStatus(
groupId = null,
feedId = null,
articleId = it.article.id,
conditions = MarkAsReadConditions.All,
isUnread = !it.article.isUnread,
withDelay = 300
)
val onToggleRead: (ArticleWithFeed) -> Unit = remember {
{
flowViewModel.updateReadStatus(
groupId = null,
feedId = null,
articleId = it.article.id,
conditions = MarkAsReadConditions.All,
isUnread = !it.article.isUnread,
withDelay = 300
)
}
}

val onSwipeEndToStart = when (swipeToStartAction) {
SwipeStartActionPreference.None -> null
SwipeStartActionPreference.ToggleRead -> onToggleRead.value
SwipeStartActionPreference.ToggleStarred -> onToggleStarred.value
val onSwipeEndToStart = remember(swipeToStartAction) {
when (swipeToStartAction) {
SwipeStartActionPreference.None -> null
SwipeStartActionPreference.ToggleRead -> onToggleRead
SwipeStartActionPreference.ToggleStarred -> onToggleStarred
}
}

val onSwipeStartToEnd = when (swipeToEndAction) {
SwipeEndActionPreference.None -> null
SwipeEndActionPreference.ToggleRead -> onToggleRead.value
SwipeEndActionPreference.ToggleStarred -> onToggleStarred.value
val onSwipeStartToEnd = remember(swipeToEndAction) {
when (swipeToEndAction) {
SwipeEndActionPreference.None -> null
SwipeEndActionPreference.ToggleRead -> onToggleRead
SwipeEndActionPreference.ToggleStarred -> onToggleStarred
}
}

LaunchedEffect(onSearch) {
Expand Down

0 comments on commit 733c8d0

Please sign in to comment.