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

    loloof64

    01/08/2022, 9:57 AM
    Hi eveyone ! I have a
    LazyColumn
    where doing a long click on each of item is supposed to show the same
    DropDownMenu
    but above the item. I know that I can control the position of the
    DropDownMenu
    using a
    Box
    , but what is the most efficient way to handle this feature ? Should I add conditionnaly (with an
    if
    clause) a
    DropDownMenu
    for each item ? I mean, inside each item inside
    LazyColumn
    , use a
    Box
    and
    if(menuOpened){ DropDownMenu{...}}
    ? Or should I avoid that ?
    • 1
    • 1
  • m

    myanmarking

    01/08/2022, 11:24 AM
    if i observe a state data class in compose, and inside i have a snapshotlist. To recompose on list changes i just need to change the list, regardless of emitting or not a new state. Is this right ?
    c
    z
    • 3
    • 5
  • l

    Luis Daivid

    01/08/2022, 2:08 PM
    I’m making an app using bottomNavigation. However, whenever I touch the bottom tab, it is recomposed and the screen is updated. When I searched the navigation document, it came out like the one below,
    By using the saveState and restoreState flags, the state and back stack of that item is correctly saved and restored as you swap between bottom navigation items.
    and of course it is recomposed every time even though it is applied. What should I do?
    a
    i
    • 3
    • 3
  • j

    Javier

    01/08/2022, 2:09 PM
    Is there an
    OnPointerEvent
    common API for Desktop and Android?
    a
    • 2
    • 16
  • s

    Solomon Tolu Samuel

    01/08/2022, 10:58 PM
    Hello, I was wondering if the is any example out there on how to implement location updates(with foreground service) in compose?
    z
    • 2
    • 2
  • d

    David W

    01/09/2022, 6:16 AM
    Any suggestions on how to add a full-width horizontal divider to a
    LazyVerticalGrid
    with adaptive cells? I searched here and google, but there weren't any solutions. edit: all set, came up with a different solution.
    • 1
    • 6
  • d

    David W

    01/09/2022, 8:15 AM
    Is there a way to either change the center of a component or center a specific item in a row, with other items to either side of it? I'd like to make a specific word be the center of a Text, essentially.
    p
    f
    c
    • 4
    • 14
  • s

    Stylianos Gakis

    01/09/2022, 4:34 PM
    I got a local object that I am creating in compose which requires cleanup when it is destroyed. Currently I am doing:
    val lifecycleOwner = LocalLifecycleOwner.current
    var audioPlayer: AudioPlayer? by remember {
        mutableStateOf(null)
    }
    DisposableEffect(audioUrl, lifecycleOwner) {
        val localAudioPlayer = AudioPlayer(audioUrl, lifecycleOwner)
        audioPlayer = localAudioPlayer
        onDispose {
            localAudioPlayer.cleanup()
        }
    }
    So using DisposableEffect to make sure to cleanup the AudioPlayer in case any of the keys change and I create a new instance of AudioPlayer so I cleanup the old one, or if it leaves the composition. This feels a bit hacky however, especially with the initial null state above it, making the code below this awkward too. Is there some better approach I could possibly look into instead?
    d
    z
    • 3
    • 20
  • r

    Rob

    01/09/2022, 5:26 PM
    I am trying to make a collapsing toolbar with Material3. I want the AppBar to layout under the statusbar so that when it collapses the content will scroll under the statusbar. I've added padding to the AppBar but when it is collapsed it doesn't collapse the padding. Is there a way to collapse the padding on the AppBar as well? Thanks!
    Untitled.kt
    d
    c
    • 3
    • 5
  • d

    dewildte

    01/09/2022, 7:02 PM
    Does anybody know if Rive is going to integrate with Compose the same way they did with Flutter?
    k
    t
    • 3
    • 3
  • a

    Ayfri

    01/09/2022, 10:57 PM
    Hey, is it possible to have a TextField required to be filled ?
    c
    • 2
    • 1
  • d

    David W

    01/10/2022, 4:50 AM
    Here's a very weird bug. Having the below code in a Card that has a Border (a normal, solid, 1dp non-conditional border) causes the Card's Border to use a horizontal gradient color (and a radial if i change the below to use radial). The super bizarre thing is that it swaps between using the gradient and showing the expected solid line when I move my mouse around, like a flicker, without any modifiers set up that do things based on mouse movement.
    Box(
                        modifier = Modifier
                            .background(
                                brush = Brush.horizontalGradient(
                                    colors = listOf(
                                        MaterialTheme.colors.primary.lighten(50).copy(alpha = 0.35f),
                                        Color.Transparent
                                    ),
                                )
                            )
                            .size(32.dp)
                    )
                    {}
    z
    • 2
    • 24
  • s

    Slackbot

    01/10/2022, 10:57 AM
    This message was deleted.
    a
    • 2
    • 1
  • d

    dimsuz

    01/10/2022, 2:30 PM
    Ok, it looks like
    LocalWindowInsets.current.ime.bottom
    does not update after keyboard is hidden. it continues to report padding as though keyboard is visible 🤔
    c
    • 2
    • 2
  • s

    Samir Basnet

    01/10/2022, 2:34 PM
    In BottomSheetScaffold i have set sheetGesturesEnabled to false yet i can drag and close the bottom sheet . Anything i am missing??
    • 1
    • 1
  • m

    Michael Langford

    01/10/2022, 5:32 PM
    I have a list of Packages. When a user taps one, they can edit it. We do this in a dialog. I'm having a bit of an issue handling the indirection. How do I pass the correct package to the viewModel that's associated with what's on the dialog when showing it? The naive way to do so seems like it would literally create a dialog per list item. Creating a view model and creating one dialog, does not seem to later let me change fields on the view model to specify the user selection.
    c
    • 2
    • 3
  • c

    Colton Idle

    01/10/2022, 9:36 PM
    I'm trying to create a non-lazy carousel. i.e. Scrollable Row with each item being about 90% of the full screen width. I have a small sample showing that I'm failing. Anyone that can spot my issue?
    z
    m
    d
    • 4
    • 78
  • b

    Billy Newman

    01/10/2022, 10:46 PM
    Should a ComposeView inside bottom sheet (behavior) handle scroll events correctly? As an example from the compose documentation:
    Simple nested scrolling requires no action on your part. Gestures that initiate a scrolling action are propagated from children to parents automatically, such that when the child can't scroll any further, the gesture is handled by its parent element.
    When I scroll up in the bottom sheet, the bottom sheet first resizes to fill the screen then properly scrolls to the bottom of the content, which is the expected behavior. However, when trying to scroll back to the top of the content (ie dragging down), the bottom sheet starts to collapse instead of scrolling the content down first.
    a
    • 2
    • 5
  • e

    eygraber

    01/10/2022, 10:58 PM
    I'm getting the following error when showing a preview in AS 7.2 alpha 🧵
    • 1
    • 2
  • r

    Rick Regan

    01/11/2022, 12:46 AM
    I was looking to use mutable state to declare a variable without initializing it and with the benefit of delegate syntax. If I do
    lateinit var myState: MutableState<MyState>
    then I have to reference with
    myState.value.myProperty
    . If I do
    var myState: MyState? by mutableStateOf(null)
    then I have to reference with
    myState?.myProperty
    (or other ways of dealing with nullable types). Is there a form that lets you use
    myState.myProperty
    with
    lateinit
    ?
    a
    • 2
    • 3
  • a

    Afzal Najam

    01/11/2022, 1:24 AM
    I can’t find an assertion for background color (or any colors) in Compose UI test functions nor in any documentation so far. Is there a way to check whether an element has an expected background color?
    z
    • 2
    • 2
  • e

    eygraber

    01/11/2022, 1:56 AM
    Is there anything like
    expandedHintEnabled=false
    from
    TextInputLayout
    for a
    TextField
    ?
    c
    • 2
    • 8
  • l

    linus muema

    01/11/2022, 4:55 AM
    I had recently discovered a default shimmer effect on Jetpack compose for loading layouts but I can't seem to find the docs. Does anyone know where I can find it or a similar implementation? 🤔
    c
    • 2
    • 2
  • e

    eygraber

    01/11/2022, 5:00 AM
    Is there any issue with passing a
    java.time.LocalDate
    to a composable function, or should it be wrapped in something marked as
    @Immutable
    ?
    ➕ 1
    g
    a
    d
    • 4
    • 7
  • s

    Scott Kruse

    01/11/2022, 5:03 AM
    How do you know if a screen was resumed in a pure compose app?
    e
    c
    • 3
    • 4
  • s

    Samir Basnet

    01/11/2022, 6:04 AM
    I am starting to doubt whether Jetpack Compose is a step forward or backwards. It is really starting to get on my nerves , i was excited as building the UI is handsdown simple and quick but man the navigation is a mess specially with the bottomsheet. I mean now i have to worry about back handling too.
    a
    c
    • 3
    • 9
  • k

    K Merle

    01/11/2022, 6:46 AM
    Is it possible to resize image (make it bigger) with modifier, but for an image to keep the same ratio?
    d
    • 2
    • 3
  • d

    Deepak Gahlot

    01/11/2022, 7:35 AM
    Hello All,
    :this-is-fine: 1
    :thread-please: 1
    c
    • 2
    • 7
  • m

    myanmarking

    01/11/2022, 10:28 AM
    how can we sort a SnapshotList. is it better just to create a new list i supposed. notification spam ?
    d
    z
    +3
    • 6
    • 25
  • d

    Damian Kwaśniak

    01/11/2022, 11:18 AM
    Hi, I have a RecyclerView where my ViewHolder has XML view inside. One of its children is ComposeView. Following the documentation of Interoperability APIs, I set view composition strategy like this:
    setViewCompositionStrategy(DisposeOnViewTreeLifecycleDestroyed)
    It works fine as long as I am not updating the view when it is still attached to the window. If so, I get an exception added in thread. 1. User enters the RecyclerView where each item has show more button 2. User press show more button what causes the view to redraw (bind method from ViewHolder is called) 3. crash Any ideas?
    :thread-please: 1
    😬 1
    a
    • 2
    • 5
