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

    Landry Norris

    10/03/2022, 5:44 PM
    When using createEmptyComposeRule and launching the activity myself, is there a way to still perform actions and make assertions using the EmptyComposeRule? The activity needs to take in data using Intents, but is otherwise fully Compose. After I create an empty compose rule, then launch the activity using ActivityScenario.launch<MyActivity>(intent), I get an error when I try to make an assertion on the rule.
    z
    • 2
    • 3
  • j

    jossiwolf

    10/03/2022, 7:00 PM
    Please file an issue with a repro project here: https://issuetracker.google.com/issues/new?component=742043
  • o

    oday

    10/03/2022, 7:11 PM
    can recomposition be described in terms of Views like:
    "recomposition is the process of removing all of the views on the screen > going over your code again > depending on state > adding different views to the screen"
    ?
    c
    z
    • 3
    • 4
  • a

    Aaron Waller

    10/04/2022, 6:17 AM
    Hey, I heard Flows are very bad for the performance of Jetpack Compose due to the fact that they are not stable. My whole app is using flows, what else should I use? (MVVM)
    c
    z
    +3
    • 6
    • 21
  • a

    Anton Shilov

    10/04/2022, 8:29 AM
    Hey, folks! I’m creating heavy AndroidViews (ads) inside
    LazyVerticalGrid
    and noticed that factory param in
    AndroidView
    Composable is called each time an item loses and obtains visibility. It’s not ideal, as creating and destroying heavy Views makes scroll not smooth due to janky frames. Is there any mechanism in Compose that would allow me recycle Views inside LazyVerticalGrid apart from creating a pool of Views and managing it myself?
    z
    r
    • 3
    • 5
  • d

    dniHze

    10/04/2022, 9:52 AM
    👋 Is there a way to disable automatic code and compose preview side-by-side IJ layout when opening a kt file with composables in it?
    • 1
    • 1
  • o

    Oleksandr Balan

    10/04/2022, 10:59 AM
    Similar 🧵: https://kotlinlang.slack.com/archives/CJLTWPH7S/p1656496283156679
    b
    • 2
    • 1
  • e

    elye

    10/04/2022, 11:34 AM
    For compose
    rememberSaveable
    , are the variables restore sequence per the order of the line coded? I have a case where it seems that way (or perhaps a Google bug?). To explain clearly what I meant with full code in https://stackoverflow.com/questions/73947154/remembersaveable-restore-value-type-influenced-by-the-order-of-the-code Can someone help? 🙏
    z
    • 2
    • 5
  • k

    KotlinLeaner

    10/04/2022, 12:07 PM
    Hello guys, I am learning in State in jetpack compose. I found that State holders as source of truth. So created my some data can you guys guide me if I am doing wrong here.
    z
    • 2
    • 20
  • o

    oday

    10/04/2022, 2:15 PM
    how would I get an instance of navController to give to the Composable in Previews?
    t
    s
    • 3
    • 13
  • z

    Zach Klippenstein (he/him) [MOD]

    10/04/2022, 2:40 PM
    You could align by the last baseline, but that might not work when the text is empty. @Halil Ozercan do you have any ideas?
    z
    h
    a
    • 4
    • 6
  • v

    Vinay Gaba

    10/04/2022, 4:41 PM
    In most of these cases, creating a library for hosting just a few lines of code doesn’t make sense. Unfortunately, there is no good way for these code snippets to be discoverable once they are shared and they often get lost in the deep corners of Slack 😞
    k
    • 2
    • 3
  • d

    Daniele Segato

    10/04/2022, 4:52 PM
    This article suggest that we should pass all parameters with lambdas (among the other things) to optimize performances with compose. Edit: what I'm asking is "when is OK (performance wise) for a Composable to not be skippable" From what I understood tho': 1) recomposition is not really an issue if it happens in an "empty" function that just pass parameters to other composables without actually drawing any UI 2) the in-between composables that do not use parameters directly but just pass them down to other composables will be skipped. Are my 2 assumption above false? Is the article right? Thanks https://t.co/9kC6BaTJbi
    • 1
    • 1
  • j

    jim

    10/04/2022, 5:04 PM
    Compose Compiler with Kotlin 1.7.20 support is now published on gmaven.
    j
    a
    z
    • 4
    • 3
  • a

    Abhishek Dewan

    10/04/2022, 6:20 PM
    Hi folks, I remember reading something about composition local providers very sparingly in your compose code in this channel but I can't find it again. Is anyone aware of any downsides of relying too much on composition locals ?
    j
    j
    +3
    • 6
    • 11
  • c

    Chuck Stein

    10/04/2022, 6:52 PM
    Is it possible for a composable that's always part of our UI tree to leave the composition and then re-enter, without the "on resume" lifecycle callback being called?
    s
    • 2
    • 3
  • a

    Abhishek Dewan

    10/04/2022, 10:52 PM
    Hi folks. Had a question around compose navigation multiple back stacks. Working on a requirement where each of the 4 bottom navigation tabs has its own backstack. That can be easily achieved by using the multiple backstack feature in compose navigation. However a bug I’m noticing is that one of the tabs navigates to another, the bottom item associated with that tab isn’t selected anymore. This is because the current route of the navgraph isn’t any of the 4 tabs anymore and is something else. question: Does anyone have a good way of dealing with this? I know of a way which requires me going through the backqueue in navhostcontroller and figuring it out using that. It works mostly but seems hacky. Wanted to see if other folks have had to deal with that
    i
    a
    • 3
    • 3
  • e

    elye

    10/05/2022, 2:24 AM
    Hi, I have the following code
    @Composable
    fun MyComposableFun(textValue: String) {
    
        val newTextValue = remember(textValue) { mutableStateOf(textvalue) }
    
        val myComposeView = remember {
            MyComposable().apply {
                setContent { Text(newTextValue) }
            }
        }
    
        Column(horizontalAlignment = Alignment.CenterHorizontally) {
            Text("Title: $newTextValue")
            myComposeView.myComposable?.invoke()
        }
    }
    
    class MyComposable {
        var myComposable: (@Composable () -> Unit)? = null
    
        fun setContent(content: @Composable () -> Unit) {
            myComposable = content
        }
    }
    On initial load it's okay. But when
    textValue
    changed, and the function got called again, • The
    Text("Title: $newTextValue")
    got updated - which is good • The
    setContent { Text(newTextValue) }
    don't get updated. Why? Did I get anything wrong?
    s
    • 2
    • 5
  • s

    Stylianos Gakis

    10/05/2022, 7:30 AM
    I’ve had a lot of luck with Live Edit in Flamingo Canary 1. Are you on that one? But in general it is a feature which is not that reliable, at least not yet.
    c
    k
    c
    • 4
    • 10
  • d

    Daniele Segato

    10/05/2022, 8:41 AM
    How do I use wide gamut colors in compose? In my app i had
    values/colors.xml
    and
    values-widecg/colors.xml
    that were picked up by my theme. There's a constructor for
    Color()
    that takes
    colorSpace = ColorSpaces.ExtendedSrgb
    , I assume i have to use this. Than what? Just check if the current window display is wide gamut to pic one color or the other? Anything else i need to do? Any handy Local provider to obtain this or do i need to go through the
    LocalContext
    , find the activity etc...? Do I need the activity
    android:colorMode="wideColorGamut"
    ? Couldn't find much documentation around this topic. Thanks
  • s

    Sebastian Höbarth

    10/05/2022, 9:53 AM
    Just pushed my first 100% compose App to the Play Store. The pre-launch report discovered 2x crashes. And I can’t figure out what the Problem is with compose. Can you help me?
    Fatal Exception: java.lang.IndexOutOfBoundsException: offset(13) should be less than line limit(12)
           at android.text.TextLine.measure(TextLine.java:389)
           at android.text.Layout.getHorizontal(Layout.java:1246)
           at android.text.Layout.getHorizontal(Layout.java:1222)
           at android.text.Layout.getPrimaryHorizontal(Layout.java:1192)
           at android.text.Layout.getPrimaryHorizontal(Layout.java:1181)
           at androidx.compose.ui.text.android.LayoutHelper.getDownstreamHorizontal(LayoutHelper.java:11)
           at androidx.compose.ui.text.android.TextLayout.getPrimaryHorizontal(TextLayout.java:11)
           at androidx.compose.ui.text.platform.AndroidParagraph.b(AndroidParagraph.java:11)
           at androidx.compose.ui.text.MultiParagraph.getBoundingBox(MultiParagraph.java:42)
           at androidx.compose.ui.text.TextLayoutResult.getBoundingBox(TextLayoutResult.java:42)
           at androidx.compose.ui.platform.AndroidComposeViewAccessibilityDelegateCompat.addExtraDataToAccessibilityNodeInfoHelper(AndroidComposeViewAccessibilityDelegateCompat.java:164)
           at androidx.compose.ui.platform.AndroidComposeViewAccessibilityDelegateCompat$MyNodeProvider.addExtraDataToAccessibilityNodeInfo(AndroidComposeViewAccessibilityDelegateCompat.java:164)
           at android.view.AccessibilityInteractionController.populateAccessibilityNodeInfoForView(AccessibilityInteractionController.java:430)
           at android.view.AccessibilityInteractionController.findAccessibilityNodeInfoByAccessibilityIdUiThread(AccessibilityInteractionController.java:363)
           at android.view.AccessibilityInteractionController.-$$Nest$mfindAccessibilityNodeInfoByAccessibilityIdUiThread(AccessibilityInteractionController.java)
           at android.view.AccessibilityInteractionController$PrivateHandler.handleMessage(AccessibilityInteractionController.java:1647)
           at android.os.Handler.dispatchMessage(Handler.java:106)
           at android.os.Looper.loopOnce(Looper.java:201)
           at android.os.Looper.loop(Looper.java:288)
           at android.app.ActivityThread.main(ActivityThread.java:7898)
           at java.lang.reflect.Method.invoke(Method.java)
           at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:548)
           at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:936)
    z
    • 2
    • 3
  • k

    Kefas

    10/05/2022, 9:54 AM
    How is this data class inferred as unstable? Which contract it doesn't comply with?
    data class User(val id: Int) {
        private var name = "a"
    }
    
    unstable class User {
      stable val id: Int
      stable var name: String
      <runtime stability> = Unstable
    }
    l
    z
    • 3
    • 3
  • m

    Michal Klimczak

    10/05/2022, 9:59 AM
    This is not going to be too specfiic, but maybe omeone can point me in the right direction at least. We get very weird random crashes (sometimes it's NPE, sometimes IndexOutOfBounds and sometimes low level stuff like SIGSEGV). It can be reproduced by rapidly clicking a refresh button which asynchronously (but quickly, think milliseconds) updates the composable state. Only on production (non-debuggable, proguarded) builds.
    • 1
    • 1
  • k

    Kata

    10/05/2022, 10:01 AM
    Is there a way in compose to implement
    CollapsingToolbarLayout
    ? With the new material design 3 I can see that it is possible to use
    LargeTopAppBar
    and it has a
    scrollBehaviour
    but it is not working with images and also it is not high enough and it is always reopening if I scroll up not just when I reach the top of the screen.
    k
    • 2
    • 3
  • n

    Nikolas Guillen Leon

    10/05/2022, 10:18 AM
    I have a LazyColumn which show a MutableStateList of items: is it normal that when I update a single item in the list, all the visible items get recomposed? even though I they do not change in any way
    s
    z
    • 3
    • 6
  • o

    Oleksandr Balan

    10/05/2022, 11:24 AM
    You should pass the shape to the
    .border()
    modifier. Also I think
    .clip()
    is not needed in this case.
    o
    j
    • 3
    • 9
  • a

    Asad Mukhtar

    10/05/2022, 11:28 AM
    Hi, Which dependency you use for loading images in Compose?
    c
    • 2
    • 1
  • m

    mattinger

    10/05/2022, 12:39 PM
    Does anyone know a good way to change the current locale in a paparazzi test that uses compose? I have a parameterized test:
    @RunWith(Parameterized::class)
    class ScreenshotTest(val selectedLocale: Locale) {
        @get:Rule
        val paparazzi: Paparazzi = Paparazzi(
            theme = "android:Theme.MaterialComponents.Light.NoActionBar",
            deviceConfig = DeviceConfig.NEXUS_5.copy(softButtons = false, screenHeight = 3000),
            renderingMode = SessionParams.RenderingMode.V_SCROLL
        )
    
        companion object {
            @Parameterized.Parameters(name = "{0}")
            @JvmStatic
            fun locales() = listOf(
                Locale("en", "US"),
                Locale("es", "US"),
                Locale("fr", "CA"),
                Locale("it", "IT"),
            )
        }
    
    }
    But i’m having trouble getting the locale to change. I tried Locale.setDefault before calling paparazzi.snapshot, but that didn’t seem to have any effect. I’m still getting english strings.
    z
    • 2
    • 1
  • d

    Djaka Pradana Jaya Priambudi

    10/05/2022, 12:47 PM
    Side effect is retaining old value from returned composable is this expected? and how to avoid this?
    @Composable
    fun foo(): Int {
        var counter by mutableStateOf(0)
        LaunchedEffect(Unit) {
            while (true) {
                delay(500)
                counter++
                println("Foo: $counter")
            }
        }
        return counter
    }
    
    @Composable
    fun bar() {
        val foo = foo()
        LaunchedEffect(Unit) {
            while (true) {
                delay(500)
                println("Bar: $foo")
            }
        }
    }
    Output in thread, but the the second composable will always returns: "Bar: 0"
    b
    o
    • 3
    • 10
  • t

    Tower Guidev2

    10/05/2022, 12:47 PM
    Hi i am looking for a "Gallery" of Android Compose Material3 Theme (Colors) so that i could use these in a demo application i am developing i cannot find any open source sites that have such sample themes Do any exist? does Google supply the themes for their standard apps like Gmail etc? Ideally I would like samples in the format available for download from the Material Theme Builder web site
    k
    • 2
    • 2
Powered by Linen
Title
t

Tower Guidev2

10/05/2022, 12:47 PM
Hi i am looking for a "Gallery" of Android Compose Material3 Theme (Colors) so that i could use these in a demo application i am developing i cannot find any open source sites that have such sample themes Do any exist? does Google supply the themes for their standard apps like Gmail etc? Ideally I would like samples in the format available for download from the Material Theme Builder web site
k

Kirill Grouchnikov

10/05/2022, 2:55 PM
Material3 has a baseline purple color theme detailed at https://m3.material.io/styles/color/the-color-system/tokens. In addition, on Android 12+, you can use dynamic colors extracted from the user wallpaper as detailed at https://m3.material.io/styles/color/dynamic-color/user-generated-color. In both cases, you have access to five tonal palettes - two neutrals and three accents. From there, Material builds layers of tokens - see https://m3.material.io/foundations/design-tokens/how-to-read-tokens - that abstract away specific RGB values, the differences between light and dark mode, or usage of baseline vs dynamic colors. There are apps on Google Play such as https://play.google.com/store/apps/details?id=com.ch3d.material.color that would show you the tonal palettes that correspond to the current user selection.
t

Tower Guidev2

10/05/2022, 3:02 PM
i have tried the baseline purple color theme and others (custom) from the Material Theme Builder web site I am happy with the Light theme associayted with these themes however I like the Gmail dark theme better than any of the ones generated from the Material Theme Builder web site how do i get an "improved" dark theme for composed material3?
View count: 12