Updated on 2026-08-14
This commit is contained in:
parent
98402fd7c3
commit
f2697b357d
1 changed files with 10 additions and 0 deletions
|
|
@ -2,6 +2,7 @@ package com.tangem.tap.common
|
|||
|
||||
import android.view.View
|
||||
import android.view.ViewTreeObserver
|
||||
import timber.log.Timber
|
||||
|
||||
/**
|
||||
[REDACTED_AUTHOR]
|
||||
|
|
@ -13,16 +14,25 @@ class GlobalLayoutStateHandler<T: View>(
|
|||
|
||||
var onStateChanged: ((T) -> Unit)? = null
|
||||
|
||||
private var isAttached: Boolean = false
|
||||
|
||||
init {
|
||||
if (attachImmediately) attach()
|
||||
}
|
||||
|
||||
fun attach() {
|
||||
if (isAttached) {
|
||||
Timber.d("Already attached")
|
||||
return
|
||||
}
|
||||
|
||||
isAttached = true
|
||||
view.viewTreeObserver.addOnGlobalLayoutListener(this)
|
||||
}
|
||||
|
||||
fun detach() {
|
||||
view.viewTreeObserver.removeOnGlobalLayoutListener(this)
|
||||
isAttached = false
|
||||
}
|
||||
|
||||
override fun onGlobalLayout() {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue