A WebView implementation in Compose as forked by Google's Accompanist repository.
With the Google's Accompanist repository deprecating it's WebView implementation starting on August 2023, I decided to take their advice and fork that piece of the library in order to continue maintaining their implementation myself, as well as making it public so that other people may leverage it too.
For more information, please check out their official documentation.
Medium: An Inquiry Into the Android WebView for Jetpack Compose
Import this library as a Gradle dependency in two simple steps:
- Add Jitpack as a repository inside your Gradle build file
// build.gradle
repositories {
...
maven { url 'https://jitpack.io' }
}
// build.gradle.kts
repositories {
...
maven { url = uri("https://jitpack.io") }
}
- Bring in dependency inside your module-level Gradle build file
// build.gradle
dependencies {
...
implementation "com.ivangarzab:composable-webview:<latest_version>"
}
// build.gradle.kts
dependencies {
...
implementation("com.ivangarzab:composable-webview:<latest_version>")
}
The simplest way to implement this wrapper is two use two main APIs from this library:
- The
WebView
Composable - The
rememberWebViewState(url: String)
function to take care of its state
// Composable function
val state = rememberWebViewState("https://example.com")
WebView(state = state)
JavaScript is disabled by default in the WebView
implementation.
In order to enable this feature -- or any other settings -- you can do so inside the onCreated
callback:
WebView(
state = state
onCreated = { it.settings.javaScriptEnabled = true }
)
Back Actions -- such as back button presses or back gestures -- are captured by default in the WebView
implementation.
This behavior can be disabled via a parameter in the Composable:
WebView(
...
captureBackPresses = false
)
Subclassing of the default WebView
implementation is possible through the factory
Composable:
WebView(
...
factory = { context -> CustomWebView(context) }
)
Make sure to check out the sample app in MainActivity
inside the :sample
module for a more
complete example on how to use this library.
- Pull to refresh ♻️
- Website loading spinner ↻
- Distribution through the Maven package 🚀
See an improvement that you'd like to see in this library? Or an impeding bug that needs to be squashed?
Feel free to drop a Bug Report 🐛 or a Feature Request 📈 ticket for consideration!
Wanna get something done yourself? 🔥
Make sure to fork the library, and submit a Pull Request with the pre-defined guidelines!
The composable-webview
library is distributed under the terms and conditions of the Apache License (Version 2).
Please refer to the LICENSE page for more information.