Skip to content

Commit 7f9ee8b

Browse files
committed
feat: allow height to change for pixel density to prevent bottom sheet handle from overlapping hardware like camera
1 parent c8d2970 commit 7f9ee8b

File tree

2 files changed

+15
-3
lines changed

2 files changed

+15
-3
lines changed

commandbar/src/main/java/com/commandbar/android/HelpHubWebView.kt

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import android.view.ViewGroup
99
import android.webkit.JavascriptInterface
1010
import android.webkit.WebChromeClient
1111
import android.webkit.WebResourceRequest
12-
import android.webkit.WebSettings
1312
import android.webkit.WebView
1413
import android.webkit.WebViewClient
1514
import androidx.coordinatorlayout.widget.CoordinatorLayout
@@ -20,6 +19,14 @@ import org.json.JSONObject
2019

2120
typealias FallbackActionCallback = ((action: Map<String, Any>) -> Unit)
2221

22+
fun Context.dpToPx(dp: Int): Int {
23+
return (dp * resources.displayMetrics.density).toInt()
24+
}
25+
26+
fun Context.pxToDp(px: Int): Float {
27+
return (px.toFloat() / resources.displayMetrics.density)
28+
}
29+
2330
class HelpHubWebView(context: Context, options: CommandBarOptions? = null, onFallbackAction: FallbackActionCallback? = null) : WebView(context) {
2431
private lateinit var options: CommandBarOptions;
2532
private lateinit var onFallbackAction: FallbackActionCallback
@@ -97,6 +104,8 @@ class HelpHubWebView(context: Context, options: CommandBarOptions? = null, onFal
97104
ViewGroup.LayoutParams.MATCH_PARENT
98105
)
99106

107+
108+
100109
webViewClient = object : WebViewClient() {
101110
override fun onPageFinished(view: WebView?, url: String?) {
102111
val snippet = getSnippet(options)
@@ -131,8 +140,10 @@ class HelpHubWebView(context: Context, options: CommandBarOptions? = null, onFal
131140

132141
// Adjust the height of the dialog to match the screen height
133142
val windowHeight = Resources.getSystem().displayMetrics.heightPixels
134-
dialog.behavior.peekHeight = windowHeight
135-
143+
val sheetHeight = windowHeight - context.dpToPx(40)
144+
dialog.behavior.peekHeight = sheetHeight
145+
this.layoutParams.height = sheetHeight
146+
dialog.behavior.maxHeight = sheetHeight
136147

137148
val bottomSheet = dialog.findViewById<View>(com.google.android.material.R.id.design_bottom_sheet);
138149
// Show the dialog using the post method to wait for the view to be fully measured and laid out

commandbar/src/main/res/values/styles.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
<style name="BottomSheetModalHandle" parent="Widget.Design.BottomSheet.Modal">
55
<item name="android:background">@drawable/shape_bottom_sheet_with_handle</item>
66
<item name="android:paddingTop">8dp</item>
7+
<item name="android:paddingBottom">4dp</item>
78
<item name="android:layout_height">match_parent</item>
89
</style>
910

0 commit comments

Comments
 (0)