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

    Carl Benson

    01/17/2022, 1:53 PM
    anyone else seeing this kinds of problems when editing a composable with preview also it takes 60+ seconds to even see a change (even with super simple composables)
    👍 5
    👍🏼 1
    👍🏽 1
    s
    a
    t
    • 4
    • 4
  • m

    Margarita Volodina

    01/17/2022, 3:22 PM
    Hello everyone! Recently I’ve encountered a problem with kotlin inline functions using compose. Sample code:
    // there is any nullable computed condition possible
    val test: Boolean? = null
    test?.let {
        println("succeed")
    } ?: run {
        println("error")
    }
    test?.let {
        Greeting("Android")
    } ?: run {
        Greeting("ios")
    }
    For kotlinVersion=1.5.31, composeVersion=1.0.5 works as expected (
    println("error")
    ,
    Greeting("ios")
    are called). For kotlinVersion=1.6.0 (and higher), composeVersion=1.1.0-rc01 composable function after
    ?:
    is never called, even though
    println("error")
    is called. This behaviour could be easily reproduced for a new project from Android Studio wizard with default compose activity template. Does anyone have the same problem? Any ideas how to fix this for newer kotlin versions without rewriting code for using if-statements?
    a
    • 2
    • 2
  • b

    Brian G

    01/17/2022, 5:26 PM
    Is there anyway to render a composable at a lower resolution than the screen? For making pixelated UI. E.g. render it at 360x640 and upscale it (no anti-aliasing) to the screen's native 720x1280 I've tried using Modifier.scale(2f), but I still get native-pixel-sized rendering artifacts.
    a
    a
    • 3
    • 13
  • h

    Hardeep Singh

    01/17/2022, 5:28 PM
    What can I do to prevent WebView from reloading on screen rotation?
    a
    • 2
    • 4
  • l

    Libor Bicanovsky

    01/17/2022, 5:59 PM
    Is it possible to use material3 and material2 together? We have a large project written with material2 components and want to migrate some components to use material3 (such as the collapsing toolbar)
    ➕ 1
    :yes: 2
    c
    • 2
    • 1
  • a

    Anthony

    01/17/2022, 6:00 PM
    Hello, in the simple row example shown below, when the current timestamp changes value, all the text shifts to the side depending on the current timestamp length. Is there a way to prevent this and just have the artist text be uninfluenced by a change in the current timestamp size?
    Row(horizontalArrangement = Arrangement.SpaceBetween, modifier = Modifier.fillMaxWidth()) {
        Text(currentTimeStamp ?: "--")
        Text(artist ?: "")
        Text(endTimeStamp ?: "--")
    }
    l
    • 2
    • 1
  • b

    brabo-hi

    01/17/2022, 9:15 PM
    Hi all, when using navigation in compose what is the difference and best practice when passing data as argument, between
    navController.currentBackStackEntry?.savedStateHandle?.set("person", person)
    and
    navController.currentBackStackEntry?.arguments?.putParcelable("person", person)
    i
    c
    +2
    • 5
    • 24
  • b

    brabo-hi

    01/17/2022, 10:51 PM
    @Ian Lake what is the difference between these two approaches
    data class Person(val name: String)
    class PersonViewModel: ViewModel() {
        private val _itemsFlow: MutableStateFlow<List<Person>> = MutableStateFlow(emptyList())
        val itemsFlow: StateFlow<List<Person>> = _itemsFlow
    
        private val _itemsState: MutableState<List<Person>> = mutableStateOf(emptyList())
        val itemsState: State<List<Person>> = _itemsState
    }
    
    @Composable
    fun PersonScreen(viewmodel: PersonViewModel = viewModel()) {
        val itemsFromState: List<Person> by viewmodel.itemsState
        val itemsFromFlow: List<Person> by viewmodel.itemsFlow.collectAsState()
    }
    they are all returning
    List<Person>
    and recomposed whenever data changes
    ✅ 1
    i
    x
    c
    • 4
    • 6
  • a

    Afzal Najam

    01/17/2022, 11:38 PM
    I have an app that’s using SQLCipher + Room and I want to ask the user for the password again when they return after leaving the app so I close the database. When they leave the single Activity app, in
    onStop
    , I close the database. When they return, I use the Navigation component to direct them to the Password Screen. The screen with the list of data uses a
    ViewModel
    that exposes Flow from a Room DAO. The problem I’m having is that observing this from my
    ItemList
    Composable apparently leaks the DAO (and hence the Database instance) when the user leaves, and when the user unlocks the app again, the
    ItemList
    is still collection this Flow, which makes the app crash. Using
    asLiveData
    on the
    Flow
    fixes the issue. Am I doing something wrong by observing the Room
    Flow
    from a
    Composable
    like this or is this some weird bug?
    h
    • 2
    • 5
  • f

    Feri Nagy

    01/18/2022, 8:30 AM
    Is there a way to convert compose
    Painter
    to a
    Drawable
    ? I know that for the other way there is
    painterResource()
    and
    rememberDrawablePainter()
    in Accompanist, but I have not found anything about the inverse way.
    a
    a
    +2
    • 5
    • 9
  • a

    Ali Albaali

    01/18/2022, 9:05 AM
    Should Scaffold be used in every screen (ProfileScreen, HomeScreen, ...) or should it only be used once at the top level with some logic to fit with each screen?
    f
    c
    c
    • 4
    • 3
  • r

    Rak

    01/18/2022, 11:45 AM
    Hi, I want to introduce compose slowly into my app. Its a single activity, multiple fragment app. How best to do this for the next screen i want to develop?
    c
    • 2
    • 1
  • c

    Colton Idle

    01/18/2022, 12:17 PM
    I'm probably missing something basic here. I'm going to blame it on sleep. But this defintiely used to work, but now the IDE is complaining "Parameters must have type annotation"
    class LoginUiState(
        var screenTitle by mutableStateOf("")
    )
    t
    • 2
    • 1
  • m

    mikehearn

    01/18/2022, 12:18 PM
    That never worked - are you mixing up
    (params)
    with
    { ... properties ... }
    c
    • 2
    • 1
  • o

    Orhan Tozan

    01/18/2022, 12:30 PM
    Are there plans for Compose to support Android 12 scroll effects out of the box, just like it is on Android view system?
    c
    j
    • 3
    • 5
  • s

    Slackbot

    01/18/2022, 3:42 PM
    This message was deleted.
    :thread-please: 1
    c
    • 2
    • 2
  • j

    Joseph Hawkes-Cates

    01/18/2022, 6:57 PM
    Is there a good way to hide or prevent the selection dropper icon from displaying in a TextField? More details in thread.
    ➕ 3
    a
    s
    t
    • 4
    • 16
  • m

    myanmarking

    01/18/2022, 7:59 PM
    since coroutine scope is used in almost all screens, and to avoid passing it around. does it make sense to provide it via compositionLocal in the theme ?
    c
    a
    • 3
    • 10
  • l

    Lachlan McKee

    01/18/2022, 11:36 PM
    Hi all, I am hoping to advocate for allowing deep links as start destinations within compose navigation. I saw this thread that discussed this a several months ago, but it doesn't seem to have reached the outcome I expected. I've raised a ticket to introduce this behaviour (https://issuetracker.google.com/issues/214733434), but it was marked as a duplicate of an issue with a similar explanation. I don't suppose anyone else would be interested in discussing this?
    s
    i
    a
    • 4
    • 37
  • s

    Simon Stahl

    01/19/2022, 1:16 AM
    Hi. What could be the root cause of
    IllegalStateException: LayoutNode should be attached to an owner
    (see comments for more info)
    i
    a
    • 3
    • 8
  • c

    clark

    01/19/2022, 1:24 AM
    Hi there, I'm trying to use 
    accompanist-insets
     to adjust my view size according to the height of the keyboard but when the insets finish animating, they reset to 0. Anyone seen this behavior? Any ideas on how I could fix it? I added a green box that displays the value of 
    LocalWindowInsets.current.ime.bottom
     to show it is going back to 0 at the end of each animation.
    ➕ 1
    🙏 1
    b
    z
    c
    • 4
    • 8
  • f

    FunkyMuse

    01/19/2022, 9:07 AM
    Hey guys, is it possible with accompanist viewpager to only allow swiping right to left?
    c
    • 2
    • 3
  • p

    Peter Mandeljc

    01/19/2022, 10:27 AM
    is it okay to return constant view in AndroidView factory?
    val btn = Button(context)
    AndroidView(factory = { btn } )
    c
    z
    • 3
    • 7
  • t

    theapache64

    01/19/2022, 10:57 AM
    Hi there. I am trying to build an impression tracking SDK. To check if the
    Composable
    in the viewport, I am using a custom modifier with
    onGloballyPositioned
    method. Inside the lambda, am comparing the
    x and y
    cords of the
    Composable
    and compare it with window height/width. It works, but am wondering if there’s any better method/approach? 🙂
    c
    • 2
    • 6
  • c

    Csaba Szugyiczki

    01/19/2022, 12:27 PM
    There is an edge-case issue we just ran into while testing our app that is about to be released in the Play Store. When the Switch is swiped by the user the
    onCheckedChange
    callback is called. We launch a request to our server and if it is successful only then we change the actual value that is backing the Switch’s checked state. If this happens in around 100ms the switch can stuck in an endless loop. Did anyone have a similar problem? It would be nice if we did not have to touch anything below VM layer to prevent this.
    screen_record.mp4
    ➕ 2
    z
    m
    a
    • 4
    • 22
  • m

    myanmarking

    01/19/2022, 12:44 PM
    LaunchedEffect can see ‘updated’ State objects, but not non-state variables right? That why we use rememberUpdatedState. Can some1 explain this better to me please
    f
    z
    • 3
    • 2
  • t

    Tolriq

    01/19/2022, 1:01 PM
    Is there a way to have the m3 theme builder generating the tonal palette with a target primaryColor (either dark/light) ? Currently you can only use seed color but that color never ends up in the palette.
    c
    • 2
    • 1
  • c

    Colton Idle

    01/19/2022, 1:39 PM
    I'm trying to have an InputField on the screen, but the input field is just a button that opens up a modal (my designers decision) Any idea why something like this doesn't actually function properly. The onclick is never called and it just leave you to type in the field.
    @Composable
    fun FakeInputFieldButton(modifier: Modifier, onClick: () -> Unit, valueText: String) {
      val someFunc = {}
      OutlinedTextField("text", {}, modifier.clickable { someFunc() })
    }
    z
    s
    a
    • 4
    • 15
  • s

    Stephen Prochnow

    01/19/2022, 3:26 PM
    I think there is an issue with the calculation of the LocalContentAlpha in themes, the LocalContentAlpha is determined before the LocalContentColor is set. This results in wrong contrast values and nested themes use the LocalContentColor from the outer themes. More details in the thread.
    c
    c
    l
    • 4
    • 6
  • c

    Colton Idle

    01/19/2022, 3:32 PM
    A bit of an architecture question I suppose. I have this bottom sheet that's a picker and it can essentially be called from any screen.
    bottomSheet(route = Screen.NumberPickerBottomSheet.route) {
      NumberPickerBottomSheet()
    }
    In the bottom sheet when the "Save" button is hit, I want to update the number value to the screen/VM that started the bottomSheet. Since it was a navigation event that started the bottom sheet, I can't pass a lambda of like
    onNumUpdateEvent
    . What's the best way to go about this? The only other thing that comes to mind is for the screen/VM to implement some interface or something? Or maybe I just save the state in some Activity level VM? Edit: Or another option is to use the navController in the bottomsheet and use that to get the previous entry and get the VM/cast to the VM and update it that way?
    ➕ 1
    👍 1
    d
    a
    m
    • 4
    • 9
Powered by Linen
Title
c

Colton Idle

01/19/2022, 3:32 PM
A bit of an architecture question I suppose. I have this bottom sheet that's a picker and it can essentially be called from any screen.
bottomSheet(route = Screen.NumberPickerBottomSheet.route) {
  NumberPickerBottomSheet()
}
In the bottom sheet when the "Save" button is hit, I want to update the number value to the screen/VM that started the bottomSheet. Since it was a navigation event that started the bottom sheet, I can't pass a lambda of like
onNumUpdateEvent
. What's the best way to go about this? The only other thing that comes to mind is for the screen/VM to implement some interface or something? Or maybe I just save the state in some Activity level VM? Edit: Or another option is to use the navController in the bottomsheet and use that to get the previous entry and get the VM/cast to the VM and update it that way?
➕ 1
👍 1
d

Desmond Teo

01/19/2022, 3:58 PM
using compose navigation, you can use the savedStateHandle of the previousBackStackEntry to communicate to the screen that launches this picker destination
NumberPickerBottomSheet(
    onPickNumber = { value ->
        navController.previousBackStackEntry?.savedStateHandle?.set(key, value)
    }
)
👍 1
in your previous destination (the one launching the picker), you can then observe the value from
navBackStackEntry.savedStateHandle
using the same key the picker used
c

Colton Idle

01/19/2022, 4:51 PM
Oh hm. Interesting. Do those values only get "transfered" once the bottom sheet collapses/goes away though? example: In the activity/fragment world with extras you only got the "extra" once the activity/fragment was closed.
a

Arjun Achatz

01/19/2022, 7:13 PM
One step backwards, but does this need to be in the navigation graph? Let's say this wasn't a bottom sheet and it was just used everywhere, it could be a normal composable with a lambda call back (i.e nothing to do with navigation). I haven't used bottom sheets in compose yet since I keep hearing they're nightmares so plz excuse this if the suggestion doesn't make sense
I ask since
navController.previousBackStackEntry
seems a lot like starting an activity/fragment for result, which I've never been a fan of from a state mgmt prospective
c

Colton Idle

01/19/2022, 8:48 PM
It could arguably just be in every destination yes. But I have a lot of screens (40) and so adding this to every screen seems subpar, although it would 100% be easier on the state management side of things.
👍 1
d

Desmond Teo

01/20/2022, 2:31 AM
Oh hm. Interesting. Do those values only get "transfered" once the bottom sheet collapses/goes away though? example: In the activity/fragment world with extras you only got the "extra" once the activity/fragment was closed.
You can see the values immediately, because the previous destination is still active.
c

Colton Idle

01/20/2022, 3:49 AM
Thanks. appreciate the tips. TIL
m

Michal Klimczak

01/21/2022, 1:34 PM
I did something like this: https://gist.github.com/micHar/716d810f319973beb86ebbb1a5257be8 Although I'm exploring using a navgraph scoped viewmodel for communication between screens in a single navgraph and wondering what the most elegant approach is.
View count: 5