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

    eygraber

    10/14/2021, 11:41 PM
    Is the suggested way of working with
    LazyColumn/LazyRow
    to use mutable state for the items, so that updating a property of a single item doesn't cause all the visible items to recompose?
    f
    c
    +2
    • 5
    • 15
  • j

    Johnny

    10/15/2021, 9:05 AM
    Question: Is there a way to prevent recomposition for a list of
    Strings
    from
    LiveData
    ? When the items are sorted it should not cause recomposition. But seems like
    observeAsState
    forces recomposition every time. Even though I’m using
    key
    val value by viewModel.data.observeAsState()
    
    LazyColumn {
        value?.forEach {
            item(key = it) {
                Text( text = "$it!")
            }
        }
    }
    f
    d
    c
    • 4
    • 7
  • a

    axehit

    10/15/2021, 10:04 AM
    Hello guys, I have a question regarding
    DisposableEffect
    . While using this effect I observed that if I move to another activity, then the
    onDispose
    lambda in the
    DisposableEffect
    of the composable in previous activity I navigated from didn’t get called. Is this an expected behaviour? That since I didn’t use compose navigation instead activity navigation
    onDispose
    isn’t called. And on the same topic can you suggest some other alternative of disposing data when composable moves out of view in case of activity navigation, my usecase is I want to send a tracking event everytime user moves out of screen.
    a
    i
    • 3
    • 5
  • s

    Stefano Sansone

    10/15/2021, 2:12 PM
    Hello, as today is there any way to implement the long click drag reorder in the list composables ?
    f
    a
    • 3
    • 2
  • c

    Chris Fillmore

    10/15/2021, 3:22 PM
    Can anyone advise on the wisdom of using
    BasicTextField
    to simply show text, in addition to allowing it to be editable? That is, instead of doing this:
    var isEditing by remember { mutableStateOf(false) }
    var text by remember { mutableStateOf("some editable text") }
    
    if (isEditing) {
      BasicTextField(...)
    } else {
      Text(...)
    }
    You do this:
    var isEditing by remember { mutableStateOf(false) }
    var text by remember { mutableStateOf("some editable text") }
    
    BasicTextField(
      ...
      value = text,
      enabled = isEditing,
      decorationBox = { innerTextField ->
        Surface(
          ...
          // A visual cue to show that the field is being edited
          border = if (isEditing) BorderStroke(...) else null
        ) {
          innerTextField()
        }
      }
    )
    🧵 2
    c
    • 2
    • 5
  • s

    Shakil Karim

    10/15/2021, 4:41 PM
    I am using Coil for image loading but I am not sure why my Images are reloading when coming back to the previous screen.
    device-2021-10-15-205546.webm
    m
    a
    +2
    • 5
    • 15
  • a

    Alex

    10/15/2021, 6:37 PM
    Any
    SubcomposeLayout
    specialists here? Trying to get the height of an inner child, code in 🧵
    a
    • 2
    • 3
  • s

    Stylianos Gakis

    10/15/2021, 11:23 PM
    When using a normal
    RecyclerView
    that holds
    ViewHolders
    that just hold a
    ComposeView
    inside it, I am not getting the expected recomposition behaviour I am expecting. More details in thread 🧵
    c
    a
    +2
    • 5
    • 23
  • w

    Waqas Tahir

    10/16/2021, 8:02 AM
    message has been deleted
    j
    o
    • 3
    • 18
  • m

    Mohammad Sianaki

    10/16/2021, 9:32 AM
    Hi, How can I have a Circle
    Checkbox
    ? I have tried
    Modifier.clip(CircleShape)
    but it’s not working.
    c
    • 2
    • 1
  • a

    AmrJyniat

    10/16/2021, 11:23 AM
    When I try to get primaryColor from outside an annotated composable fun I get an error say "@Composable invocations can only happen from the context of a @Composable function" How to get a specific color from outside an annotated composable fun?
    k
    • 2
    • 1
  • r

    Ryan Kay

    10/16/2021, 2:42 PM
    I have a question about memory management for classes which are instantiated within compose functions. I have a KMM project, and for the desktop version, I create a few pure Kotlin classes within my top level composable. I use a remember delegate which contains a enum class denoting each screen of the application (four screens total). When I want to navigate to a new screen in the desktop version, I just switch change that remembered enum and the recomposition occurs. So the thing I'm wondering is how to make sure that the classes (basically a Presenter, ViewModel, and Container class for a given screen) are being GCed properly after recomposition occurs. It's worth noting that they are instantiated within a composable that gets recomposed. Is there a general rule about what happens to such classes? My guess is that they are held on to via the slotTable, but I don't know for sure. I asked this in the #compose-desktop channel but it was suggested to ask here.
    a
    • 2
    • 5
  • j

    Jishin Dev [JD]

    10/16/2021, 2:48 PM
    Originally shared in #multiplatform.
    Seeing this compiler
    BackendException
    on AS when building a multi module KMM project which uses Jetpack compose
    org.jetbrains.kotlin.backend.common.BackendException: Backend Internal error: Exception during IR lowering
    and this as render problems when preview tries to load in between
    java.lang.NoSuchMethodError: 'void androidx.compose.material.TextKt.Text...'
    Found a few other people who had the same issue here, on the issuetracker and even on SOF but none of the solutions that worked for them, worked for me unfortunately. More details in the 🧵 .
    m
    • 2
    • 10
  • s

    spierce7

    10/16/2021, 7:15 PM
    I have a
    Composable
    that displays an image, and when you click on it, it prints out the x and y position of the click, and the RGB color of the image. I’m noticing if the image is updated though, I end up getting RGB colors from the first image I clicked, not the latest. What is the correct way to handle this, as clearly I’m doing it wrong. Code in thread.
    s
    t
    • 3
    • 11
  • a

    Alexander Suraphel

    10/17/2021, 2:00 PM
    How do I create a state that depends on another state?
    s
    • 2
    • 2
  • y

    yschimke

    10/17/2021, 3:16 PM
    How to use image loaders with Canvas and drawImage? It seems Canvas API requires ImageBitmap instead of Painter, so the image loader APIs like coil rememberImagePainter don't work.
    a
    • 2
    • 5
  • s

    Sean Proctor

    10/17/2021, 4:00 PM
    I'm trying to implement a timer using a
    LaunchedEffect
    , but it seems that
    LaunchedEffect
    gets canceled on recompose.
    @Composable
    fun TimeDisplay(viewModel: TimeDisplayViewModel) {
      val properties: Map<String, Long> by viewModel.properties.collectAsState()
      var timeRemaining by rememeber { mutableStateOf(0) }
      
      Text(timeRemaining.toString)
      
      val timeProperty = properties["time"]
      LaunchedEffect(timeProperty) {
        val currentTime = System.currentTimeMillis()
        while (timeProperty > currentTime) {
          timeRemaining = timeProperty - currentTime
          delay(1000L)
        }
        timeRemaining = 0L
      }
    }
    The
    LaunchedEffect
    is always canceled during the delay.
    properties
    is updated with an unrelated value.
    s
    • 2
    • 5
  • c

    Chris Johnson

    10/17/2021, 9:08 PM
    Hello 👋 is there a way to detect drag events and also detect when the user lifts their finger up? I've tried
    changeToUp
    from the Pointer input scope but that doesn't seem to do what I think.. currently I use
    PointerInput
    and
    detectDragGestures
    .
    a
    • 2
    • 4
  • d

    Daniel

    10/18/2021, 7:55 AM
    Hello everyone 👋🏾. while testing out compose on our project, we realised that our ui testing framework (Appium) uses view ids to run tests on the UI. is there a way to specify ids for composables. I also read about the compose semantics tree but I'm not sure how it can help. Thanks 🙏🏾
    k
    d
    +2
    • 5
    • 5
  • j

    james

    10/18/2021, 7:56 AM
    hi all. I’m still grasping thinking in Compose, and I’m wondering if someone can guide me on the “correct” way to do this in the world of Compose. I have a parent screen which holds some master context (let’s say
    someParentId
    ), and that screen is made up of some child Composables, and those Composables each have their own ViewModels. I would like to re-initialize those child ViewModels when
    someParentId
    changes, so that they re-load their data (and in turn recompose whatever is required) if I completely blow away the child ViewModels when
    someParentId
    changes and construct new ones, the corresponding UI must be recomposed every time, right? and that would be a very inefficient way to do it? so does this mean that the correct way would be to have ParentViewModel hold a reference to ChildA ViewModel and ChildB ViewModel, and when
    someParentId
    changes I can just get my existing child ViewModel references, and tell them to fetch the relevant new data? (hastily drawn pic for reference in case the relationships were unclear)
    d
    • 2
    • 2
  • d

    Danish Ansari

    10/18/2021, 7:56 AM
    Anyone noticed that APK size has increased drastically when using compose. Starter application in XML takes
    4.2 MB
    whereas starter app in Compose is
    7.2 MB
    having 5
    .dex
    files. Why there are so many dex files in a starter app? Edit: I noticed that starter app in XML also has 3 dex files, why is this happening, does this have anything to do with recent versions of Android gradle plugin?
    a
    s
    t
    • 4
    • 8
  • j

    Jason Roberts

    10/18/2021, 11:22 AM
    Hi, how can i draw this shadow in compose? this shadow info in figma
    t
    c
    c
    • 4
    • 3
  • i

    Ink

    10/18/2021, 12:06 PM
    Divider(
        color = MaterialTheme.colors.background,
        modifier = Modifier
            .height(150.dp)
            .width(2.dp)
    )
    How Can I add rounded corners for that divider?
    a
    • 2
    • 2
  • b

    bmo

    10/18/2021, 12:08 PM
    Hi, I don't know if I did something wrong reporting the issue but I posted a bug on September 30 with a reproducible sample and it's still not even acknowledge today: https://issuetracker.google.com/issues/201556419 Should have I done something different when reporting it?
    a
    • 2
    • 2
  • a

    Arpit Shukla

    10/18/2021, 2:39 PM
    Hi guys, How can I open soft keyboard in full screen mode while in landscape orientation in Jetpack Compose while typing in a BasicTextField? This used to be the default behaviour in View world.
    z
    • 2
    • 1
  • r

    robnik

    10/18/2021, 4:15 PM
    Anyone know a simple way to preload an
    Image
    ? I'm using Accompanist's
    HorizontalPager
    . A page shows an
    Image
    from a URL. I'd like to load one page ahead so paging feels faster.
    c
    • 2
    • 1
  • а

    Александр Репин

    10/18/2021, 4:27 PM
    Hello. What is the best way to decorate each symbol in text field? Each symbol in the text field should be in own composable. It should look like first is a round square, second is a circle and so on
    d
    z
    • 3
    • 8
  • m

    mingkangpan

    10/18/2021, 4:54 PM
    Hey I have a question about compose, if I have a complex screen with many states, like • Some permissions need to be granted to show any UI • UI loading • UI error • etc What is the best practise? Like defining a master state data class (with many constructor arguments) and pass it from top to bottom, where I pass the events from bottom to top? I read that passing viewModel it self as method argument in composable is not a good practise since this would imply states within the composable method
    d
    • 2
    • 5
  • r

    robnik

    10/18/2021, 5:35 PM
    My view model has a computed property - it forwards to an underlying model that does not know about the
    MutableState
    type. Is there a way to signal Compose when this computed property has changed, without keeping a separate copy of the data in my view model as a
    MutableState
    ? (In SwiftUI I do this with
    objectWillChange.send()
    )
    d
    z
    • 3
    • 3
  • f

    Fredrik Larsen

    10/18/2021, 9:22 PM
    Hi, using Compose and Paging, is there a way to mutate the items? A normal use case is to have a list of items (paginated) where you can toggle a button on each item. E.g. follow/unfollow. In a non-compose setting I'd just update the reactive stream and react accordingly, but since Paging is wrapping the source, I'm unable to mutate. Is there another approach for this, or does the paging library simply only work with immutable data?
    c
    d
    m
    • 4
    • 6
Powered by Linen
Title
f

Fredrik Larsen

10/18/2021, 9:22 PM
Hi, using Compose and Paging, is there a way to mutate the items? A normal use case is to have a list of items (paginated) where you can toggle a button on each item. E.g. follow/unfollow. In a non-compose setting I'd just update the reactive stream and react accordingly, but since Paging is wrapping the source, I'm unable to mutate. Is there another approach for this, or does the paging library simply only work with immutable data?
c

Csaba Kozák

10/19/2021, 7:44 AM
Can you share some code? You can update the data in VM, which will emit, and it will cause a recomposition to show new data.
f

Fredrik Larsen

10/19/2021, 7:53 AM
Hi, Csaba. Thanks for helping. I somehow missed the map operator for PagingData. I’m looking into it now. I’ll see if I can make a contrived example a bit later. The problem with invalidating the whole Pager is that everything invalidates. Not just the single item.
c

Csaba Kozák

10/19/2021, 7:55 AM
Ah, yes. We had this problem with Paging in non-Compose world as well. I do not think there is another way if you want to use the Paging library.
f

Fredrik Larsen

10/19/2021, 7:56 AM
I see. If that is the case it’s pretty useless for many/most use cases. I’ll let you know if I manage to get around this.
d

dewildte

10/19/2021, 2:40 PM
Can you have your data funnel from Paging into a proxy channel that you can control?
m

maxgdn

10/25/2021, 4:02 PM
Hi all. Was there any resolution or alternatives? Facing similar difficulties.
View count: 2