File tree Expand file tree Collapse file tree 1 file changed +20
-8
lines changed
core/ui/compose/common/src/main/kotlin/app/k9mail/core/ui/compose/common/koin Expand file tree Collapse file tree 1 file changed +20
-8
lines changed Original file line number Diff line number Diff line change 11package app.k9mail.core.ui.compose.common.koin
22
33import androidx.compose.runtime.Composable
4- import org.koin.compose.KoinContext
5- import org.koin.core.Koin
4+ import org.koin.compose.KoinApplicationPreview
5+ import org.koin.core.module.Module
66import org.koin.dsl.ModuleDeclaration
77import org.koin.dsl.module
88
99/* *
1010 * Helper to make Compose previews work when some dependencies are injected via Koin.
11+ *
12+ * Usage:
13+ * ```kotlin
14+ * @Composable
15+ * @Preview()
16+ * fun SomeComposablePreview() {
17+ * koinPreview {
18+ * // Declare Koin modules here
19+ * factory { SomeDependency() }
20+ * } WithContent {
21+ * // Your preview content here
22+ * }
23+ * }
24+ * ```
1125 */
1226fun koinPreview (moduleDeclaration : ModuleDeclaration ): KoinPreview {
13- val koin = Koin ().apply {
14- loadModules(listOf (module(moduleDeclaration = moduleDeclaration)))
15- }
27+ val modules = listOf (module(moduleDeclaration = moduleDeclaration))
1628
17- return KoinPreview (koin )
29+ return KoinPreview (modules )
1830}
1931
20- class KoinPreview internal constructor(private val koin : Koin ) {
32+ class KoinPreview internal constructor(private val modulesList : List < Module > ) {
2133 @Composable
2234 infix fun WithContent (content : @Composable () -> Unit ) {
23- KoinContext (context = koin ) {
35+ KoinApplicationPreview (application = { modules(modulesList) } ) {
2436 content()
2537 }
2638 }
You can’t perform that action at this time.
0 commit comments