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

    Raid Xu

    06/14/2022, 5:07 PM
    When playing with Snapshot system, I find if I take a snapshot and create a
    state: State<T>
    in it, then dispose the snapshot, the created
    state
    can’t be read from
    GlobalSnapshot
    , which makes sense. However if anything triggered
    advanceGlobalSnapshot
    (for example
    registerApplyObserver
    ), the new
    GlobalSnaphot
    will be able to read the
    state
    now (because the new
    GlobalSnapshot
    no longer remember the disposed snapshot in invalid snapshots). Is this a bug?
    s
    z
    c
    • 4
    • 10
  • k

    kotlinforandroid

    06/14/2022, 5:45 PM
    I want to open a custom "sheet" when the user presses a button. Not a BottomSheet but rather some content that draws over the bottombar and topbar, taking all space available. How can I do that with
    NavGraph
    if my
    NavGraph
    is nested inside a
    Scaffold
    ?
    ✅ 1
    i
    • 2
    • 2
  • o

    orangy

    06/14/2022, 6:27 PM
    I have a
    Text
    component with
    AnnotatedString
    with some `ParagraphStyle`s in it. Is there any way to setup spacing between paragraphs? I want something like half lineHeight between them.
    • 1
    • 1
  • z

    zsperske

    06/14/2022, 9:43 PM
    Does anyone have a good example of how they’ve achieved the cascading styles we got from XML? Things like
    Button.Flat.Blue.Small
    ➕ 1
    v
    • 2
    • 1
  • s

    spierce7

    06/14/2022, 9:54 PM
    How would I use an image as a mask in compose? I have an effect that I’m drawing as a Shader, but I only want it to be applied there there are non-transparent pixels for an image. How would I do that?
    r
    k
    s
    • 4
    • 44
  • f

    Feri Nagy

    06/15/2022, 7:54 AM
    We are trying to use paging together with sticky headers. But now instead of using
    items(pagingItems) {}
    , we have to iterate through the items manually, do
    pagingItems.peek(index)
    and add single
    item {}
    one by one:
    @Composable
    fun PlainPaging(pagingItems: LazyPagingItems<Item>) {
        LazyColumn {
            items(pagingItems) { item ->
                when (item) {
                    is Item.Header -> Text(text = item.title)
                    is Item.Data -> Text(text = item.text)
                    null -> Text("placeholder")
                }
            }
        }
    }
    
    // vs
    
    @OptIn(ExperimentalFoundationApi::class)
    @Composable
    fun StickyPaging(pagingItems: LazyPagingItems<Item>) {
        LazyColumn {
            for (index in 0 until pagingItems.itemCount) {
                when (val item = pagingItems.peek(index)) {
                    is Item.Header -> stickyHeader { Text(text = item.title) }
                    is Item.Data -> item { Text(text = item.text) }
                    null -> item { Text("placeholder") }
                }
            }
        }
    }
    Is this going to have some performance implications? Is there a better way to do it? Thanks
    ➕ 1
    a
    • 2
    • 3
  • a

    allan.conda

    06/15/2022, 3:15 PM
    What’s the simplest way to declare a layout with a header and a footer? Scaffold is simple but I heard it’s expensive to use.
    c
    • 2
    • 9
  • r

    ryan.fonzi

    06/15/2022, 3:53 PM
    Is the
    expanded
    logic for
    ExposedDropdownMenuBox
    wonky right now? I'm trying to use it for autocomplete results via an editable
    OutlinedTextField
    nested inside. When the dropdown menu is expanded, it's consuming "backspace" inputs to try to dismiss itself. In order to actually delete a character, I have to basically hit backspace twice. Once to dismiss the popup, and another to actually delete the character. Has anyone run into this behavior?
    • 1
    • 1
  • d

    Dylan

    06/15/2022, 4:05 PM
    Hi there, I'm developing an app which has a similar architecture to the Now In Android app. The thing is, my NavHost is wrapped by a Navigation Drawer, and I would like to provide the item for that navigation drawer via a ViewModel. Would it be a good practice to have a ViewModel inside the app module, or should I rather create a new module exclusively for the Navigation Drawer?
    m
    • 2
    • 7
  • a

    Artem Bezlyubchenko

    06/15/2022, 4:07 PM
    Hello guys, may anyone help me with
    MediumTopAppBar
    |
    LargeTopAppBar
    please. It shows two lines on toolbar. I’m using Material3 and I don’t use old material components… Code is in the thread
    n
    • 2
    • 10
  • c

    Chris Fillmore

    06/15/2022, 4:32 PM
    What is the difference between using these two scopes?
    val scope1 = rememberCoroutineScope()
    val scope2 = LocalLifecycleOwner.current.lifecycleScope
    a
    • 2
    • 13
  • o

    orangy

    06/15/2022, 7:17 PM
    I’m trying to implement some custom
    Layout
    , and somehow the content gets centered. I’ve measured this single item (image), placed it at (0,0) in a
    layout
    call with the size of the image (measured total children), and I expect it to be in the top left corner of the red area (parent size). Why is it in the center? Green rectangle depicts inner bounds of the parent, as if there was padding or something.
    z
    • 2
    • 3
  • n

    Nat Strangerweather

    06/15/2022, 8:34 PM
    If I convert a
    Color
    value to
    Int
    (using
    toArgb()
    ) so I can save it in Datastore, how would I then convert the
    Int
    back to Jetpack Compose
    Color
    ?
    s
    r
    f
    • 4
    • 7
  • s

    Simon Stahl

    06/16/2022, 1:50 AM
    Hi. I'm still fiddling around with navigation, but have two questions that I just cannot find the answer to. I am basically using the default bottom nav example found here and adjusted it for my requirements. In my case, the bottom tabs are received from a server call at app start and are the only known navigation destinations. In each tab, I can navigate to sub-pages with an unknown name (with navigation destination
    page/{pageName}
    ). Questions: 1.
    currentDestination?.hierarchy
    does not contain the root tab name after navigating to a sub page, so the tab does not stay selected 2. I would like to change the back behavior. By default, back first pops the current tabs backstack. Once it is empty, it moves to the
    startDestination
    (root page in the first tab with backstack empty). I would like to change that to: pop backstack of current tab. Once empty, switch to last used tab including backstack and start popping there. Once empty switch to the next last used tab etc. If there are no more backstack entries, close the app. For reference, please find my sample code in the comments
    i
    c
    • 3
    • 23
  • z

    Zoltan Demant

    06/16/2022, 4:19 AM
    Does this mean that (some) collections are now inferred as
    @Stable
    ? :60fps_parrot:
    "kotlinx.collections.immutable.ImmutableList"
    "kotlinx.collections.immutable.ImmutableSet"
    "kotlinx.collections.immutable.ImmutableMap"
    🚀 1
    b
    a
    • 3
    • 4
  • h

    Heikki Rauhala

    06/16/2022, 7:13 AM
    Hi, has anybody else encountered memory leaks within lazy columns embedded deep within a composition? I tried to replicate the problem with https://github.com/reaktor/ComposeImageMemoryLeak on a couple of different versions of compose, but could not. However I know of two completely distinct proprietary projects that leak image references in compose 1.2.0, but not in 1.1.0. The leak is shown by the image loader always loading the images from memory after the first time they have been loaded. We've tried different image loaders with 1.2.0, but that did not make a difference.
    🤔 1
    • 1
    • 1
  • m

    madhuri gupta

    06/16/2022, 7:42 AM
    Hello, Need some help is updating state in compose. I am maintaining selected items in a list. I want to clear list and update UI. I am setting empty list in Livedata. But not getting callback in observer. Can someone please suggest. Code Snippet: selectedLocalityLiveData.postValue(_emptyList_())
    c
    • 2
    • 1
  • r

    Ravi

    06/16/2022, 8:07 AM
    Hi, we are observing crash in devices that have free ram less than 1gb. Its basically fb news feed with different types of compose views and normal viewholders inside recyclerview, we are unable to replicate the issue but firebase logs are popping up alot, stacktrace in the 🧵
    c
    t
    • 3
    • 3
  • h

    Hamza GATTAL

    06/16/2022, 2:05 PM
    Is Compose compiler 1.2.0-rc01 version compatible with kotlin 1.7.0 version
    j
    f
    • 3
    • 2
  • j

    julioromano

    06/16/2022, 2:06 PM
    I’m using
    pointerInput
    and
    graphicsLayer
    to implement 360 degree scrolling on a composable (using translationX and translationY). It seems to work but I can scroll the composable infinitely (bringing it completely out of the screen), how is it possible to compute the actual bounds of the composable so that I can stop the translation when the bounds have been reached?
    c
    • 2
    • 2
  • o

    orangy

    06/16/2022, 2:27 PM
    🐛 Looks like there is a bug in measuring annotated strings with indents. Given
    ParagraphStyle(textIndent = TextIndent(0.sp, 12.sp))
    and string
    "sdkjfn\nskdjfn\n"
    I get the result as in attached image. Expected:
    sdkjfn
      skdjfn
    Looks like indents are not considered during measuring of overall size, and then when laying out it have to wrap line.
    s
    z
    • 3
    • 5
  • s

    spierce7

    06/16/2022, 5:34 PM
    I feel a little dumb for asking this, but is there a way to allow a child Composable to be larger than a parent Composable?
    :yes: 1
    t
    a
    • 3
    • 8
  • v

    Vinay Gaba

    06/16/2022, 8:38 PM
    There's been some conversation here about how your Compose apps/features should handle config changes manually - https://kotlinlang.slack.com/archives/CJLTWPH7S/p1618760581089700?thread_ts=1618691113.058800&amp;cid=CJLTWPH7S This makes sense to me and I've been lucky to follow these conversations from the early days. However, I'm not seeing this recommendation in the official docs to be able to share with my team. Is there any documentation available that I might've missed. If not, I'm sure this is on your radar but I want to flag it anyway.
    a
    a
    • 3
    • 13
  • m

    Marco Pierucci

    06/17/2022, 2:21 PM
    Hello hello! Wha would be the ideal node to match a node In a pager compsable, with same text being presed in adjacent pages ( I:E next button) Im following this solution https://akjaw.com/wiriting-ui-tests-for-pager-layouts-jetpack-compose/ it works but you kind of need to know the page you want to match whic is not really ideal for a dynamic pager
    • 1
    • 1
  • t

    Tower Guidev2

    06/17/2022, 3:03 PM
    Help 😄
    • 1
    • 2
  • a

    Andy Himberger

    06/17/2022, 3:44 PM
    I reported this in issuetracker already, but does anyone know if there is a workaround to get Previews which reference resources working in your application modules when in a multi-module project with nonTransitiveRClasses enabled? https://issuetracker.google.com/issues/236141674
    • 1
    • 2
  • m

    Manojna Chintapalli

    06/17/2022, 6:22 PM
    Hello! Does anyone have a good example for aligning TextField label and the line (underline) properly? There seems to be some gap between their starting points. Thanks in advance!
    c
    l
    • 3
    • 4
  • c

    Colton Idle

    06/17/2022, 7:58 PM
    I have a straight forward button that I want to launch an share intent. Right now I just wrote a fun in my composable file based off of this. It works fine. But I feel like maybe I shouldn't do this in my composable? I see three choices: 1️⃣ Should I bubble this event up to my nav host/activity to handle 2️⃣ Should I try to do this in my VM and have Hilt inject a context 3️⃣ Having it done like I do now "in the composable" is fine
    1️⃣ 1
    j
    f
    +2
    • 5
    • 9
  • c

    Colton Idle

    06/17/2022, 9:12 PM
    I got a design that's similar to this where my design team wants text for the "Cancel" and "Done" buttons. Is there anything special or out of the box to do this? I know I can just make a row with text + clickable modifier, but is there anything else I should take into account so that I get the nice touch target of typical TopAppBar action items?
    e
    f
    +2
    • 5
    • 10
  • t

    Tgo1014

    06/17/2022, 11:47 PM
    Using compose navigation, how can I make sure one destination has only one instance? I'm handling a intent from the main screen to a detail screen, but if the user click many times the intent then when pressing back it goes to the previous detail screen instead of the main screen
    f
    i
    • 3
    • 21
Powered by Linen
Title
t

Tgo1014

06/17/2022, 11:47 PM
Using compose navigation, how can I make sure one destination has only one instance? I'm handling a intent from the main screen to a detail screen, but if the user click many times the intent then when pressing back it goes to the previous detail screen instead of the main screen
f

Francesc

06/17/2022, 11:51 PM
you can query the current destination before you try to navigate, if you are no longer where you expect to be then ignore the button click
t

Tgo1014

06/17/2022, 11:53 PM
I found this, settings where it should pop up to works I guess: https://stackoverflow.com/a/71412193/6022725
f

Francesc

06/17/2022, 11:54 PM
when you handle the button click, you can check this
if (navController.currentBackStackEntry?.destination != <nav id of where the button is>) {
   // navigate
}
t

Tgo1014

06/17/2022, 11:56 PM
Let me try
f

Francesc

06/17/2022, 11:56 PM
you probably want to get the
route
or the
id
from the backstack entry to compare, I'm just typing this from memory
t

Tgo1014

06/17/2022, 11:56 PM
Hmm but in my case it doesn't work because I still need to navigate, the thing is when going back
My issue is like A -> B -> B -> B
so when I go back instead of always A -> B
f

Francesc

06/17/2022, 11:57 PM
do you want to debounce clicks on the back button to navigate back?
t

Tgo1014

06/17/2022, 11:58 PM
No, I want to go back to the first one, skipping all the B instances
f

Francesc

06/17/2022, 11:58 PM
then you can use popUpTo(A, inclusive = false)
t

Tgo1014

06/17/2022, 11:59 PM
Using this solved for now, just not sure it's the best way
navController.navigate(B) {
    popUpTo(A) {
         inclusive = false
    }
}
f

Francesc

06/17/2022, 11:59 PM
not
popUpTo
but
popBackStack
but that's the idea
t

Tgo1014

06/18/2022, 12:04 AM
I tried
popBackStack
but for wear when you swipe back it goes back to another B, if I set it as
popUpTo
then it works 👀
i

Ian Lake

06/18/2022, 12:11 AM
This is exactly what
launchSingleTop
is for. Have you tried using that?
to only have a single instance of a destination on the top of the stack
t

Tgo1014

06/18/2022, 12:12 AM
Isn't this a Manifest thing? I've just one activity where all destinations are composable screens
i

Ian Lake

06/18/2022, 12:12 AM
navController.navigate(B) {
  launchSingleTop = true
}
t

Tgo1014

06/18/2022, 12:13 AM
Oh, I didn't know you could use it like this, seems like this would solve the problem 😄
i

Ian Lake

06/18/2022, 12:13 AM
Covered in the docs, FWIW: https://developer.android.com/jetpack/compose/navigation#nav-to-composable
t

Tgo1014

06/18/2022, 12:14 AM
Yeah, my google search failed me 😄 Thanks for the help Ian!
👍 1
View count: 14