Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save HirogaKatageri/6c5837c060f4ee53110b38b8540722d5 to your computer and use it in GitHub Desktop.
Save HirogaKatageri/6c5837c060f4ee53110b38b8540722d5 to your computer and use it in GitHub Desktop.
SoftKeyboard or SoftInput Observer
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