From 09946e4d3eb42045714e2061d288bcc85af22819 Mon Sep 17 00:00:00 2001 From: Thiago Santos Date: Thu, 19 Dec 2024 18:35:55 -0300 Subject: [PATCH] fix: replace all atomic snapshot operation (#519) Co-authored-by: Thiago dos Santos --- .../voyager/core/stack/SnapshotStateStack.kt | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/voyager-core/src/commonMain/kotlin/cafe/adriel/voyager/core/stack/SnapshotStateStack.kt b/voyager-core/src/commonMain/kotlin/cafe/adriel/voyager/core/stack/SnapshotStateStack.kt index d6e7adb8..db9b901b 100644 --- a/voyager-core/src/commonMain/kotlin/cafe/adriel/voyager/core/stack/SnapshotStateStack.kt +++ b/voyager-core/src/commonMain/kotlin/cafe/adriel/voyager/core/stack/SnapshotStateStack.kt @@ -9,6 +9,7 @@ import androidx.compose.runtime.saveable.Saver import androidx.compose.runtime.saveable.listSaver import androidx.compose.runtime.saveable.rememberSaveable import androidx.compose.runtime.setValue +import androidx.compose.runtime.snapshots.Snapshot import androidx.compose.runtime.snapshots.SnapshotStateList import androidx.compose.runtime.toMutableStateList @@ -111,15 +112,19 @@ public class SnapshotStateStack( } public override infix fun replaceAll(item: Item) { - stateStack.clear() - stateStack += item - lastEvent = StackEvent.Replace + Snapshot.withMutableSnapshot { + stateStack.clear() + stateStack += item + lastEvent = StackEvent.Replace + } } public override infix fun replaceAll(items: List) { - stateStack.clear() - stateStack += items - lastEvent = StackEvent.Replace + Snapshot.withMutableSnapshot { + stateStack.clear() + stateStack += items + lastEvent = StackEvent.Replace + } } public override fun pop(): Boolean =