CoroutineAutoDispose
CoroutineAutoDispose copied to clipboard
There is a problem with lazy loading of fragments
The lazy load function will be executed only once,so If I use autoDisposeScope in it。 When i switch to another fragment,then come back,Button does not work properly。 such as:
import com.github.satoshun.coroutine.autodispose.view.autoDisposeScope
import kotlinx.coroutines.flow.*
import reactivecircus.flowbinding.android.view.clicks
class MyFragment : Fragment(){
fun initLazyView(){
button.clicks().sample(500).onEach {
block(this)
}.launchIn(button.autoDisposeScope)
}
}
because fragment hide triggered onViewDetachedFromWindow。
override fun onViewDetachedFromWindow(v: View) {
view.removeOnAttachStateChangeListener(this)
job.cancel()
}
Is there any way to avoid it?