A library which provides a Jetpack Compose wrapper around Android's WebView.
!!! warning This library is deprecated, and the API is no longer maintained. We recommend forking the implementation and customising it to your needs. The original documentation is below.
To implement this wrapper there are two key APIs which are needed: WebView
, which is provides the layout, and rememberWebViewState(url)
which provides some remembered state including the URL to display.
The basic usage is as follows:
val state = rememberWebViewState("https://example.com") WebView( state )
This will display a WebView in your Compose layout that shows the URL provided.
There is a larger sample in the sample app which can be found here. This sample also shows how to show a loading state.
By default, JavaScript is disabled in the WebView. To enable it or any other settings you can use the onCreated
callback.
WebView( state = webViewState, onCreated = { it.settings.javaScriptEnabled = true } )
By default the WebView will capture back presses/swipes when relevant and navigate the WebView back. This can be disabled via the parameter on the Composable.
WebView( ... captureBackPresses = false )
If you want to use a subclass of WebView
, or simply require more control over its instantiation, you can provide a factory.
WebView( ... factory = { context -> CustomWebView(context) } )
repositories { mavenCentral() } dependencies { implementation "com.google.accompanist:accompanist-webview:<version>" }