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

    Rafs

    03/21/2022, 12:15 PM
    createAndroidComposeRule
    doesn't allow calling
    setContent
    anymore if the root content of the Activity has already been set. I remember this used to work in compose beta versions but it's now throwing an
    IllegalStateException
    . I found it to be a really handy way in compose UI testing. Is there any reason why the behaviour was changed?
    a
    j
    • 3
    • 4
  • m

    myanmarking

    03/21/2022, 12:51 PM
    Is there any specific way of setting padding for a coil image? Atm, with a padding modifier, the image is being ‘resized’ at the start. It’s really fast, so not so easy to see. But this must not be the intended behavior. Any1 having same issues ?
    • 1
    • 1
  • d

    dimsuz

    03/21/2022, 1:35 PM
    When using composable navigation, how do I remember something only for the duration of "screen visible"?
    composable("/my/route") {
      val value = remember { HeavyValue() }
      MyScreen(value)
    }
    Whenever I navigate back and then forward to this screen, I'd like
    HeavyValue
    to be recreated. In code above it is created once and persists: push/pop/push <-- will get the same value
    c
    h
    +2
    • 5
    • 15
  • m

    marios proto

    03/21/2022, 1:42 PM
    👋 I have updated to compose 1.1.1 and together the compose.material to 1.1.1, but since then , in a button in my app there is some change on the way an OutlineButton is rendered. so from this, it ended up as this. Anything known issue on this? the code is quite basic
    OutlinedButton(
        onClick = actionClick,
        enabled = enabled,
        colors = buttonColors,
        modifier = modifier
            .border(
                border = BorderStroke(
                    width = 1.dp,
                    color = if (enabled) borderColor else disabledColor
                ),
                shape = RoundedCornerShape(4.dp),
            )
    ) {
        Text(
            text = actionText.uppercase(),
            textAlign = TextAlign.Center,
            style = CompanyTheme.typography.body,
            maxLines = 1,
            modifier = Modifier.semantics {
                contentDescription = actionContentDescription
            }
        )
    }
    f
    c
    • 3
    • 8
  • a

    Aditya Murthy

    03/21/2022, 1:43 PM
    Does anyone know how to easily support marquee texts? I'm currently using the custom implementation mentioned here - stackoverflow.com/questions/68974245/marquee-text-effect-in-jetpack-compose but I see some issues with it when dealing with texts in lazy row
    z
    • 2
    • 1
  • m

    Michal Klimczak

    03/21/2022, 1:47 PM
    I'm trying to use `BasicTextField`'s
    decorationBox
    and showing / hiding the texfield itself when its focus / value changes. There is an issue that when it hides, there is an exception. I guess we should not completely get rid of the inner text field in this scenario, rather hide it - so a simple
    if
    and
    AnimatedVisibility
    will not work here. What I'm looking for is something like the old
    View.GONE
    . Or just a possibility to go from wrapContent to 0 height and vice versa. Any hints how to best achieve it?
    z
    • 2
    • 4
  • i

    iamthevoid

    03/21/2022, 2:01 PM
    is there way to make constructor composable? I want pass through it data that calculates with composable function. It will always call in composable context. Can i do it somehow?
    i
    a
    j
    • 4
    • 4
  • t

    Tgo1014

    03/21/2022, 3:23 PM
    Can I somehow animate from wrap content to fill max width?
    c
    • 2
    • 4
  • a

    Alejandro Moya

    03/21/2022, 4:14 PM
    Hey everyone! hope you’re doing well, have a quick question, how can I disable a view and it’s descendants interaction?, clicks and all
    m
    z
    • 3
    • 3
  • s

    Simon Stahl

    03/21/2022, 6:47 PM
    I just stumbled over an interesting lazy list behavior. Turns out the item composables are actually cached and recycled to a certain degree? See demo code in comments
    j
    i
    +2
    • 5
    • 20
  • c

    Chris Johnson

    03/21/2022, 8:30 PM
    Is it possible to combine
    animateContentSize
    with say an alpha animation? If not, what's the way we should go about this? Say I want to update the alpha alongside the size change for a
    Text
    . Currently it animates the size first and doesn't appear to get any alpha updates. Code in 🧵
    c
    d
    • 3
    • 4
  • j

    james

    03/21/2022, 9:31 PM
    if I have a
    Row
    containing just a
    TextField
    and a
    Button
    , what's the proper way to set the TextField's height to always match the Button height? I thought giving the TextField this modifier would do the trick, but it doesn't.. the TextField is still much taller than my button:
    Modifier.height(IntrinsicSize.Min)
    m
    • 2
    • 2
  • c

    colintheshots

    03/21/2022, 9:55 PM
    Is there a recommended way to merge two MutableStates into one emitting changes from the most recently updated?
    r
    m
    +2
    • 5
    • 11
  • m

    Mehmet Peker

    03/21/2022, 10:00 PM
    I have an application written with Jetpack Compose in the Google Play Store. I have a custom dialog inside the application. I did not come across it, but my users are getting an IlegalArgumentException error when using Image. Why am I getting this error?
    java.lang.IllegalArgumentException: 
      at androidx.compose.ui.res.PainterResources_androidKt.loadImageBitmapResource (PainterResources_android.kt)
      at androidx.compose.ui.res.PainterResources_androidKt.painterResource (PainterResources_android.kt)
    c
    p
    • 3
    • 5
  • a

    Android75

    03/22/2022, 7:52 AM
    hi i have to develop text witth link and different color.. i can use row.. but is there a Spannable alternative in compose?
    f
    c
    • 3
    • 4
  • s

    Slackbot

    03/22/2022, 8:25 AM
    This message was deleted.
    f
    n
    • 3
    • 2
  • k

    Kareem Waleed

    03/22/2022, 9:03 AM
    Is there a way to inspect the elements on the screen (metadata, positions, etc ...) while using compose ? In the views system this was done by recursing on the children of the activity's
    DecorView
    , but now using compose there's only one view added to the activity's
    DecorView
    which is a
    ComposeView
    that contains no details about the composables dawn inside. Any ideas ?
    a
    a
    +2
    • 5
    • 6
  • t

    Tgo1014

    03/22/2022, 9:41 AM
    My elevation shadows are being cut, any way I can fix this? Just for a bit of context, this is not a default
    FAB
    component, but a custom one because I want to transform it into a bottom sheet
    f
    • 2
    • 6
  • b

    Benjamin Deroche

    03/22/2022, 9:53 AM
    I tried to make a "pulse" animation but the result is really bad, the icon inside the button keep "shaking" due to some rounding errors in the size and padding calculation.
    Box(
        modifier = Modifier.fillMaxSize()
    ) {
        val infiniteTransition: InfiniteTransition = rememberInfiniteTransition()
        val initialSize: Float = 72f
        val pulsingSize: Float = 88f
        val size: Float by infiniteTransition.animateFloat(
            initialValue = initialSize,
            targetValue = pulsingSize,
            animationSpec = infiniteRepeatable(
                animation = tween(
                    durationMillis = 1000,
                    easing = LinearEasing
                ),
                repeatMode = RepeatMode.Reverse
            )
        )
        val paddingReduction: Float = (size - initialSize) / 2
        FloatingActionButton(
            modifier = Modifier
                .align(Alignment.BottomCenter)
                .padding((16f - paddingReduction).dp)
                .size(size.dp),
            onClick = {}
        ) {
            Icon(
                imageVector = Icons.Default.ArrowUpward,
                contentDescription = "To the top!"
            )
        }
    }
    f
    a
    • 3
    • 25
  • v

    Vladas

    03/22/2022, 11:13 AM
    Found possible bug while trying to optimize my apps when using different declarations of
    MutableState
    •
    var value by remember { mutableStateOf(default) }
    •
    val (value, setValue) = remember { mutableStateOf(default) }
    Bad one. In this one composable recomposes every time counter is updated (each second)
    @Composable
    fun App() {
        val (counter, setCounter) = remember { mutableStateOf(1) }
    
        LaunchedEffect(null) {
            var i = 1
            while (true) {
                delay(1000)
                setCounter(++i)
            }
        }
    
        println("recomposition")
        val str by remember { derivedStateOf { (counter % 10 == 0).toString() } }
        Text(str)
    }
    This one works properly. Recomposes only when needed str changes. (every 10 seconds two times)
    @Composable
    fun App() {
        var counter by remember { mutableStateOf(1) }
    
        LaunchedEffect(null) {
            var i = 1
            while (true) {
                delay(1000)
                counter = ++i
            }
        }
    
        println("recomposition")
        val str by remember { derivedStateOf { (counter % 10 == 0).toString() } }
        Text(str)
    }
    Same behavior using android and js.
    f
    a
    z
    • 4
    • 8
  • n

    nuhkoca

    03/22/2022, 11:48 AM
    Hello! How do I rotate the gradient 180 degree?
    Brush.linearGradient(
        0.5f to Color(0xFF26313C).copy(alpha = .0f),
        1.0f to Color(0xFF26313C).copy(alpha = .6f)
    )
    ✅ 1
    a
    • 2
    • 2
  • j

    julioromano

    03/22/2022, 2:27 PM
    When using the
    Layout()
    composable is there a way to somehow group the `measurables`/`placeables` by some property of my data model?
    I’m trying to create a custom layout composable which places its children according to some property of the data model from which the children themselves are created. But from within the
    Layout()
    block the children are exposed as `measurable`/`placeable` so there is no visibility into their props. Is there a way to pass any property from my data model or from the child composables into their respective measurables/placeables? Or any other way to achieve this (e.g. meta-data or anything else)?
    ✅ 1
    a
    n
    • 3
    • 5
  • j

    Jakub Ledwon

    03/22/2022, 3:17 PM
    Is there any composable that has no body and only takes modifier? For example if I wanted to create colored square. I know that I can use
    Box
    but I wonder if there is something just for this use case
    f
    a
    • 3
    • 2
  • t

    Tgo1014

    03/22/2022, 3:18 PM
    Is there a way to animate from
    wrapContentWidth()
    to
    fillMaxWidth()
    without using
    animateContentSize()
    ? When I use this modifier it clips the elevation shadow 😕
    f
    d
    • 3
    • 6
  • r

    Ravi

    03/22/2022, 4:18 PM
    Hi, I’m getting the following error in
    release
    variant after upgrading constraintlayout(compose) to 1.0.0, it’s working fine in
    1.0.0-rc01
    . Please let me know if any proguard rules to be added to avoid this crash, more in 🧵
    • 1
    • 1
  • n

    nuhkoca

    03/22/2022, 4:20 PM
    Hello, whenever I apply a border to my
    Card
    , there is being a darker image on the rounded corners on the light mode. Is this a known bug?
    Card(
        modifier = modifier,
        shape = RoundedCornerShape(3.dp),
        border = BorderStroke(1.dp, MyTheme.colors.appBackground3)
    ) {
        ...
    }
    z
    m
    • 3
    • 8
  • a

    andrew

    03/22/2022, 4:31 PM
    Some Compose embedded in SystemUI's Device Control quick access tile screen 😊
    👍 3
    • 1
    • 1
  • m

    Michal Klimczak

    03/22/2022, 4:42 PM
    I was trying to read the focus state in BasicTextField decorationBox based on this but it doesn't seem to work. Minimum reproduction in 🧵 (print never fires)
    z
    c
    l
    • 4
    • 33
  • d

    Dmitry Strekha

    03/22/2022, 5:10 PM
    Is there any way to overlap items in LazyList? In RecyclerView we could set negative offsets in
    ItemDecoration#getItemOffsets
    I tried
    Modifier#offset
    , but seems it affects only the item on which the modifier was applied, so items below do not shift
    r
    m
    z
    • 4
    • 6
  • g

    Guilherme Almeida

    03/22/2022, 5:36 PM
    Hey there 👋 When searching for composable screens that could be recomposing unnecessarily I found out a screen which is basically a
    LazyColumn
    with mostly
    TextFields
    inside I noticed they were all recomposing on every key stroke for any of the fields. So if I type in something in the first field, the other fields, even though they did not change their value, will also recompose. After experimenting a bit I pinned it down to using the
    onFocusChanged
    modifier for these text fields. After removing the
    onFocusChanged
    modifier the text fields seem to skip composition. Is this the expected behaviour ? Quick repro (I am using the the recomposeHighlighter to visualize recompositions):
    val state = remember {
          List(20) { it to "" }.toMutableStateMap()
        }
    
        LazyColumn(Modifier.fillMaxSize()) {
          itemsIndexed(state.values.toList()) { index, string ->
            TextField(
              value = string,
              onValueChange = { state[index] = it },
              modifier = Modifier
                .recomposeHighlighter()
                .onFocusChanged {  }
            )
          }
        }
    👀 2
    m
    p
    • 3
    • 15
