From f1141e698eced533289a3a6cccb5feedfdffeeba Mon Sep 17 00:00:00 2001 From: Giovanni Gatti <156141003+geovnn@users.noreply.github.com> Date: Sun, 5 Jan 2025 00:52:53 +0100 Subject: [PATCH] Use rememberSaveable to keep note state across LazyColumns recompositions --- .../amethyst/ui/components/ExpandableRichTextViewer.kt | 3 ++- .../java/com/vitorpamplona/amethyst/ui/note/ReactionsRow.kt | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/components/ExpandableRichTextViewer.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/components/ExpandableRichTextViewer.kt index 6044422cc..2a36cb95e 100644 --- a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/components/ExpandableRichTextViewer.kt +++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/components/ExpandableRichTextViewer.kt @@ -36,6 +36,7 @@ import androidx.compose.runtime.derivedStateOf import androidx.compose.runtime.getValue import androidx.compose.runtime.mutableStateOf import androidx.compose.runtime.remember +import androidx.compose.runtime.saveable.rememberSaveable import androidx.compose.runtime.setValue import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier @@ -70,7 +71,7 @@ fun ExpandableRichTextViewer( nav: INav, ) { var showFullText by - remember { + rememberSaveable { val cached = ShowFullTextCache.cache[id] if (cached == null) { ShowFullTextCache.cache.put(id, false) diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/note/ReactionsRow.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/note/ReactionsRow.kt index f4e1193de..9fe891647 100644 --- a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/note/ReactionsRow.kt +++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/note/ReactionsRow.kt @@ -71,6 +71,7 @@ import androidx.compose.runtime.mutableStateOf import androidx.compose.runtime.produceState import androidx.compose.runtime.remember import androidx.compose.runtime.rememberCoroutineScope +import androidx.compose.runtime.saveable.rememberSaveable import androidx.compose.runtime.setValue import androidx.compose.ui.Alignment import androidx.compose.ui.Alignment.Companion.Center @@ -169,7 +170,7 @@ fun ReactionsRow( accountViewModel: AccountViewModel, nav: INav, ) { - val wantsToSeeReactions = remember(baseNote) { mutableStateOf(false) } + val wantsToSeeReactions = rememberSaveable(baseNote) { mutableStateOf(false) } InnerReactionRow(baseNote, showReactionDetail, addPadding, wantsToSeeReactions, editState, accountViewModel, nav)