https://kotlinlang.org logo
Join the conversationJoin Slack
Channels
100daysofcode
100daysofkotlin
100daysofkotlin-2021
advent-of-code
aem
ai
alexa
algeria
algolialibraries
amsterdam
android
android-architecture
android-databinding
android-studio
androidgithubprojects
androidthings
androidx
androidx-xprocessing
anime
anko
announcements
apollo-kotlin
appintro
arabic
argentina
arkenv
arksemdevteam
armenia
arrow
arrow-contributors
arrow-meta
ass
atlanta
atm17
atrium
austin
australia
austria
awesome-kotlin
ballast
bangladesh
barcelona
bayarea
bazel
beepiz-libraries
belgium
berlin
big-data
books
boston
brazil
brikk
budapest
build
build-tools
bulgaria
bydgoszcz
cambodia
canada
carrat
carrat-dev
carrat-feed
chicago
chile
china
chucker
cincinnati-user-group
cli
clikt
cloudfoundry
cn
cobalt
code-coverage
codeforces
codemash-precompiler
codereview
codingame
codingconventions
coimbatore
collaborations
colombia
colorado
communities
competitive-programming
competitivecoding
compiler
compose
compose-android
compose-desktop
compose-hiring
compose-ios
compose-mp
compose-ui-showcase
compose-wear
compose-web
connect-audit-events
corda
cork
coroutines
couchbase
coursera
croatia
cryptography
cscenter-course-2016
cucumber-bdd
cyprus
czech
dagger
data2viz
databinding
datascience
dckotlin
debugging
decompose
decouple
denmark
deprecated
detekt
detekt-hint
dev-core
dfw
docs-revamped
dokka
domain-driven-design
doodle
dsl
dublin
dutch
eap
eclipse
ecuador
edinburgh
education
effective-kotlin
effectivekotlin
emacs
embedded-kotlin
estatik
event21-community-content
events
exposed
failgood
fb-internal-demo
feed
firebase
flow
fluid-libraries
forkhandles
forum
fosdem
fp-in-kotlin
framework-elide
freenode
french
fritz2
fuchsia
functional
funktionale
gamedev
ge-kotlin
general-advice
georgia
geospatial
german-lang
getting-started
github-workflows-kt
glance
godot-kotlin
google-io
gradle
graphic
graphkool
graphql
graphql-kotlin
graviton-browser
greece
grpc
gsoc
gui
hackathons
hacktoberfest
hamburg
hamkrest
helios
helsinki
hexagon
hibernate
hikari-cp
hire-me
hiring
hongkong
hoplite
http4k
hungary
hyderabad
image-processing
india
indonesia
inkremental
intellij
intellij-plugins
intellij-tricks
internships
introduce-yourself
io
ios
iran
israel
istanbulcoders
italian
jackson-kotlin
jadx
japanese
jasync-sql
java-to-kotlin-refactoring
javadevelopers
javafx
javalin
javascript
jdbi
jhipster-kotlin
jobsworldwide
jpa
jshdq
juul-libraries
jvm-ir-backend-feedback
jxadapter
k2-early-adopters
kaal
kafka
kakao
kalasim
kapt
karachi
karg
karlsruhe
kash_shell
kaskade
kbuild
kdbc
kgen-doc-tools
kgraphql
kinta
klaxon
klock
kloudformation
kmdc
kmm-español
kmongo
knbt
knote
koalaql
koans
kobalt
kobweb
kodein
kodex
kohesive
koin
koin-dev
komapper
kondor-json
kong
kontent
kontributors
korau
korean
korge
korim
korio
korlibs
korte
kotest
kotest-contributors
kotless
kotlick
kotlin-asia
kotlin-beam
kotlin-by-example
kotlin-csv
kotlin-data-storage
kotlin-foundation
kotlin-fuel
kotlin-in-action
kotlin-inject
kotlin-latam
kotlin-logging
kotlin-multiplatform-contest
kotlin-mumbai
kotlin-native
kotlin-pakistan
kotlin-plugin
kotlin-pune
kotlin-roadmap
kotlin-samples
kotlin-sap
kotlin-serbia
kotlin-spark
kotlin-szeged
kotlin-website
kotlinacademy
kotlinbot
kotlinconf
kotlindl
kotlinforbeginners
kotlingforbeginners
kotlinlondon
kotlinmad
kotlinprogrammers
kotlinsu
kotlintest
kotlintest-devs
kotlintlv
kotlinultimatechallenge
kotlinx-datetime
kotlinx-files
kotlinx-html
kotrix
kotson
kovenant
kprompt
kraph
krawler
kroto-plus
ksp
ktcc
ktfmt
ktlint
ktor
ktp
kubed
kug-leads
kug-torino
kvision
kweb
lambdaworld_cadiz
lanark
language-evolution
language-proposals
latvia
leakcanary
leedskotlinusergroup
lets-have-fun
libgdx
libkgd
library-development
linkeddata
lithuania
london
losangeles
lottie
love
lychee
macedonia
machinelearningbawas
madrid
malaysia
mathematics
meetkotlin
memes
meta
metro-detroit
mexico
miami
micronaut
minnesota
minutest
mirror
mockk
moko
moldova
monsterpuzzle
montreal
moonbean
morocco
motionlayout
mpapt
mu
multiplatform
mumbai
munich
mvikotlin
mvrx
myndocs-oauth2-server
naming
navigation-architecture-component
nepal
new-mexico
new-zealand
newname
nigeria
nodejs
norway
npm-publish
nyc
oceania
ohio-kotlin-users
oldenburg
oolong
opensource
orbit-mvi
osgi
otpisani
package-search
pakistan
panamá
pattern-matching
pbandk
pdx
peru
philippines
phoenix
pinoy
pocketgitclient
polish
popkorn
portugal
practical-functional-programming
proguard
prozis-android-backup
pyhsikal
python
python-contributors
quasar
random
re
react
reaktive
realm
realworldkotlin
reductor
reduks
redux
redux-kotlin
refactoring-to-kotlin
reflect
refreshversions
reports
result
rethink
revolver
rhein-main
rocksdb
romania
room
rpi-pico
rsocket
russian
russian_feed
russian-kotlinasfirst
rx
rxjava
san-diego
science
scotland
scrcast
scrimage
script
scripting
seattle
serialization
server
sg-user-group
singapore
skia-wasm-interop-temp
skrape-it
slovak
snake
sofl-user-group
southafrica
spacemacs
spain
spanish
speaking
spek
spin
splitties
spotify-mobius
spring
spring-security
squarelibraries
stackoverflow
stacks
stayhungrystayfoolish
stdlib
stlouis
strife-discord-lib
strikt
students
stuttgart
sudan
swagger-gradle-codegen
swarm
sweden
swing
swiss-user-group
switzerland
talking-kotlin
tallinn
tampa
teamcity
tegal
tempe
tensorflow
terminal
test
testing
testtestest
texas
tgbotapi
thailand
tornadofx
touchlab-tools
training
tricity-kotlin-user-group
trójmiasto
truth
tunisia
turkey
turkiye
twitter-feed
uae
udacityindia
uk
ukrainian
uniflow
unkonf
uruguay
utah
uuid
vancouver
vankotlin
vertx
videos
vienna
vietnam
vim
vkug
vuejs
web-mpp
webassembly
webrtc
wimix_sentry
wwdc
zircon
Powered by Linen
compose-web
  • a

    Ayfri

    08/01/2022, 12:48 PM
    Hi, is there a simple way to insert an element into a Text() ? Like
    ${Br()}
    into a raw string ? For now it just prints the result of the method which is
    kotlin.Unit
    h
    b
    m
    • 4
    • 24
  • u

    谢朋刚

    08/02/2022, 7:14 AM
    Hi, I created a data class in kotlin :
    data class Line(
        val lng: Double,
        val lat: Double,
    )
    I create an object of Line and parse this object to javascript, the field's name changed.
  • u

    谢朋刚

    08/02/2022, 7:14 AM
    {"_lng_0":116.397461,"_lat_0":39.909186,"_$stable_57":0}
    c
    • 2
    • 3
  • u

    谢朋刚

    08/02/2022, 7:15 AM
    if I want to keep the field's name as it is in kotlin , what should I do?
    r
    b
    • 3
    • 4
  • e

    Eduardo Zuza

    08/03/2022, 2:08 AM
    Please, how to put the items inside the select for the user to choose an option? compose-web
    Div(attrs = { style { id("seAdmRet"); display(DisplayStyle.Block) }; classes("form-group") }) {
                Span { Text("Opção AdmRet - 1") }
                Select(attrs = { classes("custom-select", "mr-sm-2", "dlg-100") }
                ) {                
    //                TextInput("ola1","GD")
    //                Text( "opa")
    //                 Text("olá")
                }
            }
    t
    • 2
    • 2
  • a

    Ayfri

    08/03/2022, 9:56 PM
    Hi, just a random thoughts I have, could we use Kotlin-Wrappers to better implement the CSS API and not reinvent the wheel ? It seems more complete that the API CfW have and as a lot is generated it is really easily up to date with CSS standards 👀
    h
    a
    t
    • 4
    • 4
  • a

    Ayfri

    08/06/2022, 12:23 AM
    Hi what is the design pattern to have a list of classes containing data which is got from a Promise ? Like how do I set the variable and how do I say that if it's empty, try to get the value and wait until the list has data to put the composables using the data ?
    d
    a
    • 3
    • 7
  • o

    Oliver.O

    08/09/2022, 10:16 PM
    Compose for Web on Canvas/Skia/Wasm: I have a simple function
    BrowserViewportWindow
    for the initial window. It is easy to use, supports resizing, fills the entire browser viewport, sets the window title correctly and does not require a stylesheet. Inspired by code in @Tlaster's PreCompose. If you want to try: Code in 🧵
    d
    h
    +7
    • 10
    • 48
  • a

    Ayfri

    08/10/2022, 3:17 PM
    Does latest version supports Kotlin 1.7.10 ?
    b
    j
    o
    • 4
    • 6
  • j

    jeran

    08/11/2022, 4:13 PM
    hi all, i’m an android developer exploring compose for web. is it correct to say that compose for web at this time does not support compose ui (e.g. Box, Modifier, etc.), but compose for desktop does? also if this is the case, are there any plans for supporting compose ui for web in the near future? thank you kindly
    f
    m
    +5
    • 8
    • 37
  • h

    hfhbd

    08/11/2022, 6:26 PM
    Do you really want to hide it, but still have it in the dom? then just use
    attrs("visibility", "hidden")
    . Alternative use
    if
    .
  • m

    Michael Paus

    08/12/2022, 7:37 AM
    Did you have a look at https://github.com/icerockdev/moko-resources
    j
    • 2
    • 1
  • с

    Стефан Јовановић

    08/12/2022, 11:00 AM
    Hey guys, just one question. When are you planning to publish the official documentation about Compose for Web? 🤔
    b
    m
    • 3
    • 12
  • a

    andylamax

    08/13/2022, 1:59 PM
    I keep hearing people are already trying out Compose 4 Web Canvas (C4WC). How or where do I look to get my self started?
    a
    s
    +2
    • 5
    • 6
  • a

    Ayfri

    08/14/2022, 9:16 PM
    Hi, I have a weird error where I can't set some style to a Div dynamically, I have this code
    Div({
    	classes(AboutMeStyle.timeline)
    		
    	window.addEventListener("scroll", {
    		val footerOffset = document.querySelector(".${AppStyle.footer}")?.asDynamic()?.offsetTop as Double? ?: return@addEventListener
    		val currentOffset by mutableStateOf(window.scrollY + 100)
    		
    		if (currentOffset < footerOffset) {
    			style {
    				top(currentOffset.px)
    			}
    		}
    	})
    })
    If I put a
    console.log
    inside the condition it gets called so it should be fine, but no style is set, what am I doing wrong ?
    d
    • 2
    • 2
  • a

    Ayfri

    08/15/2022, 7:11 PM
    Hi, I can't set a value for a CSS variable in an inline script ? I have this
    object FooterStyle : StyleSheet() {
        val buttonColor by variable<CSSColorValue>()
    
        val button by style {
            backgroundColor(buttonColor.value())
            ...
        }
    }
    
    // somewhere in a @Composable
    A(href = "/my-route", {
        target(ATarget.blank)
        classes(FooterStyle.button)
    
        style {
            FooterStye.buttonColor(Color.gray)
        }
    }) {
        Text("Download")
    }
    But the variable isn't set in my resulting CSS and there's even no inline style at all 🤔
  • j

    John Aoussou

    08/16/2022, 12:39 PM
    I'm sorry this question must have been asked many times, but I couldn't find answer: is there an easy to follow tutorial to learn how to deploy a Jetpack Compose frontend website on something like Heroku or AWS?
    r
    b
    +2
    • 5
    • 8
  • a

    agrosner

    08/18/2022, 1:18 AM
    hey. I was wondering if there is an easy way to generate react components from composables? use case, we have a web based documentation site for our design system (with web versions) and want to bring our composables into the page (for Android references) in a way that enables web developers to call the composables from React easily.
    • 1
    • 1
  • a

    agrosner

    08/18/2022, 12:07 PM
    Hey , anyone have a good image loading library like Coil that supports compose canvas for web?
    d
    c
    m
    • 4
    • 13
  • o

    Oliver.O

    08/18/2022, 3:26 PM
    In compose-jb 1.2.0-alpha01-dev755 with Web/Canvas/Skiko, I'm getting a symbol resolution error today
    Module "androidx.compose.foundation:foundation" has a reference to symbol [...] EmptyLazyGridLayoutInfo
    . It did work a couple of days ago. Re-downloaded the artifacts to no avail. Could it be that there's something wrong in the JB space repo? More Details in 🧵
    o
    • 2
    • 6
  • c

    Casey Brooks

    08/19/2022, 4:00 PM
    Has anyone tried to publish a library targeting using just
    compose.runtime
    as a dependency? I’m trying to make a library with a “common Compose” module that’s compose-runtime only, and then additional modules that add on support for Material and JS DOM, but it seems like there’s a problem with compose runtime being used in the common sourceSet
    h
    • 2
    • 6
  • a

    agrosner

    08/19/2022, 5:30 PM
    i was not discouraged when I learned that scrolling within canvas is not supported yet. So i took it upon myself to fix it (hackily): 1. define a global channel
    val scrollListener = Channel<Double>()
    2. Consume it in your scrollable composable:
    val scrollState = rememberLazyListState() 
      LaunchedEffect(Unit) {
            scrollListener.consumeAsFlow()
                .collect {
                    scrollState.scrollBy(it.toFloat())
                }
        }
    3. attach it to a window event:
    fun main() {
        window.addEventListener("wheel", { event ->
            if (event is WheelEvent) {
                event.stopPropagation()
                GlobalScope.launch {
                    scrollListener.trySend(event.deltaY)
                }
            }
        })
    }
    then you have scrolling support
  • c

    Casey Brooks

    08/19/2022, 10:03 PM
    I just released another version of Kotlin JSON Forms, which adds support for Compose Web using Bulma form styling! Still very much a POC, nowhere near production ready yet and the UI is terrible, but it’s neat to see it coming together and using the same form definition working for both Android and JS targets, making it significantly less annoying to build large, dynamic forms. Links to some examples in the 🧵
    • 1
    • 1
  • z

    zt

    08/25/2022, 5:50 PM
    How could I host my compose website using github pages? Is there some example I could look at?
    h
    c
    +2
    • 5
    • 5
  • t

    theapache64

    08/28/2022, 12:16 PM
    Now you can create your Compose Wasm web app from terminal 🎉 https://twitter.com/theapache64/status/1563862677063348224
    o
    j
    • 3
    • 3
  • d

    David Herman

    09/02/2022, 1:57 AM
    I'm wondering if there are official plans for adding support for CSS functions into the Web Compose API, e.g. things like clamp, abs, min, max.
    a
    • 2
    • 14
  • a

    agrosner

    09/02/2022, 11:03 AM
    You can have webpack bundle font resources and then you can require them and load them as any other url into a font object
    d
    e
    j
    • 4
    • 9
  • d

    deviant

    09/02/2022, 11:15 AM
    looks like
    Modifier.onPreviewKeyEvent
    and
    Modifier.onKeyEvent
    don't work in browsers. desktop and android are ok
    o
    • 2
    • 2
  • s

    Sebastien Leclerc Lavallee

    09/08/2022, 3:14 PM
    Hello! 👋🏻 I’m wondering if it’s possible to detect if the compose web project is running in development or distribution mode? I’d like to change some settings based on local development or prod Thanks!
    b
    s
    • 3
    • 4
  • t

    timothy.paetz

    09/10/2022, 11:35 PM
    Hey, I just started playing with compose web and can't even figure out how to add a dependency 🙃 . I downloaded this template and am trying to add routing-compose dependency. Where specifically in build.gradle.kts should I be adding
    implementation("app.softwork:routing-compose:0.2.8")
    Thanks!
    t
    h
    • 3
    • 11
