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-desktop
  • k

    kevin.cianfarini

    12/03/2020, 1:17 AM
    Does skiko (and by extension compose desktop) support Wayland display servers? I noticed in
    <http://drawlayer.cc|drawlayer.cc>
    that only references to X11 header files are made.
    t
    • 2
    • 17
  • k

    Kirill Grouchnikov

    12/03/2020, 3:10 AM
    https://www.zdnet.com/article/kotlin-language-maker-jetbrains-windows-10-and-m1-macos-get-android-jetpack-compose/
    a
    i
    m
    • 4
    • 6
  • k

    kevin.cianfarini

    12/03/2020, 5:57 PM
    Is there a YouTrack for Skiko? I posted an issue on github, but I'm not sure if that's where it will be seen. https://github.com/JetBrains/skiko/issues/28
    i
    • 2
    • 2
  • r

    ron

    12/03/2020, 8:11 PM
    https://github.com/JetBrains/compose-jb/issues/165 I opened this ticket, does somebody have the same issue?
    d
    t
    i
    • 4
    • 29
  • k

    Kirill Grouchnikov

    12/03/2020, 11:03 PM
    I'm kinda in love with ambients. But then again, powers to be are saying that those can be easily abused 🙂
    j
    s
    +5
    • 8
    • 15
  • m

    melatonina

    12/04/2020, 12:16 PM
    Would this be a good way to run JavaFX and Compose Desktop in the same application?
    import kotlinx.coroutines.*
    
    import androidx.compose.desktop.*
    import androidx.compose.material.*
    import androidx.compose.runtime.*
    
    fun main(args: Array<String>) = runBlocking {
        val javaFxJob = GlobalScope.launch {
            launch<HelloWorld>(args)
        }
    
        val composeDesktopJob = GlobalScope.launch {
            Window {
                var text by remember { mutableStateOf("Hello, World!") }
    
                MaterialTheme {
                    Button(onClick = {
                        text = "Hello, Desktop!"
                    }) {
                        Text(text)
                    }
                }
            }
        }
    
        javaFxJob.join()
        composeDesktopJob.join()
    }
    I'm getting crashes half of the time, unless I separate the startups of the two toolkits with a
    delay()
    , so I guess there is something wrong. Otherwise it seems to work. This happens with both 0.3.0-build133 and 0.2.0-build132.
    i
    • 2
    • 9
  • t

    Thomas

    12/04/2020, 4:37 PM
    The following code is a slightly reworked snippet from the Android Compose sample app.
    val colors = if (isSystemInDarkTheme()) {
        darkColors()
    } else {
        lightColors()
    }
    Doesn't work because isSystemInDarkTheme() is not found. On the Android side it is currently resolved through foundation-1.0.0-alpha04. So, am I mistaken assuming Compose Desktop relies on another (earlier) version of androidx.compose.foundation? If I got something completely wrong, please forgive me, still apprenticing Compose Desktop. :-)
    i
    • 2
    • 2
  • s

    spierce7

    12/04/2020, 9:25 PM
    Is there a trick to centering things in compose? i.e. in a Lazy Column, for each item if I have some text, and then a divider at the bottom, I’m finding it exceptionally verbose to center the text vertically, and have the divider at the bottom.
    d
    • 2
    • 7
  • p

    py

    12/04/2020, 11:35 PM
    👋 trying compose desktop, I’m told this is the place to ask questions. So, let’s start with a dumb one: when running a desktop app from IJ, where do I see the result of
    println
    ?
    z
    c
    • 3
    • 11
  • p

    py

    12/05/2020, 12:43 AM
    Result of todays’ session: https://twitter.com/Piwai/status/1335021725361160192
    😍 1
    🎉 10
    🔥 6
    c
    • 2
    • 1
  • n

    Nikky

    12/05/2020, 12:46 AM
    how easy is it to draw custom shapes via SVG or canvas across compose-desktop and android ? (that kinda the center UI for a thing i might want to build.. but i also want to explose compose for desktop)
    z
    s
    d
    • 4
    • 10
  • c

    Colton Idle

    12/05/2020, 12:57 AM
    Just did file > new project as per https://blog.jetbrains.com/cross-post/jetpack-compose-for-desktop-milestone-2-released/ and I get this red line under
    Window
    . the app builds... but I'm curious if anyone knows how to get rid of it?
    o
    • 2
    • 3
  • k

    Kirill Grouchnikov

    12/05/2020, 5:18 AM
    A bit more progress on Aurora icons and transitions. The plan is to support not only mono-chromatic icon sets (such as Material), but a wider variety of iconography languages that may or may not use colors, textures ets. In the example below, the
    toggle
    button is using a multicolor icon from the Tango set, while
    flat
    and
    always
    buttons use the single-color icons from the Material set. The
    toggle
    button is configured to use theme-provided colors and alpha for automatically filtering the icon appearance when the button is in the disabled state. You can see when
    content enabled
    checkbox is unselected, the computer icon turns light brown when
    toggle
    is selected (+disabled) and light gray when it's not selected (+disabled). The
    flat
    and
    always
    buttons are configured to have the icon always filtered to follow the text color. This "follow text" functionality can be seen in enabled/disabled states, as well as during the rollover when the icon and the text turn from black to dark brown.
    aurora-icons.mov
    🎉 6
    👀 1
    c
    • 2
    • 3
  • l

    Luis Daivid

    12/05/2020, 2:38 PM
    I want to use drag and drop using compose-jb. I want to pull a file from outside and import it into the app. How do I implement it?
    j
    • 2
    • 2
  • s

    spierce7

    12/05/2020, 9:09 PM
    Is there any way to gain access to the code from the common layer in the IDE? It’s very annoying that all I can really see is
    /* = compiled code */
    t
    s
    a
    • 4
    • 8
  • d

    Dominaezzz

    12/06/2020, 1:23 AM
    Can skiko/skija be used to scale an image? (Not drawing it but creating another image of a different size)
    t
    • 2
    • 2
  • s

    spierce7

    12/06/2020, 5:55 AM
    If I have timers on a UI in compose, and part of my state I have the start date, what would be the best way to trigger a re-draw of the UI every second, so that the timers can be updated? It’d be obvious to just update the state with the actual value to display in a coroutine timer using
    delay
    , but I have a list of items potentially hundreds large, and it seems like there might be a better way that compose offers.
    j
    s
    z
    • 4
    • 5
  • g

    galex

    12/06/2020, 7:19 AM
    Hello, is compose-jb a multiplatform project? I’d like to build an app for windows and macOS, and I wonder what platform of a 3rd party I should use? I guess both?
    k
    a
    • 3
    • 3
  • g

    gbaldeck

    12/07/2020, 12:23 AM
    Hi, I have a Gradle project with 3 subprojects using Compose for desktop. Two of the subprojects are Compose applications and then the third is shared code between the two. I am getting an error in the IDE that I can't seem to get to go away. It is "Cannot inline bytecode built with JVM target 1.8 into bytecode that is being built with JVM target 1.6. Please specify proper '-jvm-target' option". In all my build.gradle.kts files I am setting the kotlinOptions.jvmTarget to 15 but its like the IDE ignores it. This only happens in a Gradle project with subprojects. Does anyone know how to get this to go away?
    n
    s
    • 3
    • 3
  • s

    spierce7

    12/07/2020, 5:50 AM
    Is more work planned for Scroll Bars? My initial feedback after spending an hour with them: • I put my screen in a
    ScrollableColumn
    and got an error. I was annoyed that I had to refactor my screen because I had a
    LazyColumnFor
    nested inside it. • Using the
    item
    syntax inside
    LazyColumn
    was surprisingly delightful for building lazy content. I was pretty happy with how easy it made things. • Not having access to ScrollBars in the common layer was pretty brutal. • The current api for lazy column with scroll bars forces me to give an average item height and a count. This api was pretty cumbersome to use. This takes away most of the benefits from using the
    item
    syntax with
    LazyColumn
    . • I’m going to avoid using `ScrollBar`s for now as I have to modify the way I’m developing too much, and the APIs are too error prone.
    j
    o
    i
    • 4
    • 4
  • o

    orangy

    12/07/2020, 7:43 AM
    Hi, I’m pretty new to Compose (haha, I mean trying to really do something with it), and I want to use it for simple game UI we are doing with my kid. It’s not even 2D game, just some controls and images reflecting current state, kinda like incremental/idle games, if you know. While I understand unidirectional approach, incremental computations and such, I can’t find a simple way to do a game loop. Basically, I want it to call some
    Update(dt)
    function frequently passing time passed since last call, which would update game mutable state and then I want UI to only touch things that actually depend on the change. I’ve searched the net and only found some clocks and Dino game, but they are just animating things directly, not doing this intermediate game state thing. Am I missing something? How I’d go with it?
    a
    o
    +4
    • 7
    • 12
  • t

    Thomas

    12/07/2020, 12:48 PM
    If I configure my build script like this, the Java packaging tool creates a very nice .dmg file. Excellent! The menubar picks up the app name for the menu title but the menu item still reads MainKt (see screenshot). Can I configure this on my own besides renaming the corresponding file 🙂 or are there changes inside Compose Desktop needed to make this happen? Thanks in advance
    compose.desktop {
        application {
            mainClass = "com.thomaskuenneth.tkdupefinder.MainKt"
            nativeDistributions {
                targetFormats(TargetFormat.Dmg)
                packageName = "TKDupeFinder"
                version = "0.1-SNAPSHOT"
                description = "Find duplicate files"
                copyright = "© 2020 Thomas Kuenneth. All rights reserved."
                vendor = "Thomas Kuenneth"
            }
        }
    }
    💯 2
    o
    m
    s
    • 4
    • 5
  • c

    Colton Idle

    12/08/2020, 3:42 PM
    Can any of you repro my issue? File > New Project,
    Window
    is underlined as an error. gif available of what I'm doing
    j
    • 2
    • 13
  • s

    seb

    12/08/2020, 4:00 PM
    Tried playing with CfD a bit, new project created in IJ 203 with Kotlin 1.4.20, CfD 0.20-build132. I’m stuck at the IDE/compiler complaining that
    mutableState
    doesn’t have a
    get()
    and thus cannot be used as a delegate. Code copied from the official samples. Weirdest part is, it works with the code samples, same IDE, Kotlin version, CfD version. I suspect it may be some Kotlin compiler plugin in my build interfering — I already had to remove kotlinx.serialization as its compiler plugin would just crash with NPEs as soon as I added
    @Serializable
    to literally any class. Maybe it’s coroutines? Will do some further testing, was mostly wondering whether there’s any known compat issues
    a
    o
    c
    • 4
    • 10
  • t

    Thiago

    12/09/2020, 12:36 AM
    I'm drawing a simple rectangle with red border. I noticed that the top origin is behind the system bar. We can see the left, bottom and right edges. But to show the top I have to increase the Y-axis origin. Why the top rectangle edge is behind the system bar?
    main.kt
    ➕ 1
    i
    • 2
    • 1
  • s

    suresh

    12/09/2020, 7:24 AM
    How can i see the compose compiler generated bytecode in IDE (similar to suspend functions) ?
    Show Kotlin Bytecode
    still shows the compose annotation and not the transformed function with composer context as first argument.
    k
    o
    • 3
    • 3
  • t

    tieskedh

    12/09/2020, 9:11 AM
    Quick question, I need dispatchers.Main. Which one do I need for desktop: • kotlinx-coroutines-android • kotlinx-coroutines-javafx • kotlinx-coroutines-swing • Another one?
    i
    d
    • 3
    • 3
  • k

    Kris Elsinga

    12/10/2020, 10:38 AM
    Hey, I'm compiling the todoapp example with
    gradle :desktop:package
    And I'm only getting a .deb Even if I use
    gradle :desktop:packageMsi
    I don't get an .msi file Does anyone know how to build an .msi with compose? I work on a linux vm
    i
    • 2
    • 2
  • a

    Ali Albaali

    12/10/2020, 10:33 PM
    There seems to be a problem when using Kotlin.Result with CfD by running the code below, the first call will work and print "success" just fine, however the second will throw an exception. output in the reply.
    public suspend fun main() {
    
        getImage()
            .fold(
                onSuccess = { println("success") },
                onFailure = { println("failure") }
            )
    
        Window {
            LaunchedEffect(null) {
                getImage()
                    .fold(
                        onSuccess = { println("success") },
                        onFailure = { println("failure") }
                    )
            }
        }
    }
    public suspend fun getImage(): Result<ByteReadChannel> = runCatching<ByteReadChannel> {
        client.get<ByteReadChannel>("<https://i.redd.it/22bexa3ozc461.png>")
    }
    j
    l
    • 3
    • 3
  • s

    suresh

    12/11/2020, 12:20 AM
    What's the proper way to handle exceptions thrown from composable functions? An unchecked java exception thrown from a composable function has frozen the UI and there is no way to recover from it gracefully. So in this case I want to catch (Something like
    Thread.UncaughtExceptionHandler
    ) and continue the recomposition or is this some kind of anti-pattern in compose? 
    Exception in thread "AWT-EventQueue-0 @coroutine#2" java.lang.IndexOutOfBoundsException: Index 5 out of bounds for length 5
    	at java.base/jdk.internal.util.Preconditions.outOfBounds(Preconditions.java:64)
    	at java.base/jdk.internal.util.Preconditions.outOfBoundsCheckIndex(Preconditions.java:70)
    	at java.base/jdk.internal.util.Preconditions.checkIndex(Preconditions.java:248)
    	at java.base/java.util.Objects.checkIndex(Objects.java:359)
    	at java.base/java.util.ArrayList.get(ArrayList.java:427)
    	at androidx.compose.material.TabRowKt$TabRow$1.invoke(TabRow.kt:117)
    	at androidx.compose.material.TabRowKt$TabRow$1.invoke(TabRow.kt)
    t
    j
    • 3
    • 4
