@@ -9,7 +9,6 @@ import android.view.ViewGroup
9
9
import android.webkit.JavascriptInterface
10
10
import android.webkit.WebChromeClient
11
11
import android.webkit.WebResourceRequest
12
- import android.webkit.WebSettings
13
12
import android.webkit.WebView
14
13
import android.webkit.WebViewClient
15
14
import androidx.coordinatorlayout.widget.CoordinatorLayout
@@ -20,6 +19,14 @@ import org.json.JSONObject
20
19
21
20
typealias FallbackActionCallback = ((action: Map <String , Any >) -> Unit )
22
21
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
+
23
30
class HelpHubWebView (context : Context , options : CommandBarOptions ? = null , onFallbackAction : FallbackActionCallback ? = null ) : WebView(context) {
24
31
private lateinit var options: CommandBarOptions ;
25
32
private lateinit var onFallbackAction: FallbackActionCallback
@@ -97,6 +104,8 @@ class HelpHubWebView(context: Context, options: CommandBarOptions? = null, onFal
97
104
ViewGroup .LayoutParams .MATCH_PARENT
98
105
)
99
106
107
+
108
+
100
109
webViewClient = object : WebViewClient () {
101
110
override fun onPageFinished (view : WebView ? , url : String? ) {
102
111
val snippet = getSnippet(options)
@@ -131,8 +140,10 @@ class HelpHubWebView(context: Context, options: CommandBarOptions? = null, onFal
131
140
132
141
// Adjust the height of the dialog to match the screen height
133
142
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
136
147
137
148
val bottomSheet = dialog.findViewById<View >(com.google.android.material.R .id.design_bottom_sheet);
138
149
// Show the dialog using the post method to wait for the view to be fully measured and laid out
0 commit comments