Powered by Linen
Title
t

timothy.paetz

09/10/2022, 11:35 PM
Hey, I just started playing with compose web and can't even figure out how to add a dependency 🙃 . I downloaded this template and am trying to add routing-compose dependency. Where specifically in build.gradle.kts should I be adding
implementation("app.softwork:routing-compose:0.2.8")
Thanks!
Current build.gradle.kts:
import org.jetbrains.compose.compose
import org.jetbrains.compose.desktop.application.dsl.TargetFormat
import org.jetbrains.kotlin.gradle.targets.js.nodejs.NodeJsRootExtension

plugins {
    kotlin("multiplatform")
    id("org.jetbrains.compose")
}

repositories {
    mavenCentral()
    maven("<https://maven.pkg.jetbrains.space/public/p/compose/dev>")
    google()
}

kotlin {
    js(IR) {
        browser()
        binaries.executable()
    }
    sourceSets {

        val jsMain by getting {
            kotlin.srcDir("src/main/kotlin")
            resources.srcDir("src/main/resources")

            dependencies {
                implementation(compose.web.core)
                implementation(compose.runtime)
            }
        }

    }

}



// a temporary workaround for a bug in jsRun invocation - see <https://youtrack.jetbrains.com/issue/KT-48273>
afterEvaluate {
    rootProject.extensions.configure<NodeJsRootExtension> {
        nodeVersion = "16.0.0"
        versions.webpackDevServer.version = "4.0.0"
        versions.webpackCli.version = "4.10.0"
    }
}
t

