diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 46914f78..348cdcbb 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -9,8 +9,8 @@ plugin-atomicfu = "0.23.1" coroutines = "1.8.0-RC2" kotlin = "1.9.21" kodein = "7.21.2" -koin = "3.4.3" -koin-compose = "1.0.4" +koin = "3.5.3" +koin-compose = "1.1.2" hilt = "2.49" leakCanary = "2.9.1" appCompat = "1.6.1" diff --git a/voyager-koin/src/commonMain/kotlin/cafe/adriel/voyager/koin/ScreenModel.kt b/voyager-koin/src/commonMain/kotlin/cafe/adriel/voyager/koin/ScreenModel.kt index 6815fe5d..b4b3c3d7 100644 --- a/voyager-koin/src/commonMain/kotlin/cafe/adriel/voyager/koin/ScreenModel.kt +++ b/voyager-koin/src/commonMain/kotlin/cafe/adriel/voyager/koin/ScreenModel.kt @@ -1,29 +1,60 @@ package cafe.adriel.voyager.koin import androidx.compose.runtime.Composable +import androidx.compose.runtime.remember import cafe.adriel.voyager.core.model.ScreenModel import cafe.adriel.voyager.core.model.rememberNavigatorScreenModel import cafe.adriel.voyager.core.model.rememberScreenModel import cafe.adriel.voyager.core.screen.Screen import cafe.adriel.voyager.navigator.Navigator -import org.koin.compose.getKoin +import org.koin.compose.currentKoinScope +import org.koin.compose.stable.rememberStableParametersDefinition import org.koin.core.parameter.ParametersDefinition import org.koin.core.qualifier.Qualifier +import org.koin.core.scope.Scope @Composable -public inline fun Screen.getScreenModel( +public inline fun Screen.koinScreenModel( qualifier: Qualifier? = null, - noinline parameters: ParametersDefinition? = null + scope: Scope = currentKoinScope(), + noinline parameters: ParametersDefinition? = null, ): T { - val koin = getKoin() - return rememberScreenModel(tag = qualifier?.value) { koin.get(qualifier, parameters) } + val st = parameters?.let { rememberStableParametersDefinition(parameters) } + val tag = remember(qualifier, scope) { qualifier?.value } + return rememberScreenModel(tag = tag) { + scope.get(qualifier, st?.parametersDefinition) + } } @Composable -public inline fun Navigator.getNavigatorScreenModel( +public inline fun Navigator.koinNavigatorScreenModel( qualifier: Qualifier? = null, - noinline parameters: ParametersDefinition? = null + scope: Scope = currentKoinScope(), + noinline parameters: ParametersDefinition? = null, ): T { - val koin = getKoin() - return rememberNavigatorScreenModel(tag = qualifier?.value) { koin.get(qualifier, parameters) } + val st = parameters?.let { rememberStableParametersDefinition(parameters) } + val tag = remember(qualifier, scope) { qualifier?.value } + return rememberNavigatorScreenModel(tag = tag) { + scope.get(qualifier, st?.parametersDefinition) + } } + +@Deprecated( + message = "use koinScreenModel() instead", + replaceWith = ReplaceWith("koinScreenModel") +) +@Composable +public inline fun Screen.getScreenModel( + qualifier: Qualifier? = null, + noinline parameters: ParametersDefinition? = null +): T = koinScreenModel(qualifier = qualifier, parameters = parameters) + +@Deprecated( + message = "use koinNavigatorScreenModel() instead", + replaceWith = ReplaceWith("koinNavigatorScreenModel") +) +@Composable +public inline fun Navigator.getNavigatorScreenModel( + qualifier: Qualifier? = null, + noinline parameters: ParametersDefinition? = null +): T = koinNavigatorScreenModel(qualifier = qualifier, parameters = parameters)