Skip to content

Commit 91e20d2

Browse files
committed
fix(android): adjust WebView height manually on Android 10 when keyboard is visible
1 parent d442c09 commit 91e20d2

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

android/src/main/java/com/formbricks/android/webview/FormbricksFragment.kt

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@ import android.app.Activity.RESULT_OK
55
import android.app.Dialog
66
import android.content.Intent
77
import android.graphics.Color
8+
import android.graphics.Rect
89
import android.net.Uri
10+
import android.os.Build
911
import android.os.Bundle
1012
import android.os.Handler
1113
import android.os.Looper
@@ -178,6 +180,25 @@ class FormbricksFragment(val hiddenFields: Map<String, Any>? = null) : BottomShe
178180
return
179181
}
180182

183+
if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.Q) {
184+
val rootView = dialog?.window?.decorView?.findViewById<View>(android.R.id.content)
185+
rootView?.viewTreeObserver?.addOnGlobalLayoutListener {
186+
val r = Rect()
187+
rootView.getWindowVisibleDisplayFrame(r)
188+
val screenHeight = rootView.rootView.height
189+
val keyboardHeight = screenHeight - r.bottom
190+
if (keyboardHeight > screenHeight * 0.15) {
191+
// Keyboard is open – minimize WebView
192+
binding.formbricksWebview.layoutParams.height = r.bottom - binding.formbricksWebview.top
193+
binding.formbricksWebview.requestLayout()
194+
} else {
195+
// Keyboard closed
196+
binding.formbricksWebview.layoutParams.height = ViewGroup.LayoutParams.MATCH_PARENT
197+
binding.formbricksWebview.requestLayout()
198+
}
199+
}
200+
}
201+
181202
dialog?.window?.setDimAmount(0.0f)
182203
binding.formbricksWebview.setBackgroundColor(Color.TRANSPARENT)
183204
binding.formbricksWebview.let {

0 commit comments

Comments
 (0)