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

    Zach Klippenstein (he/him) [MOD]

    04/15/2020, 8:28 PM
    Was handling Rx errors by re-throwing them from the composition point considered? I think it’s more dangerous to drop exceptions automatically then thrown them – I’ve been bitten quite often by forgetting to wire up the Rx error handling behavior and dropping exceptions because of that. It would seem intuitive to me for
    subscribeAsState
    to behave like `Flow`’s
    collect
    . If you wrapped the exception outside the
    remember
    block before rethrowing, the stack traces would probably be really helpful for debugging as well. Errors still “should” be handled by
    onErrorReturn
    and friends, but at least that would reduce the likelihood that actual exceptions get dropped on the floor by accident.
    a
    a
    • 3
    • 3
  • c

    codeslubber

    04/15/2020, 9:57 PM
    Updated to 09. I cannot BELIEVE the TextField stuff is broken again, and there’s no mention of it in the release notes. Just feels like utterly pointless thrashing….
    🙃 1
    i
    z
    +3
    • 6
    • 11
  • s

    Siyamed

    04/15/2020, 11:30 PM
    Hi all! I wondered if any of you had any issues or suggestions related to multi-style text (AnnotatedString and its builder)?
    m
    z
    • 3
    • 15
  • m

    molikto

    04/16/2020, 3:55 AM
    I've been using the dev build http://androidx.dev/ Compose and it was working fine. But seems after the Kotlin rebase PR using dev build doesn't work anymore, because
    composeOptions.kotlinCompilerVersion
    needs the new compiler dependency. Does anyone know how to get the correct compiler dependencies? If there are no straightforward way then it is fine, I will just wait for dev10 published.
    j
    • 2
    • 1
  • v

    Vinay Gaba

    04/16/2020, 5:26 AM
    I was wondering when AndroidImageAsset is going to be exposed(it’s an internal class right now) so that I don’t have copy paste it. Moreover, is there an alternate way to do what I’m trying to do?
    a
    • 2
    • 2
  • z

    Zach Klippenstein (he/him) [MOD]

    04/16/2020, 10:05 PM
    I'm not sure if this is something the compose team has any influence over, and I think it's been mentioned in the channel before, but googling for Compose documentation is surprisingly difficult. I know the priority at this time is actually building the thing, not optimizing SEO, but it seems weird to me that the official docs are ranked so low that it's almost always easier to just go to the main site and search manually.
    👍🏻 4
    c
    • 2
    • 7
  • s

    Siyamed

    04/17/2020, 3:25 AM
    I renamed them as ui-text, ui-text-core and ui-text-android
    👍 4
    v
    • 2
    • 10
  • f

    flosch

    04/18/2020, 10:05 AM
    Hey guys, I am trying to provide a
    ColorPalette
    appwide like that:
    object AppColors {
        private val primaryColor: Color = Color(0x464763)
    
        val lightPalette: ColorPalette = lightColorPalette(
            primary = primaryColor
        )
    
        val darkPalette: ColorPalette = darkColorPalette(
            primary = primaryColor
        )
    
        @Composable
        val currentPalette: ColorPalette
            get() = if (isSystemInDarkTheme()) darkPalette else lightPalette
    }
    When I use it for my
    MaterialTheme(colors = AppColors.currentPalette) { … }
    , the primary color is just invisible or set to transparent, what am I doing wrong? If I dont overwrite the primary, then everything works as expected (images in thread).
    a
    g
    c
    • 4
    • 10
  • t

    Timo Drick

    04/18/2020, 1:35 PM
    Cool to see the Material FilledTextField in the new dev-09. But i am missing following attributes: "keyboardType", "imeAction" and also a callback for "onImeActionPerformed".
    g
    • 2
    • 2
  • m

    MBegemot

    04/18/2020, 3:10 PM
    Apparently when I change the material theme all subcomponents get correctly updated, except those placed inside a dialog .... those seem to keep the initial value of the theme, but the same component called outside the dialog changes accordingly .... I might be utterly wrong but ..
    a
    l
    • 3
    • 2
  • j

    jitinsharma

    04/18/2020, 4:11 PM
    I got an compiler error when I tried to use Flow with compose, which is already reported here https://github.com/Kotlin/kotlinx.coroutines/issues/1637 Is coroutines/flow support available with compose(dev-08)?
    a
    • 2
    • 2
  • s

    SrSouza

    04/19/2020, 5:31 PM
    There is any RichText composable?
    l
    g
    +2
    • 5
    • 4
  • l

    louis993546

    04/20/2020, 8:21 AM
    Any suggestion on how to implement stagger grid (i.e. pinterest) with compose?
    m
    • 2
    • 1
  • m

    molikto

    04/21/2020, 3:14 AM
    Question: textstyle, content color, emphasis, how they interact? and what's the intended use of them collaboratively? for example currently the default light Material Theme use a 0x000000 content color, I would expect
    Text
    pick up a Emphasis.high, so the actual content color for Text is not pure black.
    l
    • 2
    • 5
  • b

    bhatnagarm

    04/21/2020, 9:09 AM
    Hey Everyone, Did anyone try to start a progressBar on a button click. For me it gives an compile time error
    Functions which invoke @Composable functions must be marked with the @Composable annotation
    which is fine. I'm wondering what's the alternative to this.
    m
    • 2
    • 1
  • l

    Laura Oran

    04/21/2020, 4:28 PM
    Hello, anyone knows how to align center a Text with more than 1 line? With 1 line it is align center horizontally correctly, but with more no
    l
    • 2
    • 5
  • s

    semoro

    04/21/2020, 7:15 PM
    Why image corners not being clipped if using
    ContentScale.FillWidth
    ? When image width is bigger then clip area
    Image(
        asset = image,
        modifier = Modifier.clip(RoundedCornerShape(20.dp)),
        contentScale = ContentScale.FillWidth
    )
    • 1
    • 3
  • f

    Fudge

    04/21/2020, 7:50 PM
    https://android-review.googlesource.com/c/platform/frameworks/support/+/1290729 Are there plans to make Compose apps work on desktop platforms?
    👀 14
    m
    g
    o
    • 4
    • 4
  • g

    Gabriel Feo

    04/21/2020, 8:25 PM
    How can one disable selection on
    Text
    or filter all touch events?
    s
    • 2
    • 3
  • m

    Mark Murphy

    04/21/2020, 9:16 PM
    If at compile time all modifiers are valid for all composables (https://kotlinlang.slack.com/archives/CJLTWPH7S/p1587486859370700?thread_ts=1587486512.370000&cid=CJLTWPH7S)... will there be any sort of compile-time checking for validity here? Lint rules, perhaps?
    l
    l
    a
    • 4
    • 5
  • v

    Vinay Gaba

    04/22/2020, 5:29 AM
    I know that coroutine support is coming soon (hopefully dev10). Would that version also allows us to use kapt in the same module as compose?
    l
    • 2
    • 3
  • r

    romainguy

    04/22/2020, 4:49 PM
    Elevation matches Material Design specs and has the immense benefit of guaranteeing consistency
    g
    • 2
    • 3
  • f

    flosch

    04/22/2020, 5:33 PM
    Any plans for some kind of blur api? 🤔
    👍🏻 5
    z
    • 2
    • 1
  • s

    sunnat629

    04/22/2020, 5:48 PM
    Hello everyone, where I can get the list of all compose dependencies like
    androidx.ui:ui-framework:$compose_version
    ? Thanks in advance...
    f
    • 2
    • 3
  • g

    Gabriel Feo

    04/23/2020, 12:36 AM
    For a shape which has three clickable like this one, how would one identify click coordinates?
    PointerInput
    doesn't seem to be a fit, as
    PointerInputHandler
    can't be
    @Composable
    l
    m
    • 3
    • 8
  • m

    molikto

    04/23/2020, 4:47 AM
    I think this is a bug but want to confirm: I have a
    savedInstanceState
    inside a "view pager" page, and when I go to another page then come back I got an
    Key -751342538 was already registered. Please call unregister before registering again
    at androidx.ui.savedinstancestate.UiSavedStateRegistryImpl.registerProvider
    l
    a
    • 3
    • 4
  • l

    Luoqiaoyou

    04/23/2020, 8:18 AM
    Who knows where can get the source code of Compose IDE Plugin? I follow this guideline:https://android.googlesource.com/platform/frameworks/support/+/androidx-master-dev/README.md , And I can see the Compose Kotlin Compile Plugin in the path “./frameworks/support/compose/compose-compiler-hosted”, but not IDE Plugin
    j
    s
    +2
    • 5
    • 9
  • m

    molikto

    04/23/2020, 1:40 PM
    Is there a way to mark a parameter of type
    List<String>
    as stable?
    a
    l
    z
    • 4
    • 24
  • s

    ShreemanArjun

    04/23/2020, 7:39 PM
    How to place a Text in center in latest update dev 09 version? There is no composable function Center(deprecated). Please help if anyone can...
    🎉 1
    z
    a
    +2
    • 5
    • 17
  • c

    Colton Idle

    04/24/2020, 1:11 AM
    @Brian Gardner your droidcon online session today was really good and it has me excited!
    l
    b
    r
    • 4
    • 40
Powered by Linen
Title
c

Colton Idle

04/24/2020, 1:11 AM
@Brian Gardner your droidcon online session today was really good and it has me excited!
l

Leland Richardson [G]

04/24/2020, 5:55 AM
Was it recorded? I have seen a ton of positive feedback about it and would love to check it out
c

Colton Idle

04/24/2020, 6:52 AM
@Leland Richardson [G] yep. Should be recorded and going onto droidcon videos soon. I'll ping ya if I see it. 😄
b

Brian Gardner

04/24/2020, 2:18 PM
Thanks! I’m glad you liked it! I had a ton of fun with the session and I’m looking forward to making more video content soon
👍 1
The recording is now live https://www.droidcon.com/media-detail?video=412304809
👍 2
l

Leland Richardson [G]

04/27/2020, 9:01 PM
@Brian Gardner this was great. really nice intro for people. I’m a bit curious about the state issue you mentioned with AdapterList. Is this a known issue reported somewhere? cc @Ryan Mentley Also, i’m curious if you intentionally were saying to use
mutableStateOf(...)
where you used it instead of
state { ... }
. The latter seems more correct based on the usage.
r

Ryan Mentley

04/27/2020, 9:02 PM
Which state issue? Timecode?
b

Brian Gardner

04/27/2020, 9:03 PM
I reported the issue here https://issuetracker.google.com/u/2/issues/151860426
l

Leland Richardson [G]

04/27/2020, 9:04 PM
in the video above, he is creating a toggleable button in each item of an adapterlist but said that it wasn’t updating when the state would get changed. My hunch is that the problem was actually just that mutableStateOf was being used instead of
state
though.
b

Brian Gardner

04/27/2020, 9:04 PM
I likely wasn’t intentional about the state part. Why would the
mutableStateOf()
work differently than
state
?
l

Leland Richardson [G]

04/27/2020, 9:06 PM
mutableStateOf
is like a constructor, and will create a new instance each time (with the value you pass in). The
state
function is a composable function which will only execute the
init
lambda the first time, and it will remember the instance each time. when creating state ina composable function, this is usually what you want. it is basically shorthand for
remember { mutableStateOf(init()) }
r

Ryan Mentley

04/27/2020, 9:07 PM
The
mutableStateOf
in the preview, I think, is the one that probably should lost be
state
b

Brian Gardner

04/27/2020, 9:08 PM
Ok, so creating the mutable state won’t trigger a recompose unless it’s wrapped in a
remember{}
block inside the composable function?
r

Ryan Mentley

04/27/2020, 9:09 PM
The code looks...otherwise mostly correct, but there's one suspicious bit. @Leland Richardson [G] is it valid to pass a
MutableState
directly like this? https://github.com/BrianGardnerAtl/JetpackComposePlayground/blob/adapter-list-state-spike/app/src/main/java/tech/briangardner/composeplayground/MainActivity.kt#L58
l

Leland Richardson [G]

04/27/2020, 9:09 PM
@Brian Gardner it does actually trigger an update… but when it recomposes the function, you just create a different mutable state instance (initialized to the same original value as before), so it doesn’t look like it’s doing anything
r

Ryan Mentley

04/27/2020, 9:09 PM
or should the value be passed directly?
l

Leland Richardson [G]

04/27/2020, 9:10 PM
it’s valid to do either
b

Brian Gardner

04/27/2020, 9:10 PM
ah ok, I didn’t realize it was calling the composable function again to recreate the view. I wasn’t sure how the recompose step worked but that makes sense
r

Ryan Mentley

04/27/2020, 9:11 PM
alright, in that case that does look like it's probably an AdapterList bug, because the rest of the mutable state code outside of the preview looks correct
I'd have to debug it to be sure, though.
l

Leland Richardson [G]

04/27/2020, 9:11 PM
yeah it calls the function again. similar to react, flutter, etc, you want to write your composable functions as if they can be called “again” at any time, so if the function itself is introducing the state, you want to make sure and hold onto it properly (hence, use remember or state)
b

Brian Gardner

04/27/2020, 9:13 PM
Another question I have is where it’s appropriate to create the state, since the functions can be called again. It seems like the state should be declared at the top-level, ‘screen’ component and passed down to the children. At least if the view state needs to change based on user interaction
l

Leland Richardson [G]

04/27/2020, 9:17 PM
there’s a whole can of worms that can be opened by that question… more or less, i try to think of it as create it in the place where the state is “owned”. That can be hard to define, but in general a good “rule of thumb” first candidate is going to be the closest ancestor composable where the value is used entirely “below” it, and nowhere else. If that scope changes, just move the state “up” until it is satisfied again
but there’s a lot more that goes into it and i might give a different answer depending on the context.
for instance, if there’s some state variable like “current logged in user”, that is going to be used at a much higher level than something more locally scoped or even just something less business-logic-specific and more ui-logic specific
b

Brian Gardner

04/27/2020, 9:20 PM
That makes sense. The main scenario I think of is loading data from a database (or web server). I can setup the state when the data loads but when I need to modify the data based on the user interaction, how do I update the screen with the new data?
Assuming the ViewModel (or presenter) handles the data loading and updates, would I just create a new composable with the updated data or is there a better way to swap it out
l

Leland Richardson [G]

04/27/2020, 9:22 PM
in those cases i think the better thing is to use something other than state (like LiveData or Flow etc.) and then join that data into the composable hierarchy using state, but keep state as an implementation detail
you can see how this is done with some of our interop libraries with Rx and LiveData
b

Brian Gardner

04/27/2020, 9:23 PM
Yeah, I saw that compose has the flow/rxjava to state stuff now which is cool. I’ll have to look into that more.
l

Leland Richardson [G]

04/27/2020, 9:23 PM
but in this case it is important to leverage tools such as
onCommit
to do it properly
also we will be releasing some new APIs around coroutines and such that will make a lot of this really really nice if your data layer uses suspend functions
b

Brian Gardner

04/27/2020, 9:24 PM
Sweet! We’re definitely moving towards suspend functions for our data layers so that will be nice
l

Leland Richardson [G]

04/27/2020, 9:25 PM
nice
b

Brian Gardner

04/27/2020, 9:25 PM
I haven’t messed with
onCommit
or
onActive
too much so I’ll look into those next
Thanks for talking through this stuff with me!
l

Leland Richardson [G]

04/27/2020, 9:26 PM
no problem!
thanks for creating such good content. it was a very well done live coding example
also, if you can, can you try updating your example to use
state
and see if that fixes the adapterlist bug you filed?
b

Brian Gardner

04/27/2020, 9:27 PM
I’m glad you liked it! I can take some time tomorrow morning to rework my sample to see if using
state
works
l

Leland Richardson [G]

04/27/2020, 9:28 PM
awesome, thanks!
View count: 2