CoroutineAutoDispose icon indicating copy to clipboard operation
CoroutineAutoDispose copied to clipboard

There is a problem with lazy loading of fragments

Open iDeMonnnnnn opened this issue 3 years ago • 0 comments

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?

iDeMonnnnnn avatar Aug 04 '22 09:08 iDeMonnnnnn