Powered by Linen
Title
g

Guilherme Almeida

03/22/2022, 5:36 PM
Hey there 👋 When searching for composable screens that could be recomposing unnecessarily I found out a screen which is basically a
LazyColumn
with mostly
TextFields
inside I noticed they were all recomposing on every key stroke for any of the fields. So if I type in something in the first field, the other fields, even though they did not change their value, will also recompose. After experimenting a bit I pinned it down to using the
onFocusChanged
modifier for these text fields. After removing the
onFocusChanged
modifier the text fields seem to skip composition. Is this the expected behaviour ? Quick repro (I am using the the recomposeHighlighter to visualize recompositions):
val state = remember {
      List(20) { it to "" }.toMutableStateMap()
    }

    LazyColumn(Modifier.fillMaxSize()) {
      itemsIndexed(state.values.toList()) { index, string ->
        TextField(
          value = string,
          onValueChange = { state[index] = it },
          modifier = Modifier
            .recomposeHighlighter()
            .onFocusChanged {  }
        )
      }
    }
👀 2
m

myanmarking

03/22/2022, 7:46 PM
If the onfocuschanged lambda content calls something not stable, it is possible it may be the cause. What are you doing in onfocuschanged?
g

Guilherme Almeida

03/22/2022, 8:29 PM
I also thought that but it happens even when it is empty, like in the example I provided
m

