https://kotlinlang.org logo
Docs
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
  • s

    Se7eN

    11/20/2020, 11:17 AM
    Should I annotate my modifiers with
    @Stable
    ? Also, is it fine to make a modifier composable?
    a
    3 replies · 2 participants
  • a

    Arun

    11/20/2020, 11:22 AM
    According to doc:
    @get:Rule
    val composeTestRule =
      AndroidComposeTestRule<MyActivity>(disableTransitions = true)
    However, there’s no such parameter
    disableTransitions
    . Is there any alternative way to disable animations and transitions while testing?
    a
    10 replies · 2 participants
  • o

    Odin

    11/20/2020, 12:14 PM
    Does anyone here know what might be the cause of this error?
    e: java.lang.IllegalArgumentException: Unbound type parameters are forbidden: [Unbound private symbol org.jetbrains.kotlin.ir.symbols.impl.IrTypeParameterSymbolImpl@69e10c4e, Unbound private symbol org.jetbrains.kotlin.ir.symbols.impl.IrTypeParameterSymbolImpl@782ec94]
    Ive read that it might be because of synthetic imports, but I cannot find any. Are there any other reason for this to occur?
    j
    1 reply · 2 participants
  • r

    Rafs

    11/20/2020, 12:17 PM
    How can I draw a text on a compose canvas? I don't see any
    drawText
    method in the
    DrawScope
    j
    n
    +3
    17 replies · 6 participants
  • a

    Arun

    11/20/2020, 12:23 PM
    Node #1 at (0.0, 66.0, 1080.0, 2009.0)px
         |-Node #2 at (970.0, 110.0, 1036.0, 176.0)px
         | OnClick = 'AccessibilityAction(label=null, action=Function0<java.lang.Boolean>)'
         | MergeDescendants = 'true'
         |-Node #3 at (0.0, 220.0, 1080.0, 2009.0)px
           VerticalAccessibilityScrollState = 'AccessibilityScrollState(value=0.0, maxValue=0.0, reverseScrolling=false)'
           ScrollBy = 'AccessibilityAction(label=null, action=Function2<java.lang.Float, java.lang.Float, java.lang.Boolean>)'
            |-Node #4 at (44.0, 1089.0, 368.0, 1152.0)px, Tag: 'Section Header'
            | Text = 'Section Header'
            | GetTextLayoutResult = 'AccessibilityAction(label=null, action=(kotlin.collections.MutableList<androidx.compose.ui.text.TextLayoutResult>) -> kotlin.Boolean)'
            |-Node #7 at (44.0, 1196.0, 1036.0, 1423.0)px
            | OnClick = 'AccessibilityAction(label=null, action=Function0<java.lang.Boolean>)'
            | MergeDescendants = 'true'
            |  |-Node #8 at (88.0, 1229.0, 201.0, 1283.0)px, Tag: 'Title 1'
            |  | Text = 'Title 1'
            |  | GetTextLayoutResult = 'AccessibilityAction(label=null, action=(kotlin.collections.MutableList<androidx.compose.ui.text.TextLayoutResult>) -> kotlin.Boolean)'
            |  |-Node #11 at (88.0, 1289.0, 794.0, 1379.0)px
            |    Text = 'Get the list of all the assigned tasks in serial order to complete'
            |    GetTextLayoutResult = 'AccessibilityAction(label=null, action=(kotlin.collections.MutableList<androidx.compose.ui.text.TextLayoutResult>) -> kotlin.Boolean)'
            |-Node #13 at (44.0, 1467.0, 1036.0, 1694.0)px
            | OnClick = 'AccessibilityAction(label=null, action=Function0<java.lang.Boolean>)'
            | MergeDescendants = 'true'
            |  |-Node #14 at (88.0, 1500.0, 201.0, 1554.0)px, Tag: 'Title 2'
            |  | Text = 'Title 2'
            |  | GetTextLayoutResult = 'AccessibilityAction(label=null, action=(kotlin.collections.MutableList<androidx.compose.ui.text.TextLayoutResult>) -> kotlin.Boolean)'
            |  |-Node #17 at (88.0, 1560.0, 794.0, 1650.0)px
            |    Text = 'Perform all IoT actions and QC of all devices in the car'
            |    GetTextLayoutResult = 'AccessibilityAction(label=null, action=(kotlin.collections.MutableList<androidx.compose.ui.text.TextLayoutResult>) -> kotlin.Boolean)'
            |-Node #19 at (44.0, 1738.0, 1036.0, 1965.0)px
              OnClick = 'AccessibilityAction(label=null, action=Function0<java.lang.Boolean>)'
              MergeDescendants = 'true'
               |-Node #20 at (88.0, 1771.0, 201.0, 1825.0)px, Tag: 'Title 3'
               | Text = 'Title 3'
               | GetTextLayoutResult = 'AccessibilityAction(label=null, action=(kotlin.collections.MutableList<androidx.compose.ui.text.TextLayoutResult>) -> kotlin.Boolean)'
               |-Node #23 at (88.0, 1831.0, 794.0, 1921.0)px
                 Text = 'Get the list of all the assigned tasks in serial order to complete'
                 GetTextLayoutResult = 'AccessibilityAction(label=null, action=(kotlin.collections.MutableList<androidx.compose.ui.text.TextLayoutResult>) -> kotlin.Boolean)'
    The following test fails even though, you can clearly see in the tree that there are Nodes with Tags
    Section Header
    and `Title 1`:
    fun apiSuccess_showFeatures(): Unit = testCoroutineDispatcher.runBlockingTest {
        composeTestRule.onRoot(useUnmergedTree = true).printToLog("TAG")
    
        composeTestRule.onNodeWithTag("Section Header").assertIsDisplayed()
        composeTestRule.onNodeWithTag("Title 1").assertIsDisplayed()
    }
    If I just test with the following single assertion, the test passes.
    composeTestRule.onNodeWithTag("Section Header").assertIsDisplayed()
    Any idea on what am I doing wrong?
    j
    f
    4 replies · 3 participants
  • g

    grandstaish

    11/20/2020, 1:12 PM
    Is there a reason why
    DefaultSwitchColors
    (and similar colour interface implementations in the Material library) don’t use `data class`es and instead manually implement equals/hashcode?
    m
    m
    +1
    6 replies · 4 participants
  • a

    Anita

    11/20/2020, 1:21 PM
    or do I have to manually change the text color?
    z
    1 reply · 2 participants
  • z

    zoha131

    11/20/2020, 2:19 PM
    Is it possible to remove the blue bar at the bottom from
    TextField
    ?
    g
    a
    4 replies · 3 participants
  • j

    jim

    11/20/2020, 5:35 PM
    I just merged (https://android-review.googlesource.com/c/platform/frameworks/support/+/1506451) support for Kotlin 1.4.20, so for those of you who like living on the edge, a compatible build should appear in the snapshots server very shortly. For the rest of you, it means our next alpha release.
    :party-parrot: 9
    🎉 29
    🙏🏼 3
    j
    i
    +4
    25 replies · 7 participants
  • n

    Nat Strangerweather

    11/20/2020, 5:39 PM
    Hi, I have a bottom drawer for my app and so far all I can find is open/expand/close. Is it possible to define how far down the drawer comes when closed, and how far up it opens when expanded? I'm using the BottomDrawerLayout.
    g
    5 replies · 2 participants
  • l

    Luke

    11/20/2020, 6:43 PM
    Is it possible to mix fragment and composable destination in a
    NavHost
    ? I want to add a fragment that I don’t own, from a library, as a destination. I tried:
    NavHost(
        navController = navController,
        startDestination = route,
    ) {
        composable(...) { ... )
        fragment<LibraryFragment>(id)
    }
    But when I run, the activity crashes with
    Could not find Navigator with name "fragment". You must call NavController.addNavigator() for each navigation type.
    If it’s not possible, is there another way to add a fragment to composition?
    👍 2
    i
    a
    6 replies · 3 participants
  • j

    Joseph D

    11/20/2020, 10:25 PM
    Hi there. In the case of this

    example▾

    , at which stage would you call
    chatVm.getMessages()
    ?
    j
    3 replies · 2 participants
  • d

    Denis

    11/21/2020, 1:32 AM
    Hi folks. Is there a way to customize back button behavior with
    navigation-compose
    ? I want to make a list with multiple selection like in the GMail app. On back button press navigation-compose goes to the previous destination, but I want it to unselect all selected items. I did it with a boolean optional argument
    "items?selected={selected}"
    , but I think it really smells. I suppose it's better to override the default behavior of back button, but I just can't find a solution. Or is there a better approach to the problem?
    i
    v
    5 replies · 3 participants
  • g

    Grigorii Yurkov

    11/21/2020, 10:45 AM
    Is it possible to cancel previous
    LaunchedEffect
    if
    args
    are changed
    LaunchedEffect(args) {
        suspendFunction(args)
    }
    Or it cancels automatically (I have not checked)
    m
    2 replies · 2 participants
  • z

    zoha131

    11/21/2020, 4:59 PM
    How can I clear focus? I have tried
    FocusRequester#freeFocus()
    but it does not work for me.
    l
    d
    +1
    9 replies · 4 participants
  • b

    Bradleycorn

    11/21/2020, 5:14 PM
    with the
    navigation
    component, is there a way to know the size of the backstack? I’m setting up a
    TopAppBar
    (via
    Scaffold
    ) and I’d like to show a back arrow if the current destination is not at the top of the back stack. I’m essentially trying to do something like
    navController.backstack.size > 0
    but the
    backstatck
    property access is restricted to the navigation lib itself. How can I determine the backstack size to know if I should show a back icon or not?
    i
    a
    11 replies · 3 participants
  • a

    alilosoft

    11/21/2020, 6:05 PM
    hey, I know that compose is in alpha, but I want to use it in a psesonal project, a simple Cart app. with the current state of the lib is that acheivable? can I use swing components if I need some use case that is not supported yet?
    c
    t
    4 replies · 3 participants
  • g

    Gabriel

    11/21/2020, 8:23 PM
    message has been deleted
    a
    a
    +1
    11 replies · 4 participants
  • s

    Superblazer

    11/22/2020, 1:51 AM
    Hello, just checking out compose, is it possible to add images into a text field? Like getting an image from a url typed into the text field and then showing the image right below the url?
    g
    1 reply · 2 participants
  • z

    zoha131

    11/22/2020, 8:59 AM
    I have a screen with full of TextFields. How can I get to the last TextField at the bottom when soft keyboard is visible on the screen. I have tried by setting
    adajustpan
    and
    adjustresize
    but those are not working for me.
    a
    r
    +1
    10 replies · 4 participants
  • n

    Nat Strangerweather

    11/22/2020, 10:10 AM
    In this example, I need my offsetPosition to be equal to my min value. How can I do that? If I put 24.0f as offsetPosition, I am not in the right place.
    val max = 202.dp
    val min = 24.dp
    val offsetPosition = remember { mutableStateOf(0f) }
    z
    2 replies · 2 participants
  • a

    Archie

    11/22/2020, 3:06 PM
    In all applications there will always be this three scopes of state:
    b
    a
    +4
    14 replies · 7 participants
  • q

    Quentin Dommerc

    11/22/2020, 3:07 PM
    👋 Hello! I was wondering if there’s a way to debug/profile recomposition. (eg know why my composable is being recomposed, like what changed) ?
    👀 4
    z
    l
    2 replies · 3 participants
  • m

    Mehdi Haghgoo

    11/22/2020, 7:44 PM
    Android Studio 4.2 Canary 15 btw.
    f
    a
    3 replies · 3 participants
  • b

    Bradleycorn

    11/23/2020, 1:33 AM
    Is there any way to use a color from the
    MaterialTheme
    to set a color (like a background color) on an “old style” view that is used via the
    AndroidView
    composable?
    ➕ 1
    c
    1 reply · 2 participants
  • k

    kluck

    11/23/2020, 9:23 AM
    I'm having trouble setting up compose on an existing project. I'm using gradle 6.7.1, kotlin 1.4.10 and compose 1.0.0-alpha07. In my app build.gradle.kts file, I have (simplified) :
    buildFeatures {
            compose = true
        }
    
        kotlinOptions {
            jvmTarget = "1.8"
            useIR = true
        }
    
        composeOptions {
            kotlinCompilerVersion = versions.kotlin
            kotlinCompilerExtensionVersion = versions.compose
        }
    
        compileOptions {
            sourceCompatibility = JavaVersion.VERSION_1_8
            targetCompatibility = JavaVersion.VERSION_1_8
        }
    
    dependencies {
        implementation(libs.compose.ui)
        implementation(libs.compose.tooling)
        implementation(libs.compose.foundation)
        implementation(libs.compose.material)
    }
    When I try to build, I get an error :
    Caused by: org.gradle.internal.event.ListenerNotificationException: Failed to notify project evaluation listener.
    Caused by: java.lang.NoClassDefFoundError: org/jetbrains/kotlin/gradle/tasks/KotlinCompile
    Could it be related to the fact I'm using a .kts build file? -> Doesn't seem to be the case, I just created a Template Compose app, and migrated it to a build.gradle.kts: it works fine
    d
    3 replies · 2 participants
  • l

    louiscad

    11/23/2020, 11:43 AM
    @Leland Richardson [G] Could the new stability inference be exposed in the front-end/IDE, if it makes sense to show it in a way or another? Based on your response to @Yann Badoual's question here:

    https://youtu.be/cSv8HxfLCbs?t=2062▾

    it seems that this possibility has been removed from the current compiler plugin APIs, but it's not clear why. Is that something that could come back with the new FIR once it's ready?
    l
    2 replies · 2 participants
  • t

    tylerwilson

    11/23/2020, 4:46 PM
    I looked in the known issue tracker above, and did not immediately see this listed. I just tried to update to 1.4.20 and I get this compiler crash:
    e: java.lang.NoSuchMethodError: 'org.jetbrains.kotlin.descriptors.Visibility org.jetbrains.kotlin.descriptors.ClassDescriptor.getVisibility()'
    	at androidx.compose.compiler.plugins.kotlin.lower.ClassStabilityFieldSerializationPlugin.afterClass(ClassStabilityFieldSerializationPlugin.kt:57)
    	at org.jetbrains.kotlin.serialization.DescriptorSerializer.classProto(DescriptorSerializer.kt:156)
    	at org.jetbrains.kotlin.incremental.JavaClassesTrackerImplKt.convertToProto(JavaClassesTrackerImpl.kt:88)
    	...
    anybody else see this? any known fix, or should i stay on 1.4.10 for now?
    l
    c
    11 replies · 3 participants
  • g

    grandstaish

    11/23/2020, 4:52 PM
    if i’m trying to mark a
    sealed class
    hierarchy as
    @Immutable
    , should i annotate the base class, the subclasses, or both?
    l
    3 replies · 2 participants
  • k

    Kirill Grouchnikov

    11/23/2020, 5:10 PM
    Looking at https://android.googlesource.com/platform/frameworks/support/+/refs/heads/androidx-master-dev/compose/material/material/samples/src/main/java/androidx/compose/material/samples/SelectionControlsSamples.kt#117 it's not clear how can this scale to anything that requires internationalization. Eventually the selected option needs to be persisted for the next run, or be used to send some info to the server, or anything else that requires some sort of non-string data to be used to indicate the user selection in the group. Is there going to be some kind of a
    RadioGroup
    or
    ToggleGroup
    class in the core Compose for this? Same for segmented toggle buttons (like controlling text alignment, e.g.)
    j
    5 replies · 2 participants
Powered by Linen
Title
k

Kirill Grouchnikov

11/23/2020, 5:10 PM
Looking at https://android.googlesource.com/platform/frameworks/support/+/refs/heads/androidx-master-dev/compose/material/material/samples/src/main/java/androidx/compose/material/samples/SelectionControlsSamples.kt#117 it's not clear how can this scale to anything that requires internationalization. Eventually the selected option needs to be persisted for the next run, or be used to send some info to the server, or anything else that requires some sort of non-string data to be used to indicate the user selection in the group. Is there going to be some kind of a
RadioGroup
or
ToggleGroup
class in the core Compose for this? Same for segmented toggle buttons (like controlling text alignment, e.g.)
j

jim

11/23/2020, 5:16 PM
What is it that concerns you? Is it just the radioValues on line 118? Because you could just load those as String resources and then they can be internationalized by the Android resources system before passing them to Text. Those values were just hard-coded strings for simplicity and easy of authorship.
k

Kirill Grouchnikov

11/23/2020, 5:19 PM
Let's say this represents some choice that needs to be persisted on the server and made available across all user's devices (mobile or desktop). One device might be displaying string in english, and another device might be set to display the same strings in another language. Lines 127 and 134 update the selected state of the "control" on the specific device, but what do I send to the server for persisting my choice? Would that need a more complex data structure in line 118 that has a unique ID for each one of the choices, and then line 128 updates the selected ID?
j

jim

11/23/2020, 5:24 PM
Ultimately engineers can make choices about how they want to write this, Compose is just Kotlin code, so you have some freedoms. But no, you don't need a complex data structure, although you certainly could use one. If you wanted a minimally invasive diff, the only line that would change is 138 were it becomes something like
text = internationalizeFromEnglish(text)
, assuming you use the english variant as your internationalization keys (which has benefits, like being able to search the codebase for english strings to locate the relevant pieces of code based on a UI). Of course, this has drawbacks too, so it is perfectly understandable if you wanted to replace 118 with an integer or enum, but either way, a complex data structure isn't necessary unless you want one.
k

Kirill Grouchnikov

11/23/2020, 5:37 PM
I think I'd go with an enum-driven approach. Something like a payment screen wouldn't even have "simple" radio button rows. Each row might have a bit more info that just one text:
j

jim

11/23/2020, 5:38 PM
Yup, depending on your use case, that makes sense. Kotlin is flexible in this way.
View count: 7