https://kotlinlang.org logo
#compose-web
Title
# compose-web
k

Koneko Toujou

02/06/2023, 2:26 PM
you cannot create a composable simply from javascript in Compose For Web, right? eg
Copy code
download("some_page/compose-app.js")
run("app.js")
h

hfhbd

02/06/2023, 2:49 PM
What do you mean? Your compose web app is just a regular kotlin js project resulting in a normal js file you can fetch and run.
k

Koneko Toujou

02/06/2023, 3:16 PM
could such be used for a scriptable ui binding such as lua
h

hfhbd

02/06/2023, 3:19 PM
If you are able to connect lua with js, sure.
k

Koneko Toujou

02/06/2023, 3:57 PM
would such benifit from recomposability ?
also how would the js for compose look like?
like is it possible to create and add compose ui directly from js
h

hfhbd

02/06/2023, 4:07 PM
Could you please say, what you really try to archive? All the questions are somehow vague. I don't know how you want to execute lua in your browser and how to pass parameters from Lua to Kotlin. Compose is a Kotlin specifc compiler plugin for Kotlin code. You can use Compose Web to use declartive @Composable functions rendering UI in your browser written in Kotlin. Of course you can dynamically change the UI based on data.
k

Koneko Toujou

02/06/2023, 4:08 PM
alright
so either way we require kotlin to actually build the composable ui as declerative for both Android, Desktop, and Web
and sorry
h

hfhbd

02/06/2023, 4:14 PM
It depends. First at all, Compose is a Kotlin compiler plugin to create a tree changing over time. If you want to use this tree to get UI, you use this tree to render your underlying UI, for example on web it is plain hmlt dom, and on android and desktop skia (a c grafic lib) is used. Of course, the wrapper needs to be written in Kotlin.
Or use the experimental ui implementations like compose web canvas using canvas or iOS using native UIKit (written in objective-c).
k

Koneko Toujou

02/06/2023, 4:16 PM
for example, creating the UI from JNI interop calls,
JNI <-> Java/Kotlin -> UI api
h

hfhbd

02/06/2023, 4:18 PM
It really depends what you are passing over JNI. Of course you can pass data and create your views like you do with any other data source. If you want to call the composable functions directly from jni, don't do it.
k

Koneko Toujou

02/06/2023, 4:20 PM
eg
Copy code
void * text = CreateText("hello"); // creates text object on java/kotlin side
void * box = CreateBox(); // creates box object on java/kotlin side
AddComponent(box, text); // reparents [text] to [box] such that [box] contains 1 child: [text], on java/kotlin side
h

hfhbd

02/06/2023, 4:22 PM
Compose is declarative based on data. Your code is imperative based on function calls. So no, calling compose functions from JNI does not work at all. You should pass the data you want to show over JNI.
k

Koneko Toujou

02/06/2023, 4:22 PM
alright
44 Views