It’ll be amazing to use `function` approach instea...
# compose
h
It’ll be amazing to use
function
approach instead of
class
on Compose and SwiftUI both if possible. then my library code will be simpler and better(for SwiftUI View to use ViewModel on Kotlin, the library logic little bit complicate). also Destination sealed classes can be shared by SwiftUI and Compose both. it sounds nice. for that, I would like to ask two question. 1. When I check Jetcaster sample, It used viewModel in function like the below,
Copy code
val viewModel: HomeViewModel = viewModel()
when I checked, the viewModel’s lifecycle, it seems same with activity. before activity is destroyed, viewModel is alive continuously. sometimes, we want to cancel api when user go back from the page. for that we normally cleared viewModel. but, currently, It seems difficult to clear, (below is my analysis with not enough Compose undestanding, if it’s wrong, kindly understand, and it’ll be appreciated if someone explain) I think
viewModel()
function have to refer to
Navigator.backstack
and if the Destination still alive, then keep the ViewModel. otherwise, clear the viewModel when removed from the backstack. as ViewModel’s lifecycle seems to have to be same with Destination in Navigator.backstack. how about considering to connect Destination and ViewModel by some way? or, If there is better approach without clearing viewModel, kindly let me know. 2. question for Owl sample When navigation is from A to B, How to setResult on B and A receive the result? If Destination is not Parcelable, it’s possible to add lambda on destination like the below
Copy code
data class Course(val courseId: Long, val onResult: () -> Unit) : Destination()
but, as It’s Parcelable for keeping data on saved state. it looks not easy for A to receive result from B is there some way to cover this? Thanks for reading and taking care🙏