Mark
07/07/2020, 5:52 AMFragment
subclass:
inline fun <T> Flow<T>.collectInViewScope(crossinline action: suspend (value: T) -> Unit) {
viewLifecycleOwner.lifecycleScope.launch {
collect(action)
}
}
But is there a way to declare this outside of the class (so it can be used from any Fragment
subclass, without having to pass in the Fragment
instance as an arg? A kind of extension function with added context of the call site. One could imagine inline <http://Fragment.fun|Fragment.fun> <T> Flow<T>.collectInViewScope(…)
Milan Hruban
07/07/2020, 6:17 AM