-
-
Notifications
You must be signed in to change notification settings - Fork 144
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update Koin and replace with new oficial naming
- Loading branch information
1 parent
5021171
commit 4007279
Showing
2 changed files
with
42 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
49 changes: 40 additions & 9 deletions
49
voyager-koin/src/commonMain/kotlin/cafe/adriel/voyager/koin/ScreenModel.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |