Skip to content

将CoroutineScope绑定到View的attachToWindow ~ detachedFromWindow期间范围。

License

Notifications You must be signed in to change notification settings

liu-wanshun/view-attach-window-coroutine-scope

Repository files navigation

View AttachToWindow CoroutineScope

jitpack GitHub license

参考AndroidX-KTX中的lifecycleScope,将CoroutineScope绑定到ViewattachToWindow ~ detachedFromWindow期间范围。

Rxjava版本请查看:https://github.com/liu-wanshun/AndroidDisposable

添加依赖

  1. 添加jitpack仓库
allprojects {
    repositories {
        maven { url "https://jitpack.io" }
    }
}
  1. 添加view-attach-window-coroutine-scope 依赖最新版(将Tag替换为jitpack 后面的数字)
dependencies {
    implementation "com.github.liu-wanshun:view-attach-window-coroutine-scope:Tag"
}

用法

val view: View = findViewById<View>(R.id.test)
// 注意:
// 仅在attachToWindow ~ detachedFromWindow 范围期间获取的attachWindowScope可以执行
// 在onDetachedFromWindow后cancel
view.attachWindowScope.launch {

}
// 实际常在自定义View内部使用,一般不在View外部使用

About

将CoroutineScope绑定到View的attachToWindow ~ detachedFromWindow期间范围。

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages