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

    Mehdi Haghgoo

    05/18/2022, 7:29 AM
    Is Compose UI version supposed to diverge from other artifacts in the compose group? I ask because recent IDE versions seem to define version variable in gradle build files only for compose_ui_version.
    :yes: 1
    a
    • 2
    • 1
  • s

    Slackbot

    05/18/2022, 8:03 AM
    This message was deleted.
    t
    • 2
    • 1
  • a

    Alexander Maryanovsky

    05/18/2022, 8:15 AM
    How do I create a bounce animation? I want to scale some text to 1.2 and then back to 1.0, with spring animation both ways.
    y
    f
    • 3
    • 8
  • m

    Michał Diner

    05/18/2022, 9:09 AM
    Hello there! We’re getting a few crashes with ResourcesNotFoundException:
    Fatal Exception: android.content.res.Resources$NotFoundException: Resource ID #0x7f08024a
           at android.content.res.ResourcesImpl.getValue(ResourcesImpl.java:215)
           at android.content.res.Resources.getValue(Resources.java:1316)
           at androidx.compose.ui.res.PainterResources_androidKt.painterResource(PainterResources_androidKt.java:61)
           at x.x.x.presentation.x.ComposableSingletons$xKt$lambda-1$1.invoke(x.kt:66)
           at x.x.x.presentation.x.ComposableSingletons$xKt$lambda-1$1.invoke(x.kt:40)
    It’s a simple usage of Image with
    painterResource
    . Any ideas? 😬
    a
    j
    • 3
    • 3
  • s

    Slackbot

    05/18/2022, 12:58 PM
    This message was deleted.
  • b

    Brian Norman

    05/18/2022, 1:03 PM
    Using Coil to load an image in Compose, and trying to fit the image into a box with a height < heightOfImage. Anyone know of a way to make the Coil crop bias towards cropping the top portion of an image, so that the bottom of the image is kept? I tried a custom shape to use in
    Modifier.clip()
    like:
    val preferBottomContentShape = GenericShape { size, _ ->  
        moveTo(0f, size.height - desiredHeightPx)
        lineTo(size.width, size.height - desiredHeightPx)
        lineTo(size.width, size.height)
        lineTo(0f, size.height)
    }
    But the issue there is that there is left over whitespace from the background where the top of that image used to be
    o
    • 2
    • 3
  • a

    Afzal Najam

    05/18/2022, 5:41 PM
    Is there a
    calculateWindowSizeClass
    equivalent for non-activities? We’re using a fair bit of
    AbstractComposeViews
    , leveraging interop capabilities and so activity instance isn’t available without casting the
    Context
    👀 Is this not enough? Or does rememberWidthSizeClass provide something else that this doesn’t?
    @Composable
    fun getWidthSizeClass(): WidthSizeClass {
        val configuration = LocalConfiguration.current
        val windowDpSize = configuration.screenWidthDp.dp
        return when {
            windowDpSize < 600.dp -> WidthSizeClass.COMPACT
            windowDpSize < 840.dp -> WidthSizeClass.MEDIUM
            else -> WidthSizeClass.EXPANDED
        }
    }
    l
    • 2
    • 8
  • a

    allan.conda

    05/18/2022, 6:09 PM
    Is it expected that
    HorizontalPager
    immediately composes adjacent pages other than the current page? I don’t want my
    LaunchedEffect
    to run if the page is not visible yet, or is it expected that I check for
    pagerState.currentPage
    ?
    y
    • 2
    • 5
  • f

    Fanilog

    05/18/2022, 6:44 PM
    I’ve a question related to Compose and Coroutine. Would it be an issue doing something like this
    //TOP level composable of the app
    with(LocalLifecycleOwner.current) {
        lifecycleScope.launch {
            navigationManager.navigationEvents
                .flowWithLifecycle(lifecycle, Lifecycle.State.STARTED)
                .collect { navigationDirection ->
                //Listening to navigation event
                navController.navigate()...          
                }
        }
    Or should I do it in LaunchEffect ? Since Compose function can execute in any order, I wanted to avoid to have it a LaunchEffect and use a replay parameter of a Flow. (eg: Sending a event before the collection,)
    m
    z
    • 3
    • 4
  • m

    Manojna Chintapalli

    05/18/2022, 7:28 PM
    Hi! I am trying to achieve something like this - a camera icon on top of a circular image, I already have the circular image in place, but I am not sure how to place the icon on top of it using compose. Any ideas or helpful links are appreciated. Thanks!
    v
    l
    • 3
    • 2
  • s

    Sterling Albury

    05/18/2022, 7:52 PM
    working on a composable and would like some feedback. doing a TopAppBar with this content:
    Row(
                    modifier = Modifier
                        .fillMaxWidth(),
                    horizontalArrangement = Arrangement.SpaceBetween
                ) {
                    leftHandContent(
                        Modifier
                            .wrapContentWidth()
                    )
    
                    Text(
                        modifier = Modifier
                            .wrapContentWidth()
                            .align(CenterVertically)
                            .weight(1F, fill = true),
                        text = appBarTitle,
                        color = topBarPrimaryColor,
                        fontWeight = FontWeight.Bold,
                        fontSize = 22.sp,
                        textAlign = TextAlign.Center
                    )
    
                    rightHandContent(
                        Modifier
                            .wrapContentWidth()
                    )
                }
    I would like the Text to be in the center of the bar but also be constrained by the left and right hand content. If one of the content items is missing, then I'd still like the text to be centered in the row. Considering a couple of options here. I briefly tried using a Box and using the align modifiers for the content items, but the text wasn't getting constrained like i wanted and got some overlap with the contents. trying to not use the constraint layout. Was looking at a custom layout and using some vertical baselines but not very familiar with using those objects. Any thoughts?
    s
    c
    o
    • 4
    • 9
  • b

    brabo-hi

    05/18/2022, 9:03 PM
    Hi all, coud we use markdown with
    Text()
    a
    s
    • 3
    • 2
  • f

    fengdai

    05/19/2022, 5:10 AM
    In the view system, a child view in a FrameLayout can be bigger than its parent, and be clipped to show only part of its content. How can I achieve this effect in Jetpack Compose?
    b
    t
    a
    • 4
    • 7
  • a

    allan.conda

    05/19/2022, 6:59 AM
    We can’t preload the list in compose so situations like Image grid UX is not good. Does anyone have a workaround around this?
    c
    • 2
    • 10
  • r

    Rene Win

    05/19/2022, 9:01 AM
    Hello, i have an issue with screen reader and jetpack compose: When I'm using Modifier.testTags the screen reader order is not correct (detail3 is marked instead of detail1) when navigating to a other screen - see code and video below: Some notes on the code (I can provide the whole application if necessary): Home is the root view with just some text and a button, which opens the detail composable
    @Composable
    fun Home(navController: NavController) {
        Column(
            modifier = Modifier.testTag("hometag")
        ) {
            Text("home1")
            Text("home2")
            Button(onClick = {
                navController.navigate("detail",
                )
            }) {
                Text("NEXT")
            }
    
        }
    }
    
    @Composable
    fun Detail(navController: NavController) {
        Column(
            modifier = Modifier
                .testTag("detailTag")
        ) {
            Text("detail1")
            Text("detail2")
            Text("detail3")
        }
    }
    Is there something I can do against that behaviour? Thanks in advance!
    recording.mp4
    j
    z
    • 3
    • 13
  • f

    Fanilog

    05/19/2022, 9:30 AM
    Hello trying to dig a bit more in compose and I’m not really sure. Despite having the remember returning me the job, is there another difference ?
    val lifecycleOwner = LocalLifecycleOwner.current
    LaunchedEffect(key1 = lifecycleOwner) {
        launch {
    and
    val lifecycleOwner = LocalLifecycleOwner.current
    remember(key1 = lifecycleOwner) {
        with(lifecycleOwner) {
            lifecycleScope.launch {
    ?
    f
    • 2
    • 10
  • d

    dimsuz

    05/19/2022, 12:53 PM
    We have released a set of Detekt rules which help us find common errors while working on Compose code. For now there are few rules there, which seem more or less generally applicable (of course, they can be turned on/off individually if they don't work for you): https://github.com/appKODE/detekt-rules-compose
    🎉 3
    f
    a
    +2
    • 5
    • 19
  • f

    FunkyMuse

    05/19/2022, 1:24 PM
    hey guys, is there a way to have a context receiver being a Composable function?
    context (Composable)
    n
    • 2
    • 2
  • r

    Rajat Singh Jasrotia

    05/19/2022, 3:12 PM
    Hey Guys, Could you please help as how can I place a frame over an image in compose as shown in attached figure?
    c
    c
    • 3
    • 2
  • h

    Hamza GATTAL

    05/19/2022, 3:17 PM
    Hi everyone It's my first time using compose I want to implement the splash screen API My question is how I can do it
    s
    c
    • 3
    • 3
  • m

    mcpiroman

    05/19/2022, 3:37 PM
    My `value class`wrapping `String`always causes parameter to be `unstable`(as per `plugin:androidx.compose.compiler.plugins.kotlin:metricsDestination`option), even though https://issuetracker.google.com/issues/144582214 is
    fixed
    , so it should be inferred as stable. Can I somehow make it became stable?
    m
    s
    u
    • 4
    • 6
  • f

    Francescos

    05/19/2022, 4:50 PM
    Is it correct that
    NavBackStackEntry.savedStateHandle
    is a complete different object from the
    SavedStateHandle
    object injected from Hilt in the corresponding route
    ViewModel
    ?
    i
    • 2
    • 3
  • m

    mattinger

    05/19/2022, 4:57 PM
    Has anyone been able to test a dropdown style control? We built a control with a card, that when you click on it would display a DropdownMenu for the user to pick items from (think the Spinner in the XML world). However, when i’m trying to test it in the robolectric environment with a ComposeTestRule, i can perform the click, but i can never do anything else, presumably because the idler things that compose is still doing something. As a result, it just sits there on the next call to
    onNode
    type functions. As a side note, it works in an espresso test, just not robolectric.
    a
    • 2
    • 7
  • c

    Chris Fillmore

    05/19/2022, 6:33 PM
    Could someone help clarify this statement in the docs, re:
    centroid
    https://developer.android.com/reference/kotlin/androidx/compose/foundation/gestures/package-summary#(androidx.compose.ui.i[…]olean,kotlin.Function4)
    onGesture
    will also provide centroid of all the pointers that are down.
    Are the centroid coordinates relative to the display? The window? Something else?
    k
    a
    • 3
    • 30
  • l

    Landry Norris

    05/19/2022, 9:25 PM
    I don’t see a separate channel for decompose, so I’ll ask my question here: I have a Component that has several instances of the same sub-component, which will get rendered in a Column. Each one has fairly complex logic and is independent from the others, so I’m thinking one Component class, and an array of instances. I can see here that I should use childComponent with a unique key. Is there a good way to create an array of childComponent built in, or should I have the keys be Bar0, Bar1, Bar2, etc?
    x
    a
    • 3
    • 4
  • z

    Zoltan Demant

    05/20/2022, 4:22 AM
    Has anyone else started seeing more and more
    Fatal Exception: java.lang.IllegalArgumentException: end cannot negative. [end: -1]
    since one of the recent compose (alpha/beta) releases?
    ➕ 1
    s
    a
    • 3
    • 6
  • e

    Eko Prasetyo

    05/20/2022, 4:28 AM
    Hi everyone, does anyone ever facing laggy issue when using navigation-animation libary from accompanist? Is there any way to optimize that?
    b
    • 2
    • 5
  • z

    zt

    05/20/2022, 4:31 AM
    I'm having a crash caused by navigating from a screen containing a lazy column to another one, then navigating back. The stack trace doesn't point to any of my code so I'm not sure what's going on
    stack.txt
    b
    a
    • 3
    • 7
  • j

    Jan Skrasek

    05/20/2022, 7:02 AM
    API design: I have rather complex composable component taking multiple slots arguments. Is it better to have: • main slot named
    content
    and having it as the last one, or • make that slot rather named by its function and sort slots differently? The second option seems more suitable, but only if there is another non slot argument as the last one, otherwise it would expose the last slot as trailing lambda, which is not good. What do you think?
    s
    • 2
    • 8
  • s

    Stylianos Gakis

    05/20/2022, 7:03 AM
    I was looking at the UI events documentation here and I have once thing I am confused about which I’d love to discuss here. In the last code snippet of the linked section, right under “causing another UI state update:“, in the compose version, we’re looking at
    viewModel.uiState.userMessages
    inside the LaunchedEffect, but with no mechanism to ensure that this only happens when the app is in the foreground. Wouldn’t this mean that if I were to press home on my device, and right as I do that a message appears, this would trigger normally, and I would miss that message. On the contrary, in the View version, we’re using the
    repeatOnLifecycle
    API to make this work correctly. Maybe this has to do something with the fact that we’re using a
    State<T>
    object inside the VM in that sample instead of a
    [State]Flow
    and there’s some interaction I don’t understand, but I still think this would happen in the background even with that approach. p.s. I really wish the docs followed the more “common” pattern of having a StateFlow inside the VM instead. Or at least show how you’d have to approach this problem with both
    State
    and
    StateFlow
    in the VM.
    c
    m
    • 3
    • 9
Powered by Linen
Title
s

Stylianos Gakis

05/20/2022, 7:03 AM
I was looking at the UI events documentation here and I have once thing I am confused about which I’d love to discuss here. In the last code snippet of the linked section, right under “causing another UI state update:“, in the compose version, we’re looking at
viewModel.uiState.userMessages
inside the LaunchedEffect, but with no mechanism to ensure that this only happens when the app is in the foreground. Wouldn’t this mean that if I were to press home on my device, and right as I do that a message appears, this would trigger normally, and I would miss that message. On the contrary, in the View version, we’re using the
repeatOnLifecycle
API to make this work correctly. Maybe this has to do something with the fact that we’re using a
State<T>
object inside the VM in that sample instead of a
[State]Flow
and there’s some interaction I don’t understand, but I still think this would happen in the background even with that approach. p.s. I really wish the docs followed the more “common” pattern of having a StateFlow inside the VM instead. Or at least show how you’d have to approach this problem with both
State
and
StateFlow
in the VM.
I remembered that tivi has a convenience function here named rememberStateWithLifecycle which does exactly what I am looking for. But the sad part is that, I can almost see myself almost always preferring that one over the normal
.collectAsState()
extension on
StateFlow
. There’s very few cases where I’d purposefully allow the state to be collected in the background (they exist, but by default I want the
rememberStateWithLifecycle
approach).
Went ahead and posted this in nowinandroid too to potentially get some official examples inside a real app. I think there’s some room for improvement around the communication of how this very common issue should be solved.
c

Colton Idle

05/25/2022, 1:54 PM
@Manuel Vivo What do you think about "but with no mechanism to ensure that this only happens when the app is in the foreground. Wouldn’t this mean that if I were to press home on my device, and right as I do that a message appears, this would trigger normally, and I would miss that message." I think @Stylianos Gakis brings up a good point that I didn't think about?
🤗 1
m

Manuel Vivo

05/30/2022, 8:49 AM
Definitely! Thanks for raising this. We already started working on this :D https://android-review.googlesource.com/c/platform/frameworks/support/+/2102573/
s

Stylianos Gakis

05/30/2022, 9:20 AM
Wow thank you SO much Manuel, yes this is exactly what I had in mind! Is this something that you’ve had on your todo list after making the initial UI event docs or was it a result of community feedback? I am just curious 🤔 It would be an amazing combo if once this is merged, you managed to get an example of using this in now-in-android repo too!
m

Manuel Vivo

05/30/2022, 10:19 AM
We’ve been having these conversations for a long time already. But the work is materializing now 🙂
s

Stylianos Gakis

05/30/2022, 10:24 AM
Nice, super happy to see it coming together!
🙌 2
c

Colton Idle

06/02/2022, 9:13 AM
Manuel published this yesterday. I haven't read it... but maybe related @Stylianos Gakis? https://medium.com/androiddevelopers/viewmodel-one-off-event-antipatterns-16a1da869b95
s

Stylianos Gakis

06/02/2022, 9:41 AM
No, not quite touching on the
collectAsState
vs
collectAsStateWithLifecycle
problem, since that one is not out yet I guess they are not going to be talking about it yet. In fact, in the last snippet, the compose and View alternatives are not functionally equivalent since one reads the state in the background as well while the View alternative uses repeatOnLifecycle as one should. I hope that once the
collectAsStateWithLifecycle
hits alpha/beta this article will be updated and all future ones will take it into consideration. A good article nonetheless, I read it before and it was a nice read.
View count: 9