Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(NavHost): fix an issue where SaveableCloseable would reference to wrong SaveableStateHolder after configuration changes #59

Merged
merged 2 commits into from
Mar 8, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -270,12 +270,10 @@
executor
.storeFor(entry.id)
.getOrCreate(SaveableCloseable::class) {
SaveableCloseable(
entry.id.value,
WeakReference(saveableStateHolder),
)
SaveableCloseable(entry.id.value)

Check warning on line 273 in navigation/src/commonMain/kotlin/com/hoc081098/solivagant/navigation/NavHost.kt

View check run for this annotation

Codecov / codecov/patch

navigation/src/commonMain/kotlin/com/hoc081098/solivagant/navigation/NavHost.kt#L273

Added line #L273 was not covered by tests
}
}
saveableCloseable.saveableStateHolderRef = WeakReference(saveableStateHolder)

Check warning on line 276 in navigation/src/commonMain/kotlin/com/hoc081098/solivagant/navigation/NavHost.kt

View check run for this annotation

Codecov / codecov/patch

navigation/src/commonMain/kotlin/com/hoc081098/solivagant/navigation/NavHost.kt#L276

Added line #L276 was not covered by tests

val savedStateHandleFactory = remember(executor, entry.id) {
SavedStateHandleFactory { executor.savedStateHandleFor(entry.id) }
Expand Down Expand Up @@ -319,12 +317,12 @@

internal class SaveableCloseable(
private val id: String,
private val saveableStateHolderRef: WeakReference<SaveableStateHolder>,
) : Closeable {
private val _viewModelStoreOwnerState: MutableState<StackEntryViewModelStoreOwner?> =
mutableStateOf(StackEntryViewModelStoreOwner())

inline val viewModelStoreOwnerState: State<StackEntryViewModelStoreOwner?> get() = _viewModelStoreOwnerState
internal inline val viewModelStoreOwnerState: State<StackEntryViewModelStoreOwner?> get() = _viewModelStoreOwnerState
internal lateinit var saveableStateHolderRef: WeakReference<SaveableStateHolder>

Check warning on line 325 in navigation/src/commonMain/kotlin/com/hoc081098/solivagant/navigation/NavHost.kt

View check run for this annotation

Codecov / codecov/patch

navigation/src/commonMain/kotlin/com/hoc081098/solivagant/navigation/NavHost.kt#L324-L325

Added lines #L324 - L325 were not covered by tests

override fun close() {
Snapshot.withMutableSnapshot {
Expand Down