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
  • i

    iroyo

    12/15/2021, 5:00 PM
    When working with custom design specs (Typography, Colors, etc.) where you already have defined the only values a spec could take does it make any sense to work with classes that then need to be provided (via CompositionLocals) and not use objects directly? In the documentation they use a
    data class CustomColors
    and then a
    staticCompositionLocalOf
    but... does it make sense to omit all of this if we use an object instead?
    c
    b
    • 3
    • 6
  • a

    Anthony

    12/15/2021, 5:26 PM
    When using
    CompositionLocalProvider
    to provide alpha and text values, should the approach be different when using an annotated string? When I use a simple Text composable, the alpha and color is applied, but a annotated string inside a clickable text does not reflect these changes.
    z
    • 2
    • 3
  • d

    dewildte

    12/15/2021, 7:01 PM
    I am using a
    BottomSheetDialogFragment
    and it’s layout has a
    ComposeView
    in it. When trying to show the sheet I get this:
    java.lang.IllegalStateException: ViewTreeLifecycleOwner not found
    after the framework calls:
    androidx.compose.ui.platform.WindowRecomposer_androidKt.createLifecycleAwareViewTreeRecomposer(WindowRecomposer.android.kt:244)
    Anybody run into this before?
    a
    i
    • 3
    • 9
  • c

    colintheshots

    12/15/2021, 8:51 PM
    Let’s say the SnackbarHost isn’t sufficient for some UI element I want to show on messages and errors. Is there a reliable way to add a Composable briefly on the screen the same way as a snackbar would appear, but sometimes called from the Fragment or ViewModel, outside of Compose? I’m trying to add our custom toasts across the app in a variety of status-specific colors with icons included.
    🤔 1
    a
    • 2
    • 6
  • o

    oday

    12/15/2021, 8:53 PM
    I seem to have a problem getting this code to resolve
    constrainAs
    and
    top
    https://developer.android.com/codelabs/jetpack-compose-layouts?continue=https%3A%2F%2Fd[…]developer.android.com%2Fcodelabs%2Fjetpack-compose-layouts even though I’ve included the library needed for ConstraintLayout and I’m using compose 1.0.5
    • 1
    • 2
  • y

    Yves Kalume

    12/15/2021, 9:09 PM
    what would be the best way to make the container of this LazyRow, TextField and LazyVerticalGrid scrollable knowing that we can't have nested scrollable in the same direction layouts ?
    j
    • 2
    • 2
  • n

    nschulzke

    12/15/2021, 10:47 PM
    I'm getting a compiler plugin error while building an android project with Kotlin 1.6, Jetpack Compose 1.1.0-rc01. Does anyone know how to debug these kinds of compiler plugin errors, or have an idea what this one means?
    java.lang.IllegalStateException: Symbol for kotlin.collections/mutableMapOf|-4813910536206556932[0] is unbound
    	at org.jetbrains.kotlin.ir.symbols.impl.IrBindablePublicSymbolBase.getOwner(IrPublicSymbolBase.kt:52)
    	at org.jetbrains.kotlin.ir.symbols.impl.IrSimpleFunctionPublicSymbolImpl.getOwner(IrPublicSymbolBase.kt:74)
    	at androidx.compose.compiler.plugins.kotlin.lower.LiveLiteralTransformer.visitCall(LiveLiteralTransformer.kt:663)
    
    ...
    b
    • 2
    • 4
  • c

    Colton Idle

    12/15/2021, 11:37 PM
    I want to use kotlin 1.6.10 (which has a bunch of good bugfixes) with compose 1.1.0-rc01 (released today) I used to use this back in the day to get around kotlin compat checks, but it doesn't work anymore. Is there a new way to get around the kotlin compat checks?
    tasks.withType<org.jetbrains.kotlin.gradle.tasks.KotlinCompile>().configureEach {
        kotlinOptions {
            jvmTarget = "1.8"
            freeCompilerArgs += listOf(
                    "-Xallow-jvm-ir-dependencies",
                    "-P",
                    "plugin:androidx.compose.compiler.plugins.kotlin:suppressKotlinVersionCompatibilityCheck=true"
            )
        }
    }
    e
    • 2
    • 2
  • l

    Luis Daivid

    12/16/2021, 2:36 AM
    When a specific Box is clicked among multiple nested Boxes, is it possible to get the x and y values ​​on the screen of that Box? Specifically, I want to know the center x y value of Box3 when I start dragging on Box3.
    z
    • 2
    • 1
  • r

    Ramesh

    12/16/2021, 5:13 AM
    Hi Team, We are planning to migrate our app to use compose. I'm keen to know the experiences/abstacles/strategy you have followed to start migration of your production projects. Our app is multi module uses MVVM, data binding and View Binding. Thank you.
    y
    • 2
    • 1
  • r

    rkeazor

    12/16/2021, 6:10 AM
    Does Compose with Kotlin 1.6.10?
    c
    • 2
    • 1
  • z

    Zoltan Demant

    12/16/2021, 7:45 AM
    Why would a
    Text
    composable misalign its text like this in some situations (seemingly, only on a Huawei P30 Pro)?
    c
    t
    • 3
    • 25
  • m

    Michal Klimczak

    12/16/2021, 8:14 AM
    screenshot testing based on compose preview - nothing like that in the wild, right? is this because of some preview tooling limitations? it would be great if we could have a simple compiler plugin which would go through the code, run the previews it found and just rendered them to bitmaps. (I am aware of screenshot testing libraries based on emulator tests, like Shot, but here I'm thinking of something much simpler). Or to rephrase it - how would one tap into the preview tooling to try and render a bitmap out of preview?
    c
    • 2
    • 2
  • j

    Javier

    12/16/2021, 10:45 AM
    Expected behavior? Why?
    // Doesn't work, it keeps the size over the time.
    SomeComponent(
        shape = RoundedCornerShape(if (someState) 8.dp else 30.dp),
    )
    
    // Work, size is changing
    SomeComponent(
        shape = if (someState) RoundedCornerShape(8.dp) else RoundedCornerShape(30.dp),
    )
    ➕ 1
    t
    z
    a
    • 4
    • 7
  • n

    nglauber

    12/16/2021, 1:57 PM
    Do you know how to keep the
    LazyColumn
    scroll state after navigate to a different screen? I’m getting a strange behavior…
    val listState = rememberLazyListState()
    
    val reportList by viewModel.reportList.flowInLifecycle()
        .collectAsState(initial = emptyList())
    The code above is in
    ScreenA
    , from this screen I open
    ScreenB
    . When I return to
    ScreenA
    , the
    reportsList
    becomes empty for 1 composition, so the
    listState
    moves to position 0.
    z
    j
    • 3
    • 7
  • y

    yschimke

    12/16/2021, 4:46 PM
    If I want to print out the Typeface names for each style in MaterialTheme.typography, is there a trick to do that? It seems like you get to FontFamily.Default, and that's the abstract concept of the default system font. And advice is to read the font config files in the system. But am I missing something? I know if I care about specific fonts, I can specify those. But I'd actually just like to understand the defaults on screen in the matching style.
    ➕ 1
    c
    • 2
    • 1
  • d

    dimsuz

    12/16/2021, 5:39 PM
    this bit of code never prints "1" in console. Does recomposer conflate values?
    fun main() {
      var state by mutableStateOf(value = "30")
      application {
        Window {
          Button(onClick = { state = "1"; state = "2"}) {
            println("got $state")
            Text(state)
          }
        }
      }
    }
    Debugger shows that shapshot system sees all values, but
    recompositionRunner
    never receives the "1" value. Are there some optimizations in
    Snapshot.apply
    method maybe? What should one do to receive all state updates (or is this impossible/wrong)?
    z
    a
    a
    • 4
    • 16
  • m

    Mohammad Jahidul Islam

    12/16/2021, 5:50 PM
    Suppose I got an API result like val apiResult = String? A nullable Image url. Now how can I display the image with coil in composeable. I add apiResult as a perimeter in Image painter value but this display nothing.
    y
    • 2
    • 2
  • b

    Brian Donovan

    12/16/2021, 6:22 PM
    Hi all, any reason why Modifier.weight not working inside of a Column?
    k
    c
    • 3
    • 13
  • n

    Nick Anthony

    12/16/2021, 7:46 PM
    Hey all - for those who were asking about Kotlin
    1.6.10
    support, we shipped Compose Compiler
    1.1.0-rc02
    with official support for Kotlin
    1.6.10
    (see https://developer.android.com/jetpack/androidx/releases/compose-compiler#1.1.0-rc02). Additionally, we also started publishing a table mapping the Compose Compiler version to it's compatible Kotlin version. (https://developer.android.com/jetpack/androidx/releases/compose-kotlin)
    :cool-doge: 8
    🎉 10
    👏🏽 1
    👏 17
    :jetpack-compose: 9
    👏🏼 1
    :kotlin-intensifies-purple: 9
    c
    j
    +2
    • 5
    • 7
  • m

    Marcello Galhardo

    12/16/2021, 9:09 PM
    Reading the docs from
    SideEffect
    it says:
    To share Compose state with objects not managed by compose, use the 
    SideEffect
     composable, as it’s invoked on every successful recomposition.
    If a
    SideEffect
    is called on “each recomposition”, what is the difference between the two codes:
    @Composable
    fun sample(user: User) {
        // 1. With Side Effect, called each successful recomposition.
        SideEffect { analytics.setUserProperty("userType", user.userType) }
    
        // 2. No SideEffect, called each recomposition.
        analytics.setUserProperty("userType", user.userType)
    }
    My understand is that a
    SideEffect
    would not be triggered if a recomposition happens (similar to
    LaunchedEffect
    and how it works with the keys) but based in the docs I think I’m missing something…
    c
    s
    +3
    • 6
    • 12
  • c

    Colton Idle

    12/16/2021, 10:27 PM
    Compose and Events! I finally got a chance to read the newly released arch docs for android. Lots of good compose related snippets in there. Probably the biggest piece of help has been event handling and how events should always result in a UI state update. I do have questions though and I suppose either manuel, florina, adam or ian might be best to chime in (among others) since they helped write the docs. https://developer.android.com/jetpack/guide/ui-layer/events?continue=https%3A%2F%2Fdeve[…]eveloper.android.com%2Fjetpack%2Fguide%2Fui-layer%2Fevents The example being
    // composable
        val currentOnUserLogIn by rememberUpdatedState(onUserLogIn)
        LaunchedEffect(viewModel.uiState)  {
            if (viewModel.uiState.isUserLoggedIn) {
                currentOnUserLogIn()
            }
        }
    I have a bunch of questions 1. I don't understand the use of
    val currentOnUserLogIn by rememberUpdatedState(onUserLogIn)
    . Why doesn't this code sample just call
    onUserLogIn
    directly? 2. What goes into LaunchedEffect arg exactly? It seems like its easy to mess up what exactly goes in there and therefore shoot yourself in the foot. I can expand on this if that didn't make sense. 3. Why can't I just pass the ref of onUserLogIn event into the ViewModel and onSuccess of a login network call it would just call onUserLogIn in the VM itself?
    a
    a
    • 3
    • 14
  • l

    loloof64

    12/16/2021, 10:41 PM
    Hi ! I have a
    @Composable
    :
    GamePage
    , which is using a native library. But this native library must be stopped when not needed any more:
    @Composable
    fun GamePage() {
    val myLib = MyLib()
    
    ...
    myLib.stop()
    }
    So, is there a way to ? 1. Build a new MyLib instance at each recomposition 2. But also stop it before the next recomposition 3. Can I wait some milliseconds before "commiting" the next recomposition ?
    k
    l
    • 3
    • 7
  • b

    Benjamin Deroche

    12/17/2021, 10:36 AM
    Hello! Why does creating a blank new Compose Multiplatform project create 2 different modules for the JVM target. There is the desktop.jvmMain module and the common.desktopMain module, and I fail to understand what is the difference between those 2. In fact I think IntelliJ is as confused as I am because if you select "Compose Desktop Module" instead of "Console Application" in common > desktop when creating a new project, then the code from desktop.jvmMain does not even work (it does not compile .. but is never run anyway)
    s
    c
    • 3
    • 10
  • z

    Zoltan Demant

    12/17/2021, 1:25 PM
    If a
    TextField
    shrinks its size inside a
    Column
    , other composables under it will jump up. Normally Id use
    Modifier.weight(1f)
    so that they stick to the bottom, however that doesnt work inside a
    AlertDialog
    without causing it to extend across the entire screen height. Is there another way?
    ➕ 1
    c
    • 2
    • 2
  • n

    Nat Strangerweather

    12/17/2021, 4:06 PM
    Hi, I followed a YT tutorial to fetch some data through retrofit. I think I understood most of the tutorial and in fact everything works well. The only problem is that it requests live data and I don't need that. The api is complaining that there are too many calls. Do you have any idea how I can modify the code so that it only loads one time per query rather than continuously? 🧵
    a
    • 2
    • 8
  • j

    jeff

    12/17/2021, 4:24 PM
    Is "donut hole skipping" impossible without MutableState? Put another way: if I have a composable whose only argument is a "normal" class
    Input
    (i.e. not a MutableState), and all of the sub-composables are based on fields from
    Input
    : Can any of the sub-composables inside it be recomposed without recomposing the parent? If so I'd love to see an example, because I can't seem to concoct one.
    ➕ 2
    t
    • 2
    • 2
  • d

    David Odari

    12/17/2021, 5:16 PM
    Hello I'm currently on A.S Chipmunk Canary 6 and compose version 1.0.5. Any clues as to why the previews don't show when
    @PreviewParameter
    is used despite creating providers as specified here ?
    c
    c
    a
    • 4
    • 7
  • s

    Shreyas Patil

    12/18/2021, 6:49 AM
    While exploring 
    TextField
     in a Jetpack Compose, I came across a case where I have to modify input typed in the field. For example, adding a comma after entering 3 characters. This is how I made it.
    @Composable
    fun TFDemo() {
        var fieldValue by remember { mutableStateOf(TextFieldValue("")) }
    
        TextField(
            value = fieldValue,
            onValueChange = {
                val newMessage = it.text.let { text -> if (text.length == 3) "$text," else text }
                fieldValue = it.copy(newMessage, selection = TextRange(newMessage.length))
            },
            keyboardOptions = KeyboardOptions(autoCorrect = false),
        )
    }
    But after running it, I realized that after the comma is added, keyboard view changed back to alphabets from numbers/symbols which should not be the case. See video output below for clarity As you can see in the below video when I typed "111" comma was appended and suddenly keyboard's numeric view changed to alphabets again. Stackoverflow: https://stackoverflow.com/questions/70401519/android-jetpack-compose-keyboard-changing-from-numeric-to-alphabets-after-modif
    Android Emulator - Pixel_API_29_5554 2021-12-18 12-02-42.mp4
    s
    • 2
    • 3
  • s

    ste

    12/18/2021, 3:09 PM
    Hi all! Is it just me or Compose (or Kotlin plugin) makes Android Studio slow as hell? It takes seconds in basically every possible task (syntax highlighting, show suggestions)... it's becoming quite frustrating
    n
    c
    +4
    • 7
    • 13
Powered by Linen
Title
s

ste

12/18/2021, 3:09 PM
Hi all! Is it just me or Compose (or Kotlin plugin) makes Android Studio slow as hell? It takes seconds in basically every possible task (syntax highlighting, show suggestions)... it's becoming quite frustrating
n

nilTheDev

12/18/2021, 7:19 PM
It's certainly not my case. I haven't noticed anything after I started using Jetpack compose. Make sure you are having 16 GB of RAM and Android studio is allowed to use 4 GB of memory.
c

Colton Idle

12/18/2021, 9:10 PM
Yeah. I've noticed this. Filed bugs, reached out to jetbrains folks. Seems like the difference maker is going to be the new frontend compiler which should be coming out in 2022. Once that is out, then all of the IDE stuff should be faster.
My first bug about this was opened in 2018, where auto-completing took seconds... and sometimes would hang for 10+ seconds. My machine in 2018 had 392GB of RAM. (I have a mac pro tower from work) and so if my machine with 392GB of ram was slow, then there was definitely going to be issues with peoples laptops that have 16GB.
e

efemoney

12/19/2021, 10:57 AM
What do you do for work 😭? 392GB of RAM is insane! Have I been settling???
c

Colton Idle

12/19/2021, 5:20 PM
work on different facets of the same project. so android studio with 1 or 2 emulators, xcode, some docker stuff. etc. plus everything seems to be chrome based now and it just eats gigabytes.
I did start using @mightyapp recently and I've been able to same a ton of ram from chrome. its sad, but right now it solves the problem.
k

Kazem Moridi

12/20/2021, 6:04 AM
I had the same problem, but after I installed the same version of Kotlin-IDE Plugin as the compose supported version , it fixed the slowness of android studio
m

Michal Klimczak

12/20/2021, 7:42 AM
if you have an m1 mac, make sure you use the arm64 version of android studio. the intel/rosetta is painfully slow (just like you described)
s

ste

12/21/2021, 9:17 AM
Idk, I already allowed android studio to use 4gb of ram, don't know what to do
simplescreenrecorder4.mp4
@Kazem Moridi this is interesting, my compose project uses 1.6.0, but i already updated kotlin plugin to 1.6.10
c

Colton Idle

12/21/2021, 3:29 PM
Write up a bug report on youtrack against intellij. They'll tell you how to get additional info to help them with this.
👍 1
s

ste

12/21/2021, 5:12 PM
Yup that's what I'll do. I just performed a clean install of AS - no luck. Very embarrassing
👍 1
c

CLOVIS

01/03/2022, 6:26 AM
Note that giving too much RAM to JVM programs can make them slower. I originally increased the IDEA heap size to 4GB, and it wasn't that fast. It's much faster now that I reduced it to 2GB.
View count: 5