Skip to content

Commit 09946e4

Browse files
programadorthiThiago dos Santos
authored and
Thiago dos Santos
committed
fix: replace all atomic snapshot operation (#519)
Co-authored-by: Thiago dos Santos <[email protected]>
1 parent c7d10cc commit 09946e4

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed

voyager-core/src/commonMain/kotlin/cafe/adriel/voyager/core/stack/SnapshotStateStack.kt

+11-6
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import androidx.compose.runtime.saveable.Saver
99
import androidx.compose.runtime.saveable.listSaver
1010
import androidx.compose.runtime.saveable.rememberSaveable
1111
import androidx.compose.runtime.setValue
12+
import androidx.compose.runtime.snapshots.Snapshot
1213
import androidx.compose.runtime.snapshots.SnapshotStateList
1314
import androidx.compose.runtime.toMutableStateList
1415

@@ -111,15 +112,19 @@ public class SnapshotStateStack<Item>(
111112
}
112113

113114
public override infix fun replaceAll(item: Item) {
114-
stateStack.clear()
115-
stateStack += item
116-
lastEvent = StackEvent.Replace
115+
Snapshot.withMutableSnapshot {
116+
stateStack.clear()
117+
stateStack += item
118+
lastEvent = StackEvent.Replace
119+
}
117120
}
118121

119122
public override infix fun replaceAll(items: List<Item>) {
120-
stateStack.clear()
121-
stateStack += items
122-
lastEvent = StackEvent.Replace
123+
Snapshot.withMutableSnapshot {
124+
stateStack.clear()
125+
stateStack += items
126+
lastEvent = StackEvent.Replace
127+
}
123128
}
124129

125130
public override fun pop(): Boolean =

0 commit comments

Comments
 (0)