Updated on 2026-08-14

This commit is contained in:
Tangem 2020-12-11 16:59:23 +03:00
parent b9429d2710
commit 60a332149e
4 changed files with 55 additions and 6 deletions

View file

@ -0,0 +1,31 @@
package com.tangem.tap.common
import android.view.View
import android.view.ViewTreeObserver
/**
[REDACTED_AUTHOR]
*/
class GlobalLayoutStateHandler<T: View>(
private val view: T,
attachImmediately: Boolean = true
) : ViewTreeObserver.OnGlobalLayoutListener {
var onStateChanged: ((T) -> Unit)? = null
init {
if (attachImmediately) attach()
}
fun attach() {
view.viewTreeObserver.addOnGlobalLayoutListener(this)
}
fun detach() {
view.viewTreeObserver.removeOnGlobalLayoutListener(this)
}
override fun onGlobalLayout() {
onStateChanged?.invoke(view)
}
}