Is there an integration path where I can load a Co...
# compose-web
m
Is there an integration path where I can load a Composable using compose-web in a WebView which is in compose-android? (I guess some version of the android target depending on a separate web target)
y
does this fit what your looking for: https://github.com/KevinnZou/compose-webview-multiplatform. It provides a composable webview component for jetpack compose and other platforms that can load a url or html content
m
No. For example, if I already have an app with a WebView, is it possible to load a composable into that WebView using compose-web (from the same project)
c
Compose web is meant to be deployed and consumed via HTML and JS/WASM. In the Webview you’d just call the URL you deployed your webapp.
Or if you have it “shared” as Compose Multiplatform. you can consume the
@Composable
direclty in Android without the need of a webview.
b
if you need it in an existing web app, you need to present to it the canvas:
Copy code
<!DOCTYPE html>
<html lang="en">
<head>
    <script type="application/javascript" src="skiko.js"></script>
    <script type="application/javascript" src="composeApp.js"></script>
</head>
<body>
    //existing content
    <canvas id="ComposeTarget"></canvas> 
    //existing content
</body>
</html>

........

@OptIn(ExperimentalComposeUiApi::class)
fun main() {
    onWasmReady {
        CanvasBasedWindow(canvasElementId = "ComposeTarget") { 
            App() 
        }
    }
}
if you need more than one compose web "app" in the same page. its going to be a bit of a can of worms. you are better off with multiple CanvasBasedWindow from one single module (each targeting its own canvas), but i think its horrible because you will endup wih an even bigger bundle.
👍 1