Skip to content

Commit

Permalink
Moved registration into a remember, so that this happens during compo…
Browse files Browse the repository at this point in the history
…sition, which prevents certain types of race conditions with initialisation in ViewModels
  • Loading branch information
isaac-udy committed Mar 23, 2023
1 parent 81bc668 commit 169fa95
Showing 1 changed file with 6 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import dev.enro.core.compose.dialog.DialogDestination
import dev.enro.core.container.*
import dev.enro.core.controller.get
import dev.enro.core.controller.interceptor.builder.NavigationInterceptorBuilder
import java.io.Closeable
import kotlin.collections.set

public class ComposableNavigationContainer internal constructor(
Expand Down Expand Up @@ -213,12 +214,15 @@ public class ComposableNavigationContainer internal constructor(
internal fun registerWithContainerManager(
registrationStrategy: ContainerRegistrationStrategy
): Boolean {
DisposableEffect(key, registrationStrategy) {
val registration = remember(key, registrationStrategy) {
val containerManager = parentContext.containerManager
containerManager.addContainer(this@ComposableNavigationContainer)
Closeable { destroy() }
}
DisposableEffect(key, registrationStrategy) {
onDispose {
when (registrationStrategy) {
ContainerRegistrationStrategy.DisposeWithComposition -> destroy()
ContainerRegistrationStrategy.DisposeWithComposition -> registration.close()
ContainerRegistrationStrategy.DisposeWithLifecycle -> {} // handled by init
}
}
Expand Down

0 comments on commit 169fa95

Please sign in to comment.