Skip to content

Commit

Permalink
Update Koin and replace with new oficial naming
Browse files Browse the repository at this point in the history
  • Loading branch information
DevSrSouza committed Mar 23, 2024
1 parent 5021171 commit 4007279
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 11 deletions.
4 changes: 2 additions & 2 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
Original file line number Diff line number Diff line change
@@ -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 <reified T : ScreenModel> Screen.getScreenModel(
public inline fun <reified T : ScreenModel> 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 <reified T : ScreenModel> Navigator.getNavigatorScreenModel(
public inline fun <reified T : ScreenModel> 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 <reified T : ScreenModel> Screen.getScreenModel(
qualifier: Qualifier? = null,
noinline parameters: ParametersDefinition? = null
): T = koinScreenModel<T>(qualifier = qualifier, parameters = parameters)

@Deprecated(
message = "use koinNavigatorScreenModel() instead",
replaceWith = ReplaceWith("koinNavigatorScreenModel")
)
@Composable
public inline fun <reified T : ScreenModel> Navigator.getNavigatorScreenModel(
qualifier: Qualifier? = null,
noinline parameters: ParametersDefinition? = null
): T = koinNavigatorScreenModel(qualifier = qualifier, parameters = parameters)

0 comments on commit 4007279

Please sign in to comment.