package com.marverenic.reader.utils

import android.view.View

inline fun <V : View> V.whenMeasured(crossinline action: V.() -> Unit) {
    if (isLaidOut) {
        action()
    } else {
        viewTreeObserver.addOnGlobalLayoutListener {
            action()
        }
    }
}

package com.marverenic.reader.utils

import android.view.View
import android.view.ViewTreeObserver

inline fun <V : View> V.whenMeasured(crossinline action: V.() -> Unit) {
    if (isLaidOut) {
        action()
    } else {
        viewTreeObserver.addOnGlobalLayoutListener(object : ViewTreeObserver.OnGlobalLayoutListener {
            override fun onGlobalLayout() {
                action()
                viewTreeObserver.removeOnGlobalLayoutListener(this)
            }
        })
    }
}

Fix listener not being released
Fix listener not being released

marverenic/Paper