Does anyone have experience with "dependency injecting" Compose views into non-Compose shared (Android) modules? We have a module shared between our Android and AndroidTV client in which we have a fragment which should either show some Composable when on Android, or an XML-based view when on AndroidTV.
Before migrating to Compose we just had both Android and AndroidTV's views inside this module, but we'd like to avoid having the shared module depend on Compose itself should we ever migrate our AndroidTV views to Compose as well (which would result in conflicting dependencies).
🧵 1
Tom De Decker
09/01/2023, 1:20 PM
The only way I currently think this could work is by wrapping the composables inside a ComposeView and somehow passing it (or some kind of view provider like
(<params for composable>) -> View
) to the fragment inside the shared module.
Tom De Decker
09/01/2023, 1:22 PM
I'm not sure that this approach is valid, however, as I don't think it's generally a good idea to pass lambdas into a fragment (not serializable iirc?)
j
John Dior
09/01/2023, 3:09 PM
What if you wrapped the composable in a class, and the view in a class, make them implement a dummy interface, and then have a lazyinit of the interface type (or inject it with your framework). You would have to cast it based on the platform type though.