@@ -7,16 +7,15 @@ import android.graphics.Color
7
7
import android.view.View
8
8
import android.view.ViewGroup
9
9
import android.webkit.JavascriptInterface
10
- import android.webkit.ValueCallback
11
10
import android.webkit.WebChromeClient
12
11
import android.webkit.WebResourceRequest
12
+ import android.webkit.WebSettings
13
13
import android.webkit.WebView
14
14
import android.webkit.WebViewClient
15
15
import androidx.coordinatorlayout.widget.CoordinatorLayout
16
16
import com.commandbar.R
17
17
import com.google.android.material.bottomsheet.BottomSheetDialog
18
18
import org.json.JSONObject
19
- import java.lang.Compiler.command
20
19
21
20
22
21
typealias FallbackActionCallback = ((action: Map <String , Any >) -> Unit )
@@ -32,6 +31,7 @@ fun Context.pxToDp(px: Int): Float {
32
31
class HelpHubWebView (context : Context , options : CommandBarOptions ? = null , articleId : Int? = null , onFallbackAction : FallbackActionCallback ? = null ) : WebView(context) {
33
32
private lateinit var options: CommandBarOptions ;
34
33
private lateinit var onFallbackAction: FallbackActionCallback
34
+ private var bottomSheetDialog: BottomSheetDialog ? = null
35
35
private var articleId: Int?
36
36
37
37
init {
@@ -110,6 +110,10 @@ class HelpHubWebView(context: Context, options: CommandBarOptions? = null, artic
110
110
ViewGroup .LayoutParams .MATCH_PARENT
111
111
)
112
112
113
+ if (options.launchCode == " local" ) {
114
+ settings.mixedContentMode = WebSettings .MIXED_CONTENT_ALWAYS_ALLOW
115
+ }
116
+
113
117
114
118
webViewClient = object : WebViewClient () {
115
119
override fun onPageFinished (view : WebView ? , url : String? ) {
@@ -141,30 +145,35 @@ class HelpHubWebView(context: Context, options: CommandBarOptions? = null, artic
141
145
142
146
fun openBottomSheetDialog () {
143
147
// Create the BottomSheetDialog
144
- var dialog = BottomSheetDialog (context, R .style.HelpHubBottomSheet )
148
+ bottomSheetDialog = BottomSheetDialog (context, R .style.HelpHubBottomSheet )
145
149
val coordinatorLayout = CoordinatorLayout (context).apply {
146
150
layoutParams = ViewGroup .LayoutParams (ViewGroup .LayoutParams .MATCH_PARENT , ViewGroup .LayoutParams .MATCH_PARENT )
147
151
addView(this @HelpHubWebView)
148
152
}
149
153
150
- dialog .setContentView(coordinatorLayout)
154
+ bottomSheetDialog? .setContentView(coordinatorLayout)
151
155
152
156
// Adjust the height of the dialog to match the screen height
153
157
val windowHeight = Resources .getSystem().displayMetrics.heightPixels
154
158
val sheetHeight = windowHeight - context.dpToPx(40 )
155
- dialog .behavior.peekHeight = sheetHeight
159
+ bottomSheetDialog? .behavior? .peekHeight = sheetHeight
156
160
this .layoutParams.height = sheetHeight
157
- dialog .behavior.maxHeight = sheetHeight
161
+ bottomSheetDialog? .behavior? .maxHeight = sheetHeight
158
162
159
- val bottomSheet = dialog .findViewById<View >(com.google.android.material.R .id.design_bottom_sheet);
163
+ val bottomSheet = bottomSheetDialog? .findViewById<View >(com.google.android.material.R .id.design_bottom_sheet);
160
164
// Show the dialog using the post method to wait for the view to be fully measured and laid out
161
- dialog .show()
165
+ bottomSheetDialog? .show()
162
166
163
167
if (bottomSheet != null ) {
164
168
bottomSheet.layoutParams.height = ViewGroup .LayoutParams .MATCH_PARENT ;
165
169
}
166
170
}
167
171
172
+ fun closeBottomSheetDialog () {
173
+ bottomSheetDialog?.dismiss()
174
+ bottomSheetDialog = null
175
+ this .destroy()
176
+ }
168
177
169
178
companion object {
170
179
0 commit comments