stream-chat-swiftui icon indicating copy to clipboard operation
stream-chat-swiftui copied to clipboard

ViewFactory should be @MainActor constrained

Open swizzlr opened this issue 11 months ago • 3 comments

What are you trying to achieve?

I have views that depend on MainActor isolated view models. In order to initialize my views I need to retrieve these MainActor isolated dependencies that are retrieved via "@Inject" in the viewfactory. Since the viewfactory methods are nonisolated, I'm not able to access these - and if I annotate the methods as @MainActor, they do not satisfy the protocol requirements.

If possible, how can you achieve this currently?

Maybe I could try injecting them directly into the views?

What would be the better way?

Since SwiftUI Views are MainActor isolated to begin with, and the ViewFactory is invoked from Views in a MainActor isolated context, it seems reasonable to constrain the ViewFactory to MainActor

GetStream Environment

GetStream Chat version: 4.61 GetStream Chat frameworks: StreamChat, StreamChatSwiftUI iOS version: any Swift version: 6 Xcode version: 16.2 Device: any

Additional context

n/a

swizzlr avatar Jan 17 '25 19:01 swizzlr