google / accompanist

A collection of extension libraries for Jetpack Compose
https://google.github.io/accompanist
Apache License 2.0
7.43k stars 598 forks source link

[WebView] Custom URL loading has only one white line #1506

Closed ruirui1128 closed 1 year ago

ruirui1128 commented 1 year ago

Describe the bug

1 Use "https:google.com" to display 2 Use your own URL but it doesn't display

3 But I use XML the traditional way, it's all fine

Screenshots

微信图片_20230203192844

微信图片_20230203192857

code

setContent {
            val systemController = rememberSystemUiController()
            LaunchedEffect(key1 = Unit) {
                systemController.setStatusBarColor(Color.Transparent, true)
            }
            M3Theme {
                Surface(
                    modifier = Modifier.fillMaxSize(),
                    color = MaterialTheme.colors.background
                ) {
                    Box(modifier = Modifier
                        .fillMaxSize()
                        .background(Color.Black)) {
                        val state = rememberWebViewState(viewModel.url.value ?: "")

                        WebView(
                            state,
                            modifier = Modifier
                                .fillMaxSize()
                                .absolutePadding(top = 25.dp),
                            onCreated = {
                                it.settings.javaScriptEnabled = true
                            },
                        )
                    }

                }

            }
        }

xml its all ok

viewBinding.webView.also {
            it.settings.javaScriptEnabled = true
            it.loadUrl("${url}")
        }

Environment: