Do you have any sample code/project that using cor...
# coroutines
Do you have any sample code/project that using coroutines in the android custom view? I would like to learn the best practice that handle coroutines in custom view.
there are no best practices in coroutines in custom views:P coroutines should not live in the viewlevel. If you really have to, i guess you could cancel the scope in onViewDetached, maybe
My strategy is to avoid if possible and keep the view dumb.... network calls live in the VM since they have to survive config changes anyway and the view is only interested in the result in certain scenarios it might make sense to expose suspend functions from the View and launch the coroutines from the lifecycle owner if 1 and 2 don't work then I might consider creating a scope and what ☝️ suggested
New version of lifecycle library allows you access lifecycle scope of view' (Activity or Fragment), search for findViewTreeLifecycleOwner
🙌 1
Though, I agree, that in most cases you shouldn't launch coroutine from view (and extract business logic to VM), but coroutines are very useful on view if you use it to view-only related stuff, like animations
👍 1
yeah, I don’t see any issues with this use case to use coroutines