Closed osrl closed 3 months ago
For a workaround, I used .task and asyncSequence
function
onChange
only requires a value, which is why it's working for your @NativeCoroutinesState
property.
A SharedFlow
doesn't have a single value, but it does have a replayCache
. You could try and use that as the value:
.onChange(of: eventDispatcher.event2ReplayCache) { event in }
onReceive
requires a Combine Publisher. You can create a publisher for any kind of flow:
let publisher = createPublisher(for: eventDispatcher.event2)
One thing to be aware of is that this will create a new publisher and therefore a new Flow collection every time.
So you would probably need to store this publisher in a viewmodel or something instead of calling the createPublisher(for:)
function in your SwiftUI body.
I have this flows in my kotlin code:
But I can't use shared flow on my swift code.
I also tried without
$
. Is it possible to use shared flows with onChange and onReceive modifiers?