Hello, I looking for feedbacks about the "best" si...
# compose-android
n
Hello, I looking for feedbacks about the "best" side-effect to use to configure a WebviewClient with a Webview in Compose. My usecase is passing some "plugins" to the
AccompanistWebViewClient
that will react to its different functions
onPageStarted
,
onPageFinished
, etc... My client looks like that:
Copy code
@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:
Copy code
@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? 🙂
1
s
DisposableEffect
is the way to go here imo
1