Thomas

09/10/2022, 11:38 PM
You should be able to add it in the
dependencies
block next to the other implementation lines, if I understand your question correctly.
https://kotlinlang.org/docs/gradle.html#configuring-dependencies
t

timothy.paetz

09/10/2022, 11:52 PM
If I add it below "implementation(compose.runtime)", then I get these errors when running ./gradlew jsBrowserRun:
\src\main\kotlin\main.kt: (2, 12): Unresolved reference: jetbrains
\src\main\kotlin\main.kt: (3, 12): Unresolved reference: jetbrains
\src\main\kotlin\main.kt: (4, 12): Unresolved reference: jetbrains
\src\main\kotlin\main.kt: (5, 12): Unresolved reference: jetbrains
\src\main\kotlin\main.kt: (8, 5): Unresolved reference: renderComposable
\src\main\kotlin\main.kt: (9, 9): @Composable invocations can only happen from the context of a @Composable function
\src\main\kotlin\main.kt: (21, 5): Unresolved reference: Div
\src\main\kotlin\main.kt: (22, 9): Unresolved reference: Text
\src\main\kotlin\main.kt: (24, 5): Unresolved reference: Button
\src\main\kotlin\main.kt: (26, 13): Unresolved reference: onClick
\src\main\kotlin\main.kt: (26, 23): Cannot infer a type for this parameter. Please specify it explicitly.
\src\main\kotlin\main.kt: (31, 9): Unresolved reference: Text
If I add a commonMain then I get the same errors as well:
val commonMain by getting {
    dependencies {
        implementation("app.softwork:routing-compose:0.2.8")
    }
}
t

