rickclephas / KMP-ObservableViewModel

Library to use AndroidX/Kotlin ViewModels with SwiftUI
MIT License
569 stars 29 forks source link

Experimental lifetime fix #40

Closed humblehacker closed 1 year ago

humblehacker commented 1 year ago

Looks like StateViewModel needs the same fix.

rickclephas commented 1 year ago

Thanks for looking into this! I am afraid this approach won't work though. Once the ObservableViewModel is deallocated the Kotlin ViewModel will be cleared, closing the CoroutineScope. Resulting in any subsequent page views to only contain static data, as can be seen with the TimeTravelViewModel.

This however did make me think some more about the responsibilities. Since the KMMViewModel is keeping a reference to the child KMMViewModel. It would be the responsibility of the Swift ObservableViewModel of said KMMViewModel to keep a reference to the ObservableViewModels of the child KMMViewModels.

Could you take a look at #41?

humblehacker commented 1 year ago

Closing this in favor of #41