Created
January 23, 2022 18:21
-
-
Save harry-private/62355f38208e7b0cae4dd4cdad225e8b to your computer and use it in GitHub Desktop.
For medium article How to add WebView in Jetpack Comose
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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