I am using Jetpack Compose and have a WebView wrapped in a AndroidView composable that looks like the following:
AndroidView(modifier = modifier, factory = { context ->
WebView(context).apply {
layoutParams = ViewGroup.LayoutParams(
ViewGroup.LayoutParams.MATCH_PARENT,
ViewGroup.LayoutParams.MATCH_PARENT
)
webViewClient = WebViewClient()
settings.javaScriptEnabled = true
}
}, update = { webView -> webView.loadUrl(url) })
In the legacy way, we could add a OnBackPressedDispatcher to the Activity to intercept the back press and navigate inside the WebView by accessing it via viewBinding for example with functions of the WebView like goBack() and to check if you can go back with canGoBack().
But how can we achieve the same with this Jetpack Compose approach?