Powered by Linen
Title
d

Damian Kwaśniak

01/11/2022, 11:18 AM
Hi, I have a RecyclerView where my ViewHolder has XML view inside. One of its children is ComposeView. Following the documentation of Interoperability APIs, I set view composition strategy like this:
setViewCompositionStrategy(DisposeOnViewTreeLifecycleDestroyed)
It works fine as long as I am not updating the view when it is still attached to the window. If so, I get an exception added in thread. 1. User enters the RecyclerView where each item has show more button 2. User press show more button what causes the view to redraw (bind method from ViewHolder is called) 3. crash Any ideas?
:thread-please: 1
😬 1
java.lang.IllegalStateException: View tree for androidx.compose.ui.platform.ComposeView{f43c13c G.E...... ......ID 58,413-912,470 #7f090115 app:id/contactOpportunityItemRelatedContactsComposeView} has no ViewTreeLifecycleOwner
        at androidx.compose.ui.platform.ViewCompositionStrategy$DisposeOnViewTreeLifecycleDestroyed.installFor(ViewCompositionStrategy.android.kt:109)
        at androidx.compose.ui.platform.AbstractComposeView.setViewCompositionStrategy(ComposeView.android.kt:136)
        at com.siemens.presentation.contactdetails.viewholder.opportunity.OpportunityViewHolder.bind(OpportunityViewHolder.kt:78)
        at com.siemens.presentation.contactdetails.viewholder.opportunity.OpportunityViewHolder.bind(OpportunityViewHolder.kt:49)
        at com.siemens.presentation.accountdetails.AccountDetailsAdapter.onBindViewHolder(AccountDetailsAdapter.kt:136)
        at androidx.recyclerview.widget.RecyclerView$Adapter.bindViewHolder(RecyclerView.java:7337)
        at androidx.recyclerview.widget.RecyclerView$Recycler.tryBindViewHolderByDeadline(RecyclerView.java:6194)
        at androidx.recyclerview.widget.RecyclerView$Recycler.tryGetViewHolderForPositionByDeadline(RecyclerView.java:6460)
        at androidx.recyclerview.widget.RecyclerView$Recycler.getViewForPosition(RecyclerView.java:6300)
        at androidx.recyclerview.widget.RecyclerView$Recycler.getViewForPosition(RecyclerView.java:6296)
        at androidx.recyclerview.widget.LinearLayoutManager$LayoutState.next(LinearLayoutManager.java:2330)
        at androidx.recyclerview.widget.LinearLayoutManager.layoutChunk(LinearLayoutManager.java:1631)
        at androidx.recyclerview.widget.LinearLayoutManager.fill(LinearLayoutManager.java:1591)
        at androidx.recyclerview.widget.LinearLayoutManager.onLayoutChildren(LinearLayoutManager.java:668)
        at androidx.recyclerview.widget.RecyclerView.dispatchLayoutStep2(RecyclerView.java:4309)
        at androidx.recyclerview.widget.RecyclerView.dispatchLayout(RecyclerView.java:4012)
        at androidx.recyclerview.widget.RecyclerView.onLayout(RecyclerView.java:4578)
a

Arjun Achatz

01/11/2022, 12:52 PM
Try ViewCompositionStrategy.DisposeOnLifecycleDestroyed
I remember something about the docs not being exactly right about this one
d

Damian Kwaśniak

01/11/2022, 2:00 PM
What I did is:
binding.lifecycleOwner?.let {
                val strategy = ViewCompositionStrategy.DisposeOnLifecycleDestroyed(it)
                setViewCompositionStrategy(strategy)
            }
and in the init block of my ViewHolder I have to set binding's lifecycleOwner manually with:
init {
        binding.lifecycleOwner = parent.findViewTreeLifecycleOwner()
    }
but I am not sure if this solution is an equivalent of whet they suggest in the documentation
according to the documentation these two strategies work differently
View count: 3