Nino
03/31/2025, 7:37 AMAccompanistWebViewClient
that will react to its different functions onPageStarted
, onPageFinished
, etc...
My client looks like that:
@Stable
class FooWebViewClient : AccompanistWebViewClient() {
var plugins: Iterable<FooWebViewClientPlugin> = emptyList()
override fun onPageStarted(view: WebView, url: String?, favicon: Bitmap?) {
super.onPageStarted(view, url, favicon)
if (url == null) return
plugins.forEach { plugin -> plugin.onPageStarted(view, url, favicon) }
}
...
And my composable looks like that:
@Composable
fun FooWebView(
...
plugins: Iterable<FooWebViewClientPlugin>? = null,
) {
val currentConfiguration = LocalFooWebViewConfiguration.current
val configurationPlugins = currentConfiguration.plugins
val client = remember { FooWebViewClient() }
// !! Is launched effect the correct way to go?
LaunchedEffect(plugins, configurationPlugins) {
client.plugins = (plugins ?: emptyList()) + (configurationPlugins ?: emptyList())
}
com.google.accompanist.web.WebView(
client = client,
...
Now, I don't know which side effect to use. Should I use:
• a simple keyed remember
to create the Client (thus, avoiding the var
in the Client because I pass the plugins in the constructor)
• a LaunchedEffect
to avoid re-creating the client
• a DisposableEffect
with an empty onDispose{}
to avoid creating a coroutine (from the LaunchedEffect
)
This is very specific but can you give me your thoughts about this? 🙂shikasd
03/31/2025, 1:42 PMDisposableEffect
is the way to go here imo