Thomas

09/11/2022, 12:12 AM
I think you may have a typo somewhere in your main.kt file causing those errors. Do you get the error without this dependency as well?
t

timothy.paetz

09/11/2022, 12:28 AM
No, works fine and opens in the browser if I delete routing-compose dependency
main.kt:
import androidx.compose.runtime.*
import org.jetbrains.compose.web.dom.Button
import org.jetbrains.compose.web.dom.Div
import org.jetbrains.compose.web.dom.Text
import org.jetbrains.compose.web.renderComposable

fun main() {
    renderComposable(rootElementId = "root") {
        Body()
//        HashRouter(initPath = "/") {
//            route("/blogs") {
//                Text("Hello World")
//            }
//        }
    }
}

@Composable
fun Body() {
    var counter by remember { mutableStateOf(0) }
    Div {
        Text("Clicked: ${counter}")
    }
    Button(
        attrs = {
            onClick { _ ->
                counter++
            }
        }
    ) {
        Text("Click")
    }
}
Looks like it might be what versions of kotlin, compose, and routing-compose are. Know which 3 all line up correctly? 🙂
h

hfhbd

09/11/2022, 8:10 AM
Hey, routing composes uses dev builds of compose to allow using Kotlin 1.7.10. The latest version of routing compose requires these versions:
kotlin("multiplatform") version "1.7.10"
id("org.jetbrains.compose") version "1.2.0-alpha01-dev770"

implementation("app.softwork:routing-compose:0.2.8")
And if you only want to have a web project, you could also use
kotlin("js") version "1.7.10"
, this makes the config a little bit easier imho.
t

timothy.paetz

09/11/2022, 4:01 PM
Thanks everyone for the help. Versions that worked for me: Kotlin 1.7.10 Compose 1.2.0-alpha01-dev774 Compose Routing 0.2.8
View count: 50