Skip to content

Instantly share code, notes, and snippets.

@harry-private
Created January 23, 2022 18:21
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 harry-private/62355f38208e7b0cae4dd4cdad225e8b to your computer and use it in GitHub Desktop.
Save harry-private/62355f38208e7b0cae4dd4cdad225e8b to your computer and use it in GitHub Desktop.
For medium article How to add WebView in Jetpack Comose
var myView: WebView? = null
@SuppressLint("SetJavaScriptEnabled")
fun myWebViewFun(context: Context, urlToRender: String): WebView {
if (myView == null) {
myView = WebView(context).apply {
layoutParams = ViewGroup.LayoutParams(
ViewGroup.LayoutParams.MATCH_PARENT,
ViewGroup.LayoutParams.MATCH_PARENT
)
webViewClient = object : WebViewClient() {
override fun shouldOverrideUrlLoading(
view: WebView?,
request: WebResourceRequest?
): Boolean {
return false
}
}
settings.javaScriptEnabled = true
loadUrl(urlToRender)
}
}
return myView!!
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment