Last active
July 21, 2019 15:08
-
-
Save HirogaKatageri/6c5837c060f4ee53110b38b8540722d5 to your computer and use it in GitHub Desktop.
SoftKeyboard or SoftInput Observer
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fun View.onScreenResize(onResize: (isScreenSmaller: Boolean) -> Unit) { | |
this.viewTreeObserver.addOnGlobalLayoutListener { | |
val r = Rect() | |
this.getWindowVisibleDisplayFrame(r) | |
val screenHeight = this.rootView.height | |
val keypadHeight = screenHeight - r.bottom | |
val ratio = 0.15 | |
if (keypadHeight > screenHeight * ratio) | |
onResize(true) | |
else | |
onResize(false) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment