Coverage Summary for Class: DataBindingLifecycleOwnerUtilKt (kr.open.library.simple_ui.xml.ui.layout.base.bind)
| Class |
Method, %
|
Branch, %
|
Line, %
|
Instruction, %
|
| DataBindingLifecycleOwnerUtilKt |
100%
(1/1)
|
14.3%
(2/14)
|
33.3%
(3/9)
|
20%
(10/50)
|
| DataBindingLifecycleOwnerUtilKt$bindLifecycleOwnerOnce$$inlined$doOnLayout$1 |
0%
(0/2)
|
|
| Total |
33.3%
(1/3)
|
14.3%
(2/14)
|
33.3%
(3/9)
|
20%
(10/50)
|
package kr.open.library.simple_ui.xml.ui.layout.base.bind
import android.view.View
import androidx.databinding.ViewDataBinding
import androidx.lifecycle.LifecycleOwner
import androidx.lifecycle.findViewTreeLifecycleOwner
import kr.open.library.simple_ui.xml.extensions.view.doOnLayout
/**
* Sets LifecycleOwner for DataBinding with a one-time layout retry if needed.<br><br>
* DataBinding에 LifecycleOwner를 설정하고 필요 시 레이아웃 완료 시점에 1회 재시도합니다.<br>
*
* @param binding The target ViewDataBinding instance.<br><br>
* 대상 ViewDataBinding 인스턴스입니다.<br>
*/
internal fun View.bindLifecycleOwnerOnce(binding: ViewDataBinding) {
val owner = findViewTreeLifecycleOwner() ?: (context as? LifecycleOwner)
if (owner != null) {
binding.lifecycleOwner = owner
return
}
doOnLayout {
if (!isAttachedToWindow) return@doOnLayout
val retryOwner = findViewTreeLifecycleOwner() ?: (context as? LifecycleOwner)
if (retryOwner != null) {
binding.lifecycleOwner = retryOwner
}
}
}