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

    Akram Bensalem

    07/02/2022, 9:37 AM
    The application slows down greatly when using LazyVerticalGrid !!! I replace the LazyVerticalGrid with LazyColumn and It works smoothly as it suppose to be. I use :
    androidx.compose.ui:ui:1.3.0-alpha01
    even with version 1.2.0-rc03 I face same problem
    ScreenVideo_202272_103418.mp4
    p
    • 2
    • 4
  • k

    kotlinforandroid

    07/02/2022, 1:28 PM
    Is there a way to get the color resulting from a source color and a given elevation level in material3 (compose)?
  • n

    nlindberg

    07/02/2022, 1:35 PM
    Is there a way to style separate parts of the text in a TextField? If I try to do a visual transformation and create a new annotated string with separate color of different parts of the string it doesn’t do anything 🤔 ?
    :nice: 1
    👀 2
    d
    • 2
    • 8
  • o

    oday

    07/02/2022, 6:25 PM
    so i have a pretty basic misunderstanding towards how state is used inside of an Activity, I have the following:
    class MainActivity @Inject constructor() : ComponentActivity() {
    
        private val viewModel: MainViewModel by viewModels()
    
        override fun onCreate(savedInstanceState: Bundle?) {
            super.onCreate(savedInstanceState)
    
            setContent {
                if (viewModel.uiState.collectAsState().value.authenticated) {
                    Home()
                } else {
                    Authentication()
                }
            }
        }
    }
    this
    authenticated
    field is going to change to
    true
    or
    false
    inside the viewModel depending if the user is authenticated or not the above code will first come up with false for that field, showing the Authentication composable and then the change will happen triggering the recomposition and then it will come up with true and show the Home composable how do I
    listen
    to changes for that field, is the above even correct or how things should be done?
    z
    • 2
    • 1
  • k

    kotlinforandroid

    07/02/2022, 6:33 PM
    My App looks like this:
    Theme -> ModalBottomSheetLayout -> Scaffold(bottomBar, topBar) -> NavHost
    . I use the same
    TopBar
    to prevent flickering. I was now wondering how I can propagate click events down to the correct screen that is currently displayed with
    NavHost
    . To use the good old todo example: When the user clicks a note they enter the
    EditNoteScreen
    . The
    SmallAppTopBar
    checks if the current route is
    edit-note
    and if so, adds an action to delete the note. However, the press happens on the TopBar level which is "more upwards" then the
    EditNoteScreen
    . And only the ViewModel of that screen knows the current note that gets edited. The toplevel that contains the
    Theme -> ... -> Scaffold
    does not even have a ViewModel. Until now it has been completely dump.
    s
    • 2
    • 1
  • j

    Jitendra

    07/03/2022, 10:02 AM
    I want to use debounce here , to just put few time delay, what is the best way for this,
    c
    f
    a
    • 4
    • 4
  • o

    oday

    07/03/2022, 1:07 PM
    how do I listen to a mutableStateFlow object from an Activity? I only want the activity to act on it if it has changed into something other than the default value
    a
    o
    • 3
    • 20
  • d

    Daniel Okanin

    07/03/2022, 4:23 PM
    Hi everyone ! Im using the compose metrics and I get the following declare class: What is mean my class is stable but includes unstable fields? How is it effect? Is it effect if the function that uses this class be considers as skippable or not only? Is it ok to put “stable” annotation on class that includes unstable fields?
    stable class ProViewModelItem {
      unstable val profileImage: ImageDescriptor?
      unstable val coverImage: ImageDescriptor?
      stable val numReviews: Int
      stable val reviewRating: Float
    } 
    
    This is how I declare this class:
    @Stable
    class ProViewModelItem(
        id: String?, title: String?,
        val profileImage: ImageDescriptor? = null,
        val coverImage: ImageDescriptor? = null,
        val numReviews: Int = 0,
        val reviewRating: Float = 0f,
    ) : HomeFeedViewModelItem(id, title)
    f
    s
    • 3
    • 16
  • b

    Berkeli Alashov

    07/04/2022, 1:15 AM
    Can this kind of interface marked as @Immutable?
    interface ColorSpec {
        @Composable
        operator fun invoke(): Color
    
        companion object {
            fun fromColor(lightVariant: Color, darkVariant: Color): ColorSpec = object : ColorSpec {
                @Composable
                override fun invoke(): Color = if (Theme.isDarkTheme) darkVariant else lightVariant
            }
        }
    }
    i
    a
    • 3
    • 13
  • f

    Frank van der Laan

    07/04/2022, 10:20 AM
    With Navigation Compose. When I select a tab, and follow the documentation, I do this:
    popUpTo(navController.graph.findStartDestination().id) {
        saveState = true
    }
    as a result, my tab's ViewModels is not cleared when switching tabs. That's good. But let's say the user now logs out and I want to clear this ViewModel after all. How do I do so? Popping all screens from the backstack will clear all their ViewModels, but this screen is not in the backstack anymore.
    i
    • 2
    • 5
  • a

    Alex

    07/04/2022, 11:42 AM
    Will there be any updates to the Jetpack Compose Roadmap? Last Updated: February 9, 2022
    ➕ 4
    z
    j
    • 3
    • 2
  • j

    Jonas Frid

    07/04/2022, 12:41 PM
    Any tips on how to force the BottomSheetModal to expand to full and disable half expand?
    c
    a
    • 3
    • 4
  • s

    ste

    07/04/2022, 3:04 PM
    I'm trying to figure out how to use
    VelocityTracker::calculateVelocity
    to determine whether complete the swipe at the end of a drag gesture or not. I just don't understand why it returns velocities with opposite signs upon very similar drag gestures...
  • v

    Vaios Tsitsonis

    07/04/2022, 3:58 PM
    Out of curiosity, is
    testTag
    used only for testing? Is it included in production code or is it somehow removed?
  • l

    Lilly

    07/04/2022, 5:07 PM
    Can this simple nested
    Row
    composable be done better? I'm also asking because I coudn't access the nested weight and had to use
    fillMaxWidth(fraction = 0.Xf)
    instead. Without the nested Row, I'm not able to fix the position of the second
    Spacer
    at ~0.7f. The second Spacer should look like it is horizontally aligned to
    Start
    . Screenshot -> in Thread.
    loader.kt
    • 1
    • 1
  • c

    Colton Idle

    07/05/2022, 12:03 AM
    I'm using the code from this video to load some info about items when they're shown on the screen. When I do this I get a warning from the IDE. Ideas on the correct way to do this?
    s
    b
    +2
    • 5
    • 50
  • t

    Titouan

    07/05/2022, 7:49 AM
    Hi everyone, I have a Column that has several views in it, and one LazyColumn with a fixed size. Sometimes the scroll has a strange behavior, it jumps to the top or the bottom of the parent Column. Does anyone knows if there is a way to solve this issue?
  • m

    Mjahangiry75

    07/05/2022, 8:22 AM
    In my
    Composable
    , I have a
    NumberPicker
    (traditional
    View
    ) If I want to make `NumberPicker`'s font the same as `Compose`'s, how can I do that?
  • k

    kotlinforandroid

    07/05/2022, 11:42 AM
    Is there anything special about
    Scaffold
    ? I always compared it to
    AppBarLayout
    but it seems that it is OK to nest
    Scaffolds
    . Even Now In Android does it. https://github.com/android/nowinandroid. It
    Scaffold
    just a special kind of
    Column
    following some Material design parameters?
    ✅ 1
    s
    • 2
    • 3
  • r

    Rihards

    07/05/2022, 11:45 AM
    Hi! Is there any way to get Compose previews with Compose Ui version 1.2.0-rc03? I have tried to update all compose libraries by checking advices in stackoverflow and this channel, but nothing really helped. Only turning back to stable 1.1.1 version seemed as an option so far, but can’t use that because of methods that are being used in higher versions.😑
    ✅ 1
    k
    f
    • 3
    • 7
  • s

    ste

    07/05/2022, 3:21 PM
    How can I disable
    HorizontalPager
    scroll (via
    userScrollEnabled
    ) when the user started a
    LazyColumn
    scroll (and vice versa)? Do I need to write a complex
    NestedScrollConnection
    ?
    untitled.webm
    c
    • 2
    • 11
  • v

    vgonda

    07/05/2022, 3:48 PM
    So, it is a feature or a bug that in
    ComposeTest
    the lifecycle aware composer is replaced with one controlled by the test? As far as I can tell, this makes it such that things aren't disposed when they would be outside a test environment, and it's causing us memory leaks in the test. More details in the thread.
    z
    p
    • 3
    • 12
  • m

    Matti MK

    07/05/2022, 6:17 PM
    Is it possible to pass an argument when navigating to a separate NavGraph route? I’d ideally like to have something as follows:
    navigation(
            route = "routeToNavigateTo",
            startDestination = "startDestination/{argument}"
        ) {
            composable(route = "startDestination/{argument}" ... ) { ... }
        }
    i
    l
    • 3
    • 5
  • v

    Vaios Tsitsonis

    07/05/2022, 10:24 PM
    Hello! Is there a way to press the back button while running a test?
    • 1
    • 1
  • d

    darkmoon_uk

    07/06/2022, 1:45 AM
    This Katalog library looks nice for building Compose Component catalog preview Apps; but it doesn't support Multiplatform - is anyone aware of a similar project that does?
    b
    z
    +2
    • 5
    • 8
  • a

    Ahmed Shehata

    07/06/2022, 1:20 PM
    Hi everyone, I have a notification list like this All I need is: When user clicks any item that has a blue dot , it should be hidden without making any refresh call to my API again. I use compose and paging3 compose so I need to update a single object in the paging source easily.
    c
    m
    • 3
    • 3
  • g

    galex

    07/06/2022, 2:02 PM
    How can I align a
    Text
    to the start of the
    Text
    as label in a
    TextField
    ?
    @Composable
    fun SomeTextField(
        label: String,
    ) {
    
        TextField(
            label = {
                Text( // text label here
                    text = label
                )
            }
        )
    
        Text("Here is an error text") // align this to start where the text label starts
    }
    🤔
    l
    c
    c
    • 4
    • 6
  • z

    Zoltan Demant

    07/06/2022, 3:50 PM
    Did the scrolling of LazyColumn get weird with compose
    1.3.0-alpha01
    ? It looks to me like the Android 12 overscroll effect is active in all directions rather than just vertically?
    k
    • 2
    • 2
  • a

    Akram Bensalem

    07/06/2022, 4:43 PM
    Is there any trick or way to use nested navigation with some sharable UI content ? Fir example in my case I want all the :
    policyGraph()
    contactUsGraph()
    aboutUsGraph()
    conditionOfUseGraph()
    share the same "Custom Parent Layout" but the other graphs do not share that layout ?
    i
    d
    l
    • 4
    • 5
  • m

    mcpiroman

    07/06/2022, 5:53 PM
    I'm occasionally pulling and building master branch of compose/runtime module. I'm using CfD. I'd like to report that with this commit my app insanely slowed down, and, as I benchmarked, ~90% of all the cpu time is spend on this single new line. When zoomed in, in the flame graph it looks so:
    👀 3
    z
    s
    n
    • 4
    • 11
Powered by Linen
Title
m

mcpiroman

07/06/2022, 5:53 PM
I'm occasionally pulling and building master branch of compose/runtime module. I'm using CfD. I'd like to report that with this commit my app insanely slowed down, and, as I benchmarked, ~90% of all the cpu time is spend on this single new line. When zoomed in, in the flame graph it looks so:
👀 3
z

Zach Klippenstein (he/him) [MOD]

07/06/2022, 6:02 PM
@shikasd
m

mcpiroman

07/06/2022, 6:26 PM
Btw, even besides
derivedStates.removeScope(value)
, there are still some performance issues with `recordReadOf`: •
identityHashCode
, used in `IdentityScopeMap`seems to be surprisingly expensive (at least on my Eclipse Adoptium 18.0.1). I've read that JDK lazely initializes it and then has to decode it from the object header, but still. Or it is just due to the binary search in
IdentityScopeMap.find
. • There are a cupule of iterations over non-linked hash sets. That shouldn't matter that much tho, unless the set ever shrinks? • When called from
DerivedSnapshotState.getValue()
, the non-trivial `getCurrentValue()`function is called twice.
s

shikasd

07/06/2022, 7:19 PM
Interesting, I always assumed that identityHashCode will take almost constant time, I believe that's why we use it Maybe there's a better strategy for CfD there
Unfortunately, we kinda need to call
removeScope
to make sure we don't leak derived state for now Maybe it is worth investing into a better strategy for handling it Overall, Compose heavily relies on identity hashcode, assuming it is calculated in a constant time, so it taking long to calculate will slow down everything quite severely
One of the things that might help is to check if your JVM supports
-XX:hashCode
Maybe tweaking that will result in somehow better performance :)
m

mcpiroman

07/06/2022, 7:53 PM
For now I have removed usage of derivedStateOf and my app is like 10x faster.
s

shikasd

07/06/2022, 7:56 PM
Btw, would you be able to share your perf trace (through perfetto or any other exportable format)? Could be interesting to look into those at some point
m

mcpiroman

07/06/2022, 8:06 PM
I think it'd be easier if I make some example app. Because basically all I do is I build a tree view and the derivedState in question like this:
class TreeNode {
   val parent: TreeNode
   var isExpanded by mutableStateOf(true)
   val isVisible by derivedStateOf { parent.isExpanded && parent.isVisible && !isFilteredOutBySearch() }
}
s

shikasd

07/06/2022, 8:11 PM
Interesting, I am wondering if nested derived states are also part of the problem here If you could create an example app and file a bug, that would be great :)
n

Norbi

07/07/2022, 8:21 AM
I have never looked into how identity hash code is generated but it seems that it should not be used in performance critical code because its implementation may depend on Java version, host platform, or even configuration by
-XXhashCode
. E.g. https://shipilev.net/jvm/anatomy-quarks/26-identity-hash-code/
s

shikasd

07/07/2022, 11:31 AM
Although it is true for desktop, Compose is designed with Android in mind, where the implementation is fixed Platform specific actuals can provide identityHashCode implementation that doesn't use system values though, but not sure if it is going to be reasonable Similarly, Compose avoids ThreadLocals/WeakReferences because of performance concerns on Android, although they might work just fine on Desktop systems I still wonder if we ever hit the same penalty on Android as well, that's why the sample would be great Cross platform is complicated 😅
👍🏻 1
View count: 13