Powered by Linen
Title
s

suresh

12/11/2020, 12:20 AM
What's the proper way to handle exceptions thrown from composable functions? An unchecked java exception thrown from a composable function has frozen the UI and there is no way to recover from it gracefully. So in this case I want to catch (Something like
Thread.UncaughtExceptionHandler
) and continue the recomposition or is this some kind of anti-pattern in compose? 
Exception in thread "AWT-EventQueue-0 @coroutine#2" java.lang.IndexOutOfBoundsException: Index 5 out of bounds for length 5
	at java.base/jdk.internal.util.Preconditions.outOfBounds(Preconditions.java:64)
	at java.base/jdk.internal.util.Preconditions.outOfBoundsCheckIndex(Preconditions.java:70)
	at java.base/jdk.internal.util.Preconditions.checkIndex(Preconditions.java:248)
	at java.base/java.util.Objects.checkIndex(Objects.java:359)
	at java.base/java.util.ArrayList.get(ArrayList.java:427)
	at androidx.compose.material.TabRowKt$TabRow$1.invoke(TabRow.kt:117)
	at androidx.compose.material.TabRowKt$TabRow$1.invoke(TabRow.kt)
t

Timo Drick

12/11/2020, 3:31 AM
I think you should try to convert this to states. E.g. when you are loading s.th. than this loading composable will return a state. Which can be Loading, Sucess and Error. Than you can show different UI depending on the state.
j

