I thought I’d try to run one of my compose apps in...
# compose-web
s
I thought I’d try to run one of my compose apps in the new alpha web. Ran into a hangup - How would I draw an SVG in compose web?
b
You need to add compose.web.svg dependency. Then it's the same api as in html
s
Thanks - looking for it!
You mean
"org.jetbrains.compose.web:web-svg-js:1.2.0-alpha01-dev675"
?
b
Yes, but compose plugin provides that typesafe acessor I've posted
s
I didn’t realize that was an accessor! Thanks
@Big Chungus This appears to be an API to build an SVG. I’ve got an SVG as a String. Is there any way for me to display it with this?
b
Ah, you might get lucky with attrs.ref and setting innerHtml on the native element?
Here are some snippets for you
Copy code
@OptIn(ExperimentalComposeWebSvgApi::class)
  Svg(attrs = {
    attr("width", "100")
    attr("height", "100")
    ref { element ->
      element.innerHTML = """
        <circle cx="50" cy="50" r="40" stroke="black" stroke-width="3" fill="red" />
      """.trimIndent()
      onDispose { }
    }
  })

  Div(attrs = {
      ref { element ->
        element.innerHTML = """
        <svg height="100" width="100">
          <circle cx="50" cy="50" r="40" stroke="black" stroke-width="3" fill="red" />
        </svg> 
      """.trimIndent()
        onDispose { }
      }
  })
s
this API is fairly inconvenient 😕
Am I able to use a Div inside of a web canvas application?
b
Intentionally so. One should avoid touching native DOM elements as much as possible when wrking with compose
Otherwise you risk desyncronised states
No clue about web canvas. Never tried that myself.
s
oh - I’m trying to do all of this in web canvas
b
Ah, then all my suggestions might be totally invalid.
s
ic thanks
j
Are there any examples about running apps with new alpha web?
s
yes - check the repo in the experimental/samples directory
f
Woah, compose web canvas alpha? Any links to announcement?
s
No announcements. Only side discussions here
j
Thanks for the tip Scott. Do you know if it’s possible to run compose multiplatform with android as well? None of the samples are including Android
s
Yes - it is. Look at the primary samples, not the experimental samples and you’ll see examples of that.