OCWebView
This is a Composable function that creates a WebView for our Android Application. It uses Accompanist's WebView library for managing WebViews in Jetpack Compose.
Usage
@Composable
fun WebViewScreen() {
OCWebView(
urlToLoad = "https://example.com",
title = "Example",
showTopToolbar = true,
enableToolbar = false,
onCloseWebView = { /* Handle WebView close event */ }
)
}
Parameters
urlToLoad
: The URL to be loaded in the WebView.title
: The title to be displayed in the top toolbar.showTopToolbar
: A boolean to control whether the top toolbar is shown.enableToolbar
: A boolean to control whether the toolbar (with the back, refresh, and forward buttons) should be enabled.allowFileAccess
: A boolean to control whether file access should be allowed in the WebView. This should be enabled only if it's absolutely necessary.client
: An AccompanistWebViewClient instance to observe WebView events.chromeClient
: An AccompanishWebChromeClient instance to manage interactions with the WebView such as video handling, geolocation, console messages and others.onCloseWebView:
: A callback block to handle the WebView close event.
This Composable function uses Accompanist's WebView, which uses Android's WebView under the hood. It also shows a loading spinner when the WebView is loading a page. It has an inbuilt navigation toolbar that includes buttons for Back, Forward, and Refresh operations. On dispose, it clears all the cookies to maintain user's privacy.