Skip to content

A WebView implementation in Compose as forked by Google's Accompanist repository.

License

Notifications You must be signed in to change notification settings

ivangarzab/composable-webview

Repository files navigation

badge-android badge-release

banner-image

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.

As Seen On

Medium: An Inquiry Into the Android WebView for Jetpack Compose

Setup

Import this library as a Gradle dependency in two simple steps:

  1. 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") }
}
  1. 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>")
}

Basic Usage

The simplest way to implement this wrapper is two use two main APIs from this library:

// Composable function
val state = rememberWebViewState("https://example.com")
WebView(state = state)

Enabling JavaScript

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 }
)

Capturing Back Actions

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 a WebView Implementation

Subclassing of the default WebView implementation is possible through the factory Composable:

WebView(
    ...
    factory = { context -> CustomWebView(context) }
)

Sample Application

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.

Upcoming Features

  • Pull to refresh ♻️
  • Website loading spinner ↻
  • Distribution through the Maven package 🚀

Let's Work Together!

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!

License

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.

About

A WebView implementation in Compose as forked by Google's Accompanist repository.

Resources

License

Stars

Watchers

Forks

Packages

No packages published