I have following extension method. How can I reference the OnGlobalLayoutListener
that is passed into the addOnGLobalLayoutListener()
method? I need to pass the listener to the removeOnGlobalLayoutListener()
method.
fun View.OnGlobalLayout(callback:() -> Unit ): Unit{
this.viewTreeObserver.addOnGlobalLayoutListener {
if(android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.JELLY_BEAN) {
this.viewTreeObserver.removeOnGlobalLayoutListener(this);
}
else {
this.viewTreeObserver.removeGlobalOnLayoutListener(this);
}
callback();
}
}