Anyone using Decompose + Compose Multiplatform + K...
# decompose
Anyone using Decompose + Compose Multiplatform + Koin combination? If so is there any way to inject decompose components directly into compose functions with Koin? I know there is a example of someting similar Arkadii did for Droidcon app, but there he passes components into compose functions. What I want is basically the same thing, but injecting components into functions instead of passing them. If I’m not mistaken Koin doesn’t support that for multiplatform compose, but did somebody tried to do something like that or has some workaround to do so? 🙏
Perhaps you should be able to utilize Locals for this, which I guess Koin is using as well. You could create your own API for this. But Locals are discouraged for argument passing, I would just pass all arguments manually.
I don’t know what is that exactly, but I guess it is time to learn! 🥳 I will check that out, but I guess passing them as arguments is good enough. It introduces a bit of boilerplate with factories but that is nothing major. I was hoping there is something as simple as injecting VM in Android Compose, but I guess it is a bit too early for that 😄
That's not too early, that's by design 😀 Decompose doesn't populate the currently active child instance via Local because it's less compile-time safe. But perhaps you could write your own variant of the
function wrapping the original one and using Locals. You can read more about Locals here -
For instance, you may call ScreenB() by accident instead of ScreenA(). It will compile but crash at runtime. With the current approach you pass components manually, which is a bit more verbose. But it won't compile if you mess with functions.