Skip to content

Commit 4d748cc

Browse files
committed
refactor: provide navigation event dispatcher in Koin previews
- Wrap the `content` of the `PreviewKoin` composable with a `CompositionLocalProvider`. - Initialize and provide a `LocalNavigationEventDispatcherOwner` using `rememberNavigationEventDispatcherOwner` to support UI components that depend on navigation event dispatching within Compose Previews.
1 parent acf05f9 commit 4d748cc

1 file changed

Lines changed: 9 additions & 1 deletion

File tree

  • core/ui/src/commonMain/kotlin/com/softartdev/notedelight/di

core/ui/src/commonMain/kotlin/com/softartdev/notedelight/di/PreviewKoin.kt

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
package com.softartdev.notedelight.di
22

33
import androidx.compose.runtime.Composable
4+
import androidx.compose.runtime.CompositionLocalProvider
5+
import androidx.navigationevent.compose.LocalNavigationEventDispatcherOwner
6+
import androidx.navigationevent.compose.rememberNavigationEventDispatcherOwner
47
import org.koin.compose.KoinApplicationPreview
58
import org.koin.core.logger.Level
69
import org.koin.dsl.KoinConfiguration
@@ -14,7 +17,12 @@ fun PreviewKoin(content: @Composable () -> Unit) {
1417
includes(config)
1518
modules(sharedModules + uiModules)
1619
},
17-
content = content
20+
content = {
21+
val dispatcherOwner = rememberNavigationEventDispatcherOwner(parent = null)
22+
CompositionLocalProvider(LocalNavigationEventDispatcherOwner provides dispatcherOwner) {
23+
content()
24+
}
25+
}
1826
)
1927
}
2028

0 commit comments

Comments
 (0)