rickclephas / KMP-NativeCoroutines

Library to use Kotlin Coroutines from Swift code in KMP apps
MIT License
1.06k stars 31 forks source link

Support for setting values in a stateflow on iOS #169

Closed BasBuijsen closed 6 months ago

BasBuijsen commented 6 months ago

Hi there! I want to say that i love this library and use it in all of my KMP projects :).

There is one thing i run into quite often that i would like some improvement on and i would like to know what you think about this.

I use this library in combination with KMMViewModel to create viewmodels in KMP. I have multiple MutableStateFlows that i need to use as a binding variable on iOS but because of the way this library works, it only has a getter for these flows while it needs both a getter and a setter. I know that a setter for a flow wouldn't work because that would replace the whole Flow object. So i would like to add a setter that will call the .update {} of the flow to emit the value to it. Ofcourse this would only be added to a MutableStateFlow because in other cases this wouldn't be possible. This would solve the issue of not being able to create bindings on iOS from these variables with the $ syntax.

I would love to hear your opinion on this and if you think this would be a good idea. If you agree with me and this is a good solution then i will create a PR for this.

BasBuijsen commented 6 months ago

Im sorry i just figured out by going through the code that this does actually work but it only works for a MutableStateFlow. I was using .stateIn(...) and that created a StateFlow from my MutableStateFlow so that way it won't work.