jim

12/11/2020, 5:32 AM
Yes, Timo is correct. At this time, you do not want to have your composable functions be throwing exceptions. Instead, catch the exception directly by wrapping your non-composable function calls in try-catch blocks. When an exception is caught, set some state in your application (eg. set an error message you want to display to the user) and then the app will see the data state change and will recompose, and your composables can read from that variable to see what message (if any) to display to the user.
❤️ 2
t

Timo Drick

12/11/2020, 8:29 AM
I use following code (Mainly for image loading but can be used for every thing)
sealed class LoadingState<out T: Any> {
    object Start: LoadingState<Nothing>()
    object Loading: LoadingState<Nothing>()
    class Error(val error: Exception): LoadingState<Nothing>()
    class Success<T: Any>(val data: T): LoadingState<T>()
}

@Composable
fun <T: Any> loadingStateFor(vararg inputs: Any?, initBlock: () -> LoadingState<T> = { LoadingState.Start },
                             loadingBlock: suspend CoroutineScope.() -> T): LoadingState<T> {
    var state by remember(*inputs) { mutableStateOf(initBlock()) }
    if (state !is LoadingState.Success) {
        LaunchedEffect(*inputs) {
            val loadingSpinnerDelay = async {
                delay(500)
                state = LoadingState.Loading
            }
            state = try {
                LoadingState.Success(loadingBlock())
            } catch (err: Exception) {
                LoadingState.Error(err)
            } finally {
                loadingSpinnerDelay.cancelAndJoin()
            }
        }
    }
    return state
}
Than you can use it in your composables like that:
val imageState = loadingStateFor(image) {
                loadImageSizeFileCached(image.file, width)
            }
            Box(Modifier.fillMaxSize()) {
                InitializedCrossfade(imageState) { state ->
                    when (state) {
                        is LoadingState.Loading -> LoadingBox()
                        is LoadingState.Success -> Image(
                            modifier = Modifier.fillMaxSize(),
                            bitmap = state.data,
                            contentScale = ContentScale.Fit
                        )
                        is LoadingState.Error -> ErrorBox(
                            message = "Error: ${state.error.message}",
                            onRetry = { retryCounter++ })
                    }
                }
            }
s

suresh

12/11/2020, 6:56 PM
@jim @Timo Drick thanks!
View count: 8