myanmarking

03/22/2022, 8:48 PM
Hm ok. Is that composable declared inside a fragment by any chance?
p

Paul Woitaschek

03/22/2022, 8:53 PM
Bildschirmaufnahme 2022-03-22 um 21.52.41.mov
Confirmed in a sandbox environment: https://gist.github.com/PaulWoitaschek/34c352ffbe08a9e33a6e62def5b9802f
@Guilherme Almeida It is because it can’t omit recomposition as long as it’s not in its own composable
With one big composable, its inputs seem to be everything that’s before that code
Bildschirmaufnahme 2022-03-22 um 21.57.55.mov
g

Guilherme Almeida

03/22/2022, 9:02 PM
Ah interesting 🤔 In the app the text field is passed in through two composables (by passing a composable lambda), but the composable itself is created in the main composable I guess
I guess if you try to pass in the modifier from the main composable it will also recompose right?
m

myanmarking

03/22/2022, 9:06 PM
ToMutableStateMap, is that stable?
g

Guilherme Almeida

03/22/2022, 9:06 PM
I can test it a bit more tomorrow, thank you very much 🙏
I would expect it to be, and without the modifier recomposition occurs as expected 🤔
m

myanmarking

03/22/2022, 9:09 PM
Oh. The second item recompose is the focus change it makes sense
g

Guilherme Almeida

03/23/2022, 12:12 PM
So after testing it a bit more the problem seems to be where the
onFocusChanged
modifier is created, so If the modifier is created in the main composable it recomposes for every new state there, if it is inside its own composable then it only recomposes when the state has changed. Wrapping the modifier with
remember
also works, but does not seem ideal
View count: 8