KevinnZou / compose-webview-multiplatform

WebView for JetBrains Compose Multiplatform
https://kevinnzou.github.io/compose-webview-multiplatform/
Apache License 2.0
305 stars 39 forks source link

Possibility of using with Koin #131

Open akiirax opened 1 month ago

akiirax commented 1 month ago

@KevinnZou

How to achieve being able to recreate the WebView instance ahead of usage through having it defined in a Koin single module?

Coming here from attempting to do this in low-level code on WKWebView and getting faced with multiple issues.

The target is to save the effort/time the platform takes to initialize the WebView and always maintains a ready-to-use instance.

KevinnZou commented 1 month ago

@akiirax Thank you for your feedback! In the Android version of this library, I did provide a factory method that allows developers to use a custom WebView object. However, in situations where the library is being used across multiple platforms, it may not be feasible to provide this method because WebView instances differ across various platforms. Do you have any suggestions on how to handle this?

cayolblake commented 1 month ago

@KevinnZou in iOS for example, I guess the possibility of defining the WKWebView in the .swift part of the project in a Koin single() would make sense and then using it afterwards down the road through injecting it using Koin as well in the Kotlin code.

Not sure if it's possible to do from the commonMain tho.

KevinnZou commented 1 month ago

@cayolblake It's easy to implement for a single platform, but seems to be impossible in CommonMain because platforms have different WebView objects and no common interface. You are welcome to submit a pull request if you have any ideas. Thank you in advance!

akiirax commented 1 month ago

@KevinnZou I guess implementing for platform modules rather than common will be great, if possible. It only makes sense also because that’ll be considered early enough to be instantiated even asynchronously and use/inject it later.