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

    Colton Idle

    04/10/2022, 4:20 PM
    I don't use
    derivedStateOf
    often but does this seem like a good use case? Bonus: Why can't I use
    by
    and need to use
    =
    when using
    derivedStateOf
    ?
    class SignUpScreenViewState {
      var email by mutableStateOf("")
      var password by mutableStateOf("")
      var acceptTerms by mutableStateOf(false)
      var canMakeSignUpCall = derivedStateOf { email.isNotEmpty() && password.isNotEmpty() && acceptTerms }
    }
    d
    f
    +4
    20 replies · 7 participants
  • c

    Christoph Wiesner

    04/11/2022, 7:35 AM
    Material
    Button
    applies some inset even though
    elevation
    +
    contentPadding
    is set to zero.
    Button(
            modifier = modifier
                .size(46.dp)
                .padding(0.dp).background(Color.Green),
            elevation = ButtonDefaults.buttonElevation(
                // all zero
            ),
            shape = RoundedCornerShape(13.dp),
            contentPadding = PaddingValues(0.dp)
        ) {
            Icon(
                painter = iconPainter,
                contentDescription = contentDescription,
                modifier = Modifier.size(20.dp)
            )
        }
    gives me
    f
    4 replies · 2 participants
  • m

    Michał Diner

    04/11/2022, 8:59 AM
    Hi, we’re getting a few
    java.lang.IllegalArgumentException
    No destination with route "A" is on the NavController's back stack. The current destination is a route ="B"
    while trying to access
    public fun getBackStackEntry(route: String): NavBackStackEntry
    to scope our sharedViewModel.
    composable("A"){
     ScreenA(hiltViewModel(it)
    }
    
    composable("B){
     val parentNavBackStack = remember { navController.getBackStackEntry("A") }
     ScreenB (hiltViewModel(parentNavBackStackEntry))
    }
    It literally feels like we covered all the necessary steps and I’m totally clueless about what else I can do to fix this. Both screens are inside the same navGraph and usually work without any issues. Is this an issue with the navigation component? Crashes happen on the following devices:
    1. Huawei Mate 20 lite Android 10
    2. Realme 7 Pro Android 11
    ➕ 2
    i
    1 reply · 2 participants
  • l

    Lilly

    04/11/2022, 10:46 AM
    Is there a modifier to set a width for every child in a
    Column
    ?
    c
    c
    5 replies · 3 participants
  • z

    zalewski.se

    04/11/2022, 3:07 PM
    In
    AnimatedContent
    how can I provide
    ContentTransform
    to handle a case where I don’t want any animation?
    a
    2 replies · 2 participants
  • n

    Nikolas Alvelo

    04/11/2022, 4:14 PM
    Any thoughts on a Brush that can be used with
    drawArc
    that has different colors along the arc based on the arc’s sweep angle? We can get most of the way there with sweepGradient but ideally we wouldn't have the actual gradients and just solid color transitions between arc segments
    r
    5 replies · 2 participants
  • j

    Joseph Hawkes-Cates

    04/11/2022, 6:15 PM
    We went ahead and added the configChanges activity settings that have been suggested here previously in our app. Everything works great except I’m seeing that Images that use the painterResource() composable are not being updated when switching from light to dark mode. Has anyone else seen this?
    c
    a
    +2
    28 replies · 5 participants
  • m

    Mehdi Haghgoo

    04/11/2022, 6:40 PM
    Does adding androidx.compose.material3:material3:version remove the need for androidx.compose.material* and com.google.android.material* artifacts?
    f
    c
    +1
    3 replies · 4 participants
  • c

    Colton Idle

    04/11/2022, 9:40 PM
    When creating forms I find myself doing this a lot
    MyTextField(
        text = vm.state.email,
        onTextChange = vm::emailChange,
    ...
    }
    but then
    emailChange(text: String)
    basically does nothing except for setting the value. Better off just doing
    MyTextField(
        text = vm.state.email,
        onTextChange = {vm.state.email = it},
    I've always "thought" that all logic that can be moved up to a VM should be moved out of the UI layer, but after reading the arch docs im kinda convinced that whether or not i put stuff in a composable or a VM that's both the UI layer, and it basically "doesn't matter" where I put this stuff. Anyway. Thoughts?
    l
    f
    +1
    10 replies · 4 participants
  • r

    Ryan Simon

    04/12/2022, 3:40 AM
    What's the community's take on stateful Composables like a favorite button? It seems logical that we want to show the user the filled state of Favoriting something right away, and then update our internal ViewModel state once our network request goes through. Thoughts on this? Seems to make sense to me. Code sample and screenshot in the thread
    n
    p
    +1
    10 replies · 4 participants
  • a

    Anastasia Rozovskaya

    04/12/2022, 8:55 AM
    Hi! In a thread below there is a peculiar behaviour of
    ExpandedDropdownMenuDefaults.TrailingIcon
    . Feel free to share your thoughts.
    l
    6 replies · 2 participants
  • c

    Christoph Wiesner

    04/12/2022, 9:46 AM
    I have an
    OutlinedTextField
    where i want to display a different border modifier when it’s focused. when chaining modifiers I get
    IllegalStateException: Compose Runtime internal error. Unexpected or incorrect use of the Compose internal runtime API (Use active SlotWriter to determine anchor location instead)
    (code in comment)
    a
    6 replies · 2 participants
  • d

    dbaelz

    04/12/2022, 10:18 AM
    I've tried to build an EPG as a Grid and struggle to get a working, lazy-loading solution. My use case: • The EPG consists of 120+ rows (tv stations) and every row consist of 200+ row items (tv programs of the different broadcast times). • Every item in the row has a different width based on its broadcasting time. On the x-axis only a specific timespan is displayed and the user can scroll throw them horizontal. Because the x-axis represents the time, a horizontal scroll should change all items in all rows. • It should be possible to scroll throw both horizontal (tv programs based on time) and vertical (different tv stations) on the same time. With non-lazy Composable it works, but with the mentioned amount of items the performance is really bad. Obviously, it should be done lazy. Unfortunately, I didn't find a solution that worked for me. Especially syncing the scroll state of the different rows was a problem. I looked into different approaches to do it with LazyList Composables or Lazy Grid (e.g. syncing the scroll with NestedScrollConnection and shared state). See some examples in the thread. Afaik there isn't a Composable that supports horizontal and vertical lazy loading for such a use case out of the box. Has someone has an idea how to tackle that it without writing all of it by myself or an easy way to do it with a Custom Layout?
    n
    3 replies · 2 participants
  • j

    julioromano

    04/12/2022, 12:53 PM
    I’ve tried compose 1.1.1 with
    compose-compiler:1.2.0-dev-k1.6.20-61e81dadb1c
    from https://androidx.dev/storage/compose-compiler/repository It seems to work, does anyone know if there can be any specific issues using such kinds of combos (i.e. compiler 1.2.x + rest of compose 1.1.x )? Besides being unsupported of course 🙂
    a
    2 replies · 2 participants
  • f

    Filip Wiesner

    04/12/2022, 2:33 PM
    Hello, I've been struggling with accompanist
    AnimatedNavHost
    a lot lately. I've even filed a bug three weeks ago with no response. Does anyone have a workaround for this issue? It seems to me like a huge issue and I didn't see anyone talking about it which seems like it might be only on my end. Also, is the "official" support for navigation transitions coming anytime soon? The mandatory fade transitions were introduced back in January.
    i
    7 replies · 2 participants
  • o

    Orhan Tozan

    04/12/2022, 3:12 PM
    Is there an example of how to write custom hooks in Compose? In React, you can extract logic into a hook. No UI, just pure logic. Curious how people would do this in Compose
    n
    a
    +2
    6 replies · 5 participants
  • v

    Venthorus

    04/12/2022, 6:05 PM
    I have a problem with content size changes in a ModalBottomSheetLayout. If it is in expanded state (without filling the whole screen) and I add content to the sheet content, it seems to animate without me having animateContentSize() or AnimatedContent() anywhere. That's fine I guess, however the anchor of the animation isn't at the bottom. When adding the content, it pushes everything below it down instantly and then "fixes" it by animating everything up. When removing the content, it pushes everything below it up instantly and then animates down everything. It looks especially bad when removing content because you can briefly see an area without the sheet background below the sheet content. I also cannot seem to get around it by adding slideInVertically and slideOutVertically animations to the content that changes. Am I missing something or is it an issue with ModalBottomSheetLayout?
    m
    d
    3 replies · 3 participants
  • r

    ritesh

    04/12/2022, 6:49 PM
    👋 I came across this article recently, the part
    Safe Flow collection in Jetpack Compose
    @Composable
    fun LocationScreen(locationFlow: Flow<Flow>) {
    
        val lifecycleOwner = LocalLifecycleOwner.current
        val locationFlowLifecycleAware = remember(locationFlow, lifecycleOwner) {
            locationFlow.flowWithLifecycle(lifecycleOwner.lifecycle, Lifecycle.State.STARTED)
        }
    
        val location by locationFlowLifecycleAware.collectAsState()
    
        // Current location, do something with it
    }
    Do we need it, while collecting states? Isn't
    Composables
    have their own life-cycle? and we need not to worry about how the lifecycle of host it's contained in, while collecting flows?
    a
    18 replies · 2 participants
  • d

    Dan Yang

    04/12/2022, 7:32 PM
    Do I need to do anything special to make sure compose's baseline profiles are bundled with my APK? This article https://android-developers.googleblog.com/2022/01/improving-app-performance-with-baseline.html says I just have to build with AGP 7.1+ and baseline profiles will be included in my apk under
    assets/dexopt/baseline.prof
    However, I've done both of those and can't find
    assets/dexopt/baseline.prof
    when I profile/debug the apk in android studio.
    a
    t
    5 replies · 3 participants
  • y

    Yacov Rosenberg

    04/12/2022, 7:40 PM
    Hey Guys. I'm having a crash when trying to inflate a custom view with AbstractComposeView. My crash is java.lang.IllegalStateException: ViewTreeLifecycleOwner not found from com.hiatus.android.ui.toast.ToastCustomView{4836644 V.E...... ......I. 0,0-0,0} What I'm trying to do is to inflate this custom view in a toast this way.
    fun create (lifecycleOwner: LifecycleOwner, view: View) {
    
        val toast = Toast(context)
    
        val toastCustomView = ToastCustomView(
            context
        )
    
        toast.view = toastCustomView
        toast.show()
    }
    
    Any help?
    a
    5 replies · 2 participants
  • z

    zalewski.se

    04/12/2022, 8:13 PM
    Is it just me or the way panning + zooming is being handled in this example from the official docs, works quite weird together? If you pinch the object and (keep touching the screen) you start moving it around (do few circles on your screen with it) it will quickly go out of the bounds of your screen. Shouldn’t the offsetChange be impacted by the scale there? 🤔
    1 reply · 1 participant
  • m

    martmists

    04/12/2022, 9:50 PM
    Does anyone have an example for how to use the navigation tutorial? I can find the decompose library but for some reason gradle doesn't seem to like it, and if a working example exists I'd prefer to work from there
    l
    a
    31 replies · 3 participants
  • j

    james

    04/12/2022, 11:24 PM
    Hi all, has anyone else figured out how to workaround this bug with ModalBottomSheetLayout? Seems to exist in all versions of Compose, right up to the current 1.2.0-alpha07 release. It works as expected until I enable adjustResize on the containing activity with
    windowSoftInputMode="adjustResize"
    Once
    adjustResize
    is enabled, the ModalBottomSheet re-animates into the screen from the bottom during the keyboard close process, despite the fact the modal was already on screen in the Expanded state. Further, while creating a video to show this bug I discovered that the layout does not obey the Animation Scale from Developer Settings (which was introduced in 1.2.0-alpha05), whereas other Compose components do in fact obey those settings. Wanted to check if anyone else knows about this or if it has already been filed on the issue tracker, before I file an issue myself.
    Kapture 2022-04-13 at 09.13.06.mp4
    j
    3 replies · 2 participants
  • s

    Saurabh Khare

    04/13/2022, 1:09 AM
    Can we include “FragmentContainerView” in compose view
    i
    1 reply · 2 participants
  • j

    James Black

    04/13/2022, 2:47 AM
    I have an array of 18 elements that I create a dropdown menu with, so I have an array of states so when I move one over I expect it to stay moved. The problem is that it isn't. The array of remembered states has the correct values, which is what confuses me. This is my source:
    enum class ClothingTypes(val clothingLabel:String) {
        BLAZER("blazer"),
        BLOUSE("blouse"),
        BODY("body");
    
        companion object {
            fun getNumberOfItems() = values().size
        }
    }
    And this is my code, but I am not certain why it doesn't remember the state for each one. You can see the code under androidApp in https://github.com/jblack975/MyOutfitPicker/tree/initial_ui
    var selectedIndex by remember { mutableStateOf(MutableList(ClothingTypes.getNumberOfItems()) { 0 }) }
    val checkedState = remember { mutableStateOf(MutableList(ClothingTypes.getNumberOfItems()) { false }) }
    Column {
        DropdownMenu(
            expanded = expanded,
            onDismissRequest = { expanded = false },
            modifier = Modifier.background(Color.LightGray)
        ) {
            ClothingTypes.values().forEachIndexed { index, s ->
                DropdownMenuItem(onClick = {
                    selectedIndex[index] = index
                    expanded = true
                }) {
                    Switch(
                        checked = checkedState.value[index],
                        onCheckedChange = { checkedState.value[index] = it }
                    )
                    Text(text = s.clothingLabel)
                }
            }
        }
        Text(text = "outfit view", style = MaterialTheme.typography.h6)
    }
    a
    2 replies · 2 participants
  • r

    ritesh

    04/13/2022, 3:21 AM
    FocusManager.moveFocus(FocusDirection.Down)
    doesn't scroll to the nearest focusable descendent, if i am calling it from the last visible node on the screen and next focusable node is out of the screen. Is this an expected behavior and needs some extra handling or it's a known bug? Here, my all focusable nodes are text-fields.
    c
    z
    7 replies · 3 participants
  • a

    Android75

    04/13/2022, 6:11 AM
    I’ d like load drawable shape and have same error.
    java.lang.IllegalArgumentException: Only VectorDrawables and rasterized asset types are supported ex. PNG, JPG
    this is shape.
    <?xml version="1.0" encoding="utf-8"?>
    <shape xmlns:android="<http://schemas.android.com/apk/res/android>" android:shape="oval">
        <solid android:color="#F44336"/>
    
    </shape>
    and code.
    Image(
        imageVector =   ImageVector.vectorResource(
            id = R.drawable.ball
        ),
        contentDescription = null
    )
    a
    c
    7 replies · 3 participants
  • j

    jasu

    04/13/2022, 7:27 AM
    Is it possible to have two compose navigation destination at a time, like shown in below ss. There's a note list and selected note details in one screen?
    i
    3 replies · 2 participants
  • r

    ritesh

    04/13/2022, 8:27 AM
    Is there a better way of doing this 👇
    val lits1 = listOf(1, 2, 3, 4, 5, 6, 7, 8, 9, 10)
    val list2 = listOf("one", "two", "three", "four", "five")
    LazyRow {
        // first
        itemsIndexed(items = lits1) { _, item ->
            Text(text = "$item")
        }
    
        // second
        itemsIndexed(items = list2) { _, item ->
            Text(text = item, modifier = Modifier.background(Green))
        }
    }
    Instead of giving background to each items in
    list2
    , is it possible to give the whole list items as a background in
    second
    itemsIndexed
    . I couldn't think of any other solution than this.
    f
    t
    +1
    15 replies · 4 participants
  • n

    nuhkoca

    04/13/2022, 10:04 AM
    Hello, is there a better way to center align this icon button to the text rather than using offset? It a little bit looks off to me.
    ✅ 1
    c
    c
    5 replies · 3 participants
Powered by Linen
Title
n

nuhkoca

04/13/2022, 10:04 AM
Hello, is there a better way to center align this icon button to the text rather than using offset? It a little bit looks off to me.
✅ 1
c

Csaba Szugyiczki

04/13/2022, 10:28 AM
I guess you already put them in a
Row
If yes, the Row has a
verticalAlignment
parameter to which you can pass
Alignment.CenterVertically
➕ 1
👍 1
c

Chris Sinco [G]

04/13/2022, 10:36 AM
Depending what version of Compose you are using, includeFontPadding may still be on, which has led to less than pixel perfect vertical alignment with Text in the past, which in that case requires tiny nudges with offset 😔
✔️ 2
n

nuhkoca

04/13/2022, 11:27 AM
Thank you guys for a quick turnaround, I think I fixed it using custom layout but there is another problem 😞 Even though I wrap both
title
and
description
inside a
Column
, the
description
doesn’t respect to the `title'`s space and overlaps it. Do you know why?
My layout
Layout(
    modifier = Modifier
        .padding(horizontal = TRTheme.spacing.default)
        .padding(top = TRTheme.spacing.default, bottom = TRTheme.spacing.single),
    content = {
        ...
    }) { measurables, constraints ->
    ...
ok, instead of
maxHeight
, used placeables’ height and it is fixed 🙂
👍 1
View count: 8