WebView 不在 Compose 内滚动。我需要使用 Compose 将 WebView 放入 BottomSheet 中。即使我们使用NestedWebView或NestedScrollWebView , WebView 也不会滚动的问题。如果我将 WebView 放入 NestedScrollView 中,它仍然不会对滚动做出反应。
BottomSheetScaffold(
sheetContent = {
AndroidView(factory = {
NestedWebView(it).apply {
layoutParams = ViewGroup.LayoutParams(
ViewGroup.LayoutParams.MATCH_PARENT,
ViewGroup.LayoutParams.MATCH_PARENT
)
settings.domStorageEnabled = true
settings.javaScriptEnabled = true
settings.useWideViewPort = true
webViewClient = WebViewClient()
//loadUrl("https://contest.rippl.club/")
loadUrl("https://codeflarelimited.com")
}
})
}) {
}
Run Code Online (Sandbox Code Playgroud)
解决方法之一是使用 VerticalScroll 并将 webview 高度设置为 WRAP_CONTENT:
val scrollState = rememberScrollState()
AndroidView(modifier = Modifier.verticalScroll(scrollState), factory = {
WebView(it).apply {
layoutParams = ViewGroup.LayoutParams(
ViewGroup.LayoutParams.MATCH_PARENT,
ViewGroup.LayoutParams.WRAP_CONTENT
---//---
Run Code Online (Sandbox Code Playgroud)
但有很多网站无法使用wrap_content,例如因为像这个网站https://contest.rippl.club/ …