Updated on 2026-08-14
This commit is contained in:
parent
b9429d2710
commit
60a332149e
4 changed files with 55 additions and 6 deletions
|
|
@ -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)
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue