I have a structure today where my Screen Injects widgets, created as Fragments, from other Modules, using named references from Koin. Something like this:
val view2 by inject<Fragment>(named(FRAGMENT_VIEW_2)) {
parametersOf(
VALUE11,
VALUE12
)
}
val view2 by inject<Fragment>(named(FRAGMENT_VIEW_2)) {
parametersOf(VALUE22)
}
We are on a mission to replace some of these "Fragment Widgets" for Composable views.
Is there a similar approach to Injecting Fragments for a Composable View?
I don't think that is possible because Koin is designed to inject classes/instances, while Composables are functions that are not even encapsulated in a class.
What you could do, however, is to create a
Fragment
that contains aComposable
, and then inject thatFragment
the same way as you currently do. There is a dedicatedComposeView
view that you can use in your Fragment, as explained in the documentation:Then you inflate this layout in your
Fragment
like this: