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

    Tower Guidev2

    06/29/2022, 10:24 AM
    Hi i am using the compose backdrop
    BackdropScaffold
    there are a number of features i do not like and would like to customise 1). when the back layer is open the user cannot interact with the frontlayer. is there any way i can enable frontlayer interactions while the backdrop is open? 2). i would like to animate the transition between Hamburger and Cross icon, however i cannot see how to achieve this. 3). I have added my own animation for conceal/reveal of the back layer which i like however it has made the transition between the hamburger and cross icon very "sluggish" what have i done wrong?
    j
    • 2
    • 9
  • e

    Erik

    06/29/2022, 12:04 PM
    Say you have some (state) class
    Foo
    and you want to create a
    @Composable fun
    to build some UI for
    Foo
    instances. How would you name it? • `Foo`: note that this is the same name as the
    Foo
    class. This is not an error (if class and function are in different namespaces), but it could be confusing. •
    FooView
    •
    FooComposable
    Something else? Are there guidelines for composable naming?
    👀 1
    c
    f
    s
    • 4
    • 9
  • t

    the great warrior

    06/29/2022, 12:39 PM
    Hi guys I want to implement swipe to delete in lazyColumn, is there any src code for this?
    p
    • 2
    • 2
  • j

    Jessica Ernst

    06/29/2022, 1:53 PM
    Hi is there anything official Documentation about notifications in Compose or a sample App for that?
    👀 1
    c
    • 2
    • 20
  • c

    Colton Idle

    06/29/2022, 5:20 PM
    Bunch of compose updates today! 😛arty-parrot: Compose supports kotlin 1.7.0 in compiler 1.2.0 https://twitter.com/JimSproch/status/1542193552326680577 (kinda weird I think for it to be in 1.2.0? maybe just me?) Version 1.2.0-rc03 out today • Pretty minor bump Version 1.3.0-alpha01 • New
    LookaheadLayout
    that supports a lookahead pass before the actual measure/layout. • Introduced the
    UrlAnnotation
    annotation type and associated methods to support
    TalkBack
    link support in `AnnotatedString`s. • Add optional alpha parameter to Brush flavor of
    TextStyle
    and
    SpanStyle
    to modify opacity of the whole
    Text
    • Added a new API
    WindowInfo.keyboardModifiers
    to observe its state within composable functions or via snapshotFlow Version 1.0.0-alpha14 • Nothing too major. See here if curious
    🎉 22
    i
    j
    +4
    • 7
    • 17
  • l

    Landry Norris

    06/29/2022, 8:15 PM
    I’m trying to record a RoboScript for an app built with compose and I get the error
    espresso testing framework does not support compose projects
    . When I Google this error, I only find articles about how to use espresso with a compose project. To my knowledge, espresso does currently support compose. I tried this on Chipmunk and Electric Eel. Has anyone run into this issue before?
  • b

    Berkeli Alashov

    06/29/2022, 11:04 PM
    Hello. I'm trying to implement accessibility requirements for a reusable component called
    FullScreenLoading
    . Requirements include to announce loading starting and finishing via TalkBack. I have two possible implementations using
    DisposableEffect
    in loading icon's composable scope and both are not ideal. Including code in comments. Any ideas to improve option 1 (from code) or maybe I should go with option 2 in cases like this?
    • 1
    • 1
  • c

    Colton Idle

    06/30/2022, 4:50 AM
    My team and I don't always remember to size an image "correctly". With that I mean that the AsyncImage() (using Coil) doesn't have a defined size before it comes back from the network. Essentially we want to require a set size or a maxWidth with aspectRatio modifier. This helps us cut out Cumulative Layout Shift https://web.dev/cls/ (basically content shifting because an image loaded) We want to accomplist this by writing a lint rule (we're working on it) and potentially just enforcing to use OurImageComposable() that will wrap AsyncImage and itself it'll do some checks to make sure that the image bounds can actually be laid out fully without an image to come back from the network. How would you go about checking to make sure that the image has a deterministic height and width? My first attempt at this is basically removing the ability to set any modifier, and requiring that you either set a width + height with args and providing another version of the image that takes in args for fill width OR height + aspect ratio. Thoughts?
    a
    • 2
    • 10
  • y

    Young Rock

    06/30/2022, 6:55 AM
    How to handle global ui element state and behavior?
    s
    c
    • 3
    • 3
  • m

    Michał Diner

    06/30/2022, 8:06 AM
    Is there a way to add the compose plugin to a non-android module? We have issues with recompositions because of our kotlin domain module and its non-inferred stability of data classes.
    c
    • 2
    • 2
  • c

    Colton Idle

    06/30/2022, 9:09 AM
    I think this will get some hate from folks... but is it that bad to use snapshot state in an App level state holder instead of something like StateFlow? Example: Is this that bad? It's just so easy to use and I think the argument has been made before that snapshot state is a compose dependency, but it's not a compose UI dependency and so its similar to stateFlow in that respect.
    @Singleton
    class AppStateHolder() {
      var someBoolean by mutableStateOf(false)
    👀 4
    f
    s
    • 3
    • 9
  • s

    Stylianos Gakis

    06/30/2022, 9:42 AM
    Using a ComposeView
    <androidx.compose.ui.platform.ComposeView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_gravity="center_horizontal"/>
    Inside of a
    <LinearLayout>
    and I am experiencing a problem where for 1 frame the ComposeView starts aligned to the left and then it jumps to the center. Is this something someone else has experienced as well? Any thoughts on a workaround aside from finally fixing that screen to not be so archaic 😅
    ➕ 1
    • 1
    • 1
  • k

    kotlinforandroid

    06/30/2022, 11:01 AM
    Material3's newest Compose alpha includes a new List component. However, I cannot find the component in the official M3 documentation: https://developer.android.com/jetpack/androidx/releases/compose-material3#1.0.0-alpha14 https://m3.material.io/ Is it somehow possible to specify what documentation version I want to look at? The doc link https://developer.android.com/reference/kotlin/androidx/compose/material3/package-summary does not allow me to select the newest alpha version.
    c
    • 2
    • 1
  • v

    vide

    06/30/2022, 11:43 AM
    Is it better to store individual class properties as MutableState or the whole class? (Example of what I mean in 🧵)
    s
    z
    +5
    • 8
    • 17
  • o

    orangy

    06/30/2022, 3:17 PM
    I can’t find a way to constraint composable to grab all width but not more that N.dp. How do I do it?
    ✅ 1
    l
    • 2
    • 2
  • s

    spierce7

    06/30/2022, 7:59 PM
    Is there a way to recycle a compose ImageBitmap? I’m using multiplatform.
  • s

    spierce7

    06/30/2022, 8:18 PM
    Is there a way with a Compose or a native / Skia canvas to apply Skia ImageFilters?
    k
    • 2
    • 5
  • l

    Lilly

    06/30/2022, 9:37 PM
    [SOLVED]
    unselectedContentColor
    of
    Tab
    is not respected. Do I miss something or is this a bug?
    Tab(
                        selected = true,
                        text = { Text(stringResource(section.stringRes)) },
                        onClick = { selectedTabIndex = i },
                        selectedContentColor = LightGreen600,
                        unselectedContentColor = Color.Red
                    )
    s
    • 2
    • 4
  • f

    fengdai

    07/01/2022, 1:32 AM
    Which should I prefer for creating item of Paging’s LoadState?
    LazyColumn {
        ...
        if (lazyItems.loadState.append is LoadState.Loading) {
            item(contentType = Loading) {
                PagingLoadingItem()
            }
        }
        if (lazyItems.loadState.append is LoadState.Error) {
            item(contentType = Error) {
                PagingErrorItem {
                    lazyItems.retry()
                }
            }
        }
        if (lazyItems.loadState.append.endOfPaginationReached) {
            item(contentType = EndReached) {
                PagingEndItem()
            }
        }
    Or:
    LazyColumn {
        ...
        item(contentType = LoadStateIndicator) {
            if (lazyItems.loadState.append is LoadState.Loading) {
                PagingLoadingItem()
            }
            if (lazyItems.loadState.append is LoadState.Error) {
                PagingErrorItem {
                    lazyItems.retry()
                }
            }
            if (lazyItems.loadState.append.endOfPaginationReached) {
                PagingEndItem()
            }
        }
    }
    i
    • 2
    • 9
  • s

    Stefan Oltmann

    07/01/2022, 7:04 AM
    To reduce GC I want to have a static instance of
    Modifier.weight(1.0f)
    I have this extension function:
    @Composable
    fun ColumnScope.FillSpacer(): Unit = Spacer(Modifier.weight(1.0f))
    Now I try to figure out how I can define my
    val
    for that. I find it a bit tricky because of the ColumnScope.
    a
    • 2
    • 2
  • j

    Jan Skrasek

    07/01/2022, 8:18 AM
    I'm looking to for weight() + with minHeight to force the column to scroll. Here is a question with solution but I'm not much satisfied with BoxWithConstraints solution. Is there any other option?
    Column(modifier = Modifier.verticalScroll(rememberScrollState()).fillMaxSize) {
        Box(modifier = Modifier.weight(1f).sizeIn(minHeight = 160.dp))
        Box(modifier = Modifier.height(600.dp))
    }
    • 1
    • 2
  • s

    Saiedmomen

    07/01/2022, 9:04 AM
    Why is compose compiler at
    1.2.0
    while everything else is at rc03? Is it because it is a classpath dependency? https://maven.google.com/web/index.html?q=compose#androidx.compose.compiler:compiler:1.2.0
    j
    • 2
    • 2
  • n

    Nuru

    07/01/2022, 10:50 AM
    Can we scope a viewmodel to a particular composable?
    m
    c
    a
    • 4
    • 4
  • i

    Ian Warwick

    07/01/2022, 11:48 AM
    Hey all is there any way for a
    Box
    to stop constraining its children? I just want them to overflow when I
    offset(x,y)
    them or size them
    Box(Modifier.size(256.dp)) {
        Box(Modifier.border(2.dp, Color.Red).size(512.dp)) {
        }
    }
    The inner box always gets constrained to the outer box which I don’t want, but I do want all the cool things about the box such as
    Alignment
    I just don’t want it to constrain children size, any ideas? 🙂
    m
    • 2
    • 2
  • k

    kotlinforandroid

    07/01/2022, 11:56 AM
    Is there a way to leverage
    remember
    in combination with Proto DataStores? I've defined my
    DataStore
    :
    val Context.dataStore: DataStore<AppPreferences> = dataStore(serializer = ..., ...)
    However, I would like to have a way to fetch single values inside composables:
    @Composable
    fun SomeUI() {
        val context = LocalContext.current
        var userFontSize by remembe { context.dataStore.data.fontSize } // or something similar
    
        // Re-composition happens if the value changes for some reason. And it also gets stored if the var changes.
    }
    It's easy to do with a
    SharedPreferences
    -backed
    DataStore
    since I can use keys to fetch the value and set it. But I am not sure how to do it with Protobufs.
    a
    s
    • 3
    • 3
  • d

    Dean Djermanović

    07/01/2022, 12:49 PM
    What does the error
    Something went wrong while getting root views
        java.lang.IllegalArgumentException: Failed requirement.
    imply? I’m using an
    AndroidView
    composable in which I create an instance of a custom view from 3rd party library. The error happens when I quickly navigate to/from that
    AndroidView
    composable.
    a
    • 2
    • 6
  • k

    Kata

    07/01/2022, 2:20 PM
    Is there a way to write hybrid UI tests with compose? I have a flow that I would like to test and on some places compose is used and on other places I still use xmls
    s
    • 2
    • 3
  • m

    mattinger

    07/01/2022, 6:28 PM
    Anyone have any suggestiosn on how to write a good test for using AlertDialog? I’m getting this as the second root in the tree:
    Node #5 at (l=0.0, t=0.0, r=320.0, b=174.0)px
    [IsDialog]
     |-Node #6 at (l=0.0, t=0.0, r=320.0, b=174.0)px, Tag: 'alertDialog'
        |-Node #8 at (l=24.0, t=8.0, r=45.0, b=49.0)px
        | Text = '[Let's try that again]'
        | Actions = [GetTextLayoutResult]
        |-Node #9 at (l=24.0, t=44.0, r=72.0, b=85.0)px
        | Text = '[Sorry, we ran into a problem. Please try again.]'
        | Actions = [GetTextLayoutResult]
        |-Node #10 at (l=176.0, t=115.0, r=240.0, b=172.0)px
        | Role = 'Button'
        | Focused = 'false'
        | Text = '[Exit setup]'
        | Actions = [OnClick, GetTextLayoutResult]
        | MergeDescendants = 'true'
        |-Node #13 at (l=248.0, t=115.0, r=312.0, b=172.0)px
          Role = 'Button'
          Focused = 'false'
          Text = '[Try again]'
          Actions = [OnClick, GetTextLayoutResult]
          MergeDescendants = 'true'
    The problem is if i match using
    isDialog()
    , there seems to be no decent way of checking all descendants, only direct children. So i had to add a test tag to the actual alert dialog, and then i can use
    onChildren()
    to find one that has the right text. The other issue is that there’s no semantics indicating which one is the title and which one is the body. Same issue with buttons as well. I do suppose I could add test tags to each node individually in my call to AlertDialog. What are others doing here?
  • a

    Arun Joseph

    07/01/2022, 6:48 PM
    Is there any option for
    rememberAnimatedNavController
    not to remember
    navController
    across process death?
  • m

    Marcin Wisniowski

    07/01/2022, 11:44 PM
    What is the intended way to have the system navigation bar be the same color as the Material 3 navigation bar? I can set the system navigation bar color, but I don't know the Material 3 navigation bar color as it changes automatically with tonal color.
    ✅ 1
    a
    r
    • 3
    • 3
Powered by Linen
Title
m

Marcin Wisniowski

07/01/2022, 11:44 PM
What is the intended way to have the system navigation bar be the same color as the Material 3 navigation bar? I can set the system navigation bar color, but I don't know the Material 3 navigation bar color as it changes automatically with tonal color.
✅ 1
a

Adam Powell

07/02/2022, 12:10 AM
Set it to fully transparent and use insets within your content
r

RE

07/02/2022, 3:42 AM
agree with adam, this is my solution:
@Composable
fun Md3BottomNavigation(
    content: @Composable RowScope.() -> Unit
) {
    Surface(
        tonalElevation = 3.dp
    ) {
        CompositionLocalProvider(
            LocalAbsoluteTonalElevation provides LocalAbsoluteTonalElevation.current - 3.dp
        ) {
            NavigationBar(
                modifier = Modifier.navigationBarsPadding()
            ) {
                content()
            }
        }
    }
}
m

Marcin Wisniowski

07/03/2022, 4:37 PM
Thanks both, this worked nicely.
👍 1
View count: 5