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

    Adam Powell

    05/13/2020, 7:14 PM
    Heads up, folks, dev11 is temporarily delayed while we work out a build system/gradle plugin issue that was producing artifacts with missing kotlin metadata. More as it develops and we're working to get it out ASAP.
    👍🏼 1
    👍🏻 36
    a
    m
    t
    • 4
    • 4
  • b

    bohregard

    05/14/2020, 12:14 AM
    What’s the easiest way to bottom align something
    Box(
        modifier = Modifier.fillMaxSize(),
        gravity = Alignment.BottomEnd
    ) {
        Column(modifier = Modifier.fillMaxHeight()) {
            ....
        }
        val icon = vectorResource(id = R.drawable.ic_home)
        FloatingActionButton(
            onClick = {
            }, modifier = Modifier.padding(20.dp)
        ) {
            Image(asset = icon, modifier = Modifier.preferredSize(24.dp))
        }
    }
    Is there a better way than the above?
    v
    m
    • 3
    • 2
  • t

    Timo Drick

    05/14/2020, 9:22 AM
    Because the AdapterList is not working correctly for now. I implemented my own custom list. I think the performance is more or less similar but it do not crash so often and it calls onDispose when a item is not visible any more. And also for me it is impressive that it is possible to implement a AdapterList in 60 lines of code.
    😮 2
    • 1
    • 1
  • j

    jitinsharma

    05/14/2020, 1:29 PM
    I’ve created a custom theme by creating a color palette
    val themeColors = lightColorPalette(
        primary = Color(0xFF092432),
        primaryVariant = Color(0xFF092432),
        secondary = Color(0xFF3DDB85)
    )
    And initialised the same like this
    MaterialTheme(colors = themeColors) {
    // children
    }
    Now if I access colors using
    MaterialTheme.colors
    , I’m able to get custom colors in all composables except for
    Dialog
    In
    Dialog
    , the colours reset to default values. Is this a known issue?
    l
    z
    • 3
    • 3
  • v

    Val Salamakha

    05/15/2020, 12:15 AM
    Is the dependency
    "androidx.ui:ui-framework"
    excluded from compose?
    l
    • 2
    • 1
  • z

    Zach Klippenstein (he/him) [MOD]

    05/15/2020, 10:55 AM
    What are yall's thoughts on making composable functions to render a specific type: 1️⃣
    DrawFoo(myFoo)
    2️⃣
    myFoo.draw()
    Both functions are composable and do the same thing. Worded another way, when is it appropriate/idiomatic to create a composable extension function?
    1️⃣ 6
    2️⃣ 3
    j
    • 2
    • 3
  • g

    Gabriel Feo

    05/15/2020, 12:41 PM
    Is there any particular reason in some contexts the term “widget” is chosen over “component”? The framework, compose and Flutter for that matter, seem to have made this decision, and I wonder if I’m missing something or if it’s just general preference
    j
    s
    +4
    • 7
    • 23
  • c

    carlos cdmp

    05/15/2020, 1:27 PM
    1. The actual version of compose is just to have feedback from people playing with it, but it´s not expected to be enough to build a full app right? 2. Is someone trying to create a "real app" with compose and trying to have a polished view?. And in that case what are the thoughts about it?
    t
    a
    m
    • 4
    • 12
  • r

    romainguy

    05/15/2020, 2:53 PM
    It could be enough, it depends on your needs but APIs may (will?) change drastically and you may (will?) run into stability/performance issues. To us it is not production ready
    a
    • 2
    • 1
  • v

    Val Salamakha

    05/16/2020, 3:50 AM
    What is difference between for example: “tagModifier.plus(focusModifier)” and “tagModifier + focusModifier”?
    l
    g
    • 3
    • 3
  • c

    cb

    05/16/2020, 8:28 AM
    Figured I'd post this here too: https://twitter.com/chrisbanes/status/1261279161735208960 The MDC interop is especially useful as you migrate existing apps over
    🤩 8
    👍 5
    c
    • 2
    • 1
  • h

    henrikhorbovyi

    05/16/2020, 4:14 PM
    Hello everyone, Someone knows how to solve this preview problem??
    k
    z
    +2
    • 5
    • 12
  • k

    Kazemihabib1996

    05/16/2020, 5:01 PM
    A jetpack compose shimmer effect modifier library https://github.com/kazemihabib/compose-shimmer
    👍 14
    a
    r
    • 3
    • 13
  • v

    Vinay Gaba

    05/16/2020, 11:54 PM
    Wondering if there is a notion of “scaling” a composable. Like if I increase the display size or scale of my android device, how does compose honor that? Moreover, if I want to do that at an individual composable level, what’s the best way to do it?
    g
    z
    c
    • 4
    • 9
  • g

    grandstaish

    05/17/2020, 1:23 AM
    What's the plan regarding try/catch with compose? I really want my parent components to be able to catch and handle certain exceptions from children
    a
    t
    • 3
    • 9
  • m

    molikto

    05/17/2020, 8:50 AM
    Is there a way to draw rotated text? The Canvas API has no drawText
    k
    l
    +3
    • 6
    • 7
  • c

    caelum19

    05/17/2020, 10:48 PM
    For ConstraintLayout, it seems percent(100f) refers to 100x the size of the parent? I reckon it should be renamed or changed a bit, since "percent" means "per one hundred"
    s
    m
    • 3
    • 3
  • c

    coolchandrakumar

    05/18/2020, 1:44 PM
    Done the swipe action using the snippet
    val modifier = Modifier.rawDragGestureFilter(dragObserver = object : DragObserver { })
    Button( onClick = {
       log()
    }) {
    Text(text = "Delete")
    }
    
    Box( modifier = modifier.drawLayer(
                translationX = itemLeft.value
            )
    ) {
    }
    Button click not working !!! translationX not moving the actual UI coordinates !?
    swipeAction.mov
    a
    t
    • 3
    • 9
  • z

    Zach Klippenstein (he/him) [MOD]

    05/18/2020, 3:53 PM
    I've been using
    OwnerAmbient
    to get access to the root View for inflating nested Android views further down in the composition. The inflation is being done by another library, so I can't use the
    AndroidView(Int)
    composable. However,
    OwnerAmbient
    is deprecated. Is there (or will there be) another API for getting access to the View hosting a composition?
    a
    • 2
    • 6
  • v

    Vinay Gaba

    05/18/2020, 4:58 PM
    I noticed that in dev11 there was cleanup in the
    ContextDrawScope
    and
    clipRRect
    was removed from it. What’s the alternative if I want to clip a rect with rounded corners?
    a
    k
    n
    • 4
    • 14
  • k

    Kazemihabib1996

    05/18/2020, 5:43 PM
    I've seen the word
    subcomposition
    multiple times in slack, what does it mean?
    j
    • 2
    • 1
  • t

    Timo Drick

    05/18/2020, 8:48 PM
    How should touch drag gesture consumption work? I have following problem. I do have e.g.: A scrollable list and each element can be swiped. The problem now is that both gestures are detected at the same time. But i want to stop detecting the swipe gesture when the user is scrolling and vice versa. Here is a sample (A little bit simplified just using Vertical/HorizontalScroller to demonstrate the problem:
    VerticalScroller() {
        Column(Modifier.padding(10.dp)) {
            for (i in 0..50) {
                Box(backgroundColor = if (i % 2 == 0) Color.LightGray else Color.Gray) {
                    HorizontalScroller(()) {
                        Row {
                            for (j in 0..10) {
                                Text("i: $i element $j", Modifier.padding(20.dp))
                            }
                        }
                    }
                }
            }
        }
    }
    m
    • 2
    • 4
  • b

    bohregard

    05/18/2020, 10:51 PM
    Anyone have any ideas why during build I get an error related to SurfaceView unresolved reference:
    @Composable
    fun buildUi() {
        Column(
            modifier = Modifier.fillMaxSize(),
            horizontalGravity = Alignment.CenterHorizontally
        ) {
            SurfaceView(ContextAmbient.current)
        }
    }
    l
    r
    a
    • 4
    • 14
  • d

    dagomni

    05/19/2020, 6:06 PM
    Hi! Is there an alternative in Compose Text for TextView's autoSize text scaling?
    l
    s
    m
    • 4
    • 30
  • k

    kagomez

    05/20/2020, 6:08 AM
    Hey guys 😄 I’ve been testin Compose and I have a question, how do you draw a shadow into an Image??
    Untitled
    r
    • 2
    • 11
  • a

    Antanas A.

    05/20/2020, 11:33 AM
    Hello, Is it possible to try out compose without android itself? I mean just somehow use only compose core where I can write @Composable functions and somehow run (render) these functions with my own implementation.
    s
    • 2
    • 2
  • g

    grandstaish

    05/20/2020, 3:45 PM
    Suppose I wanted to draw a loading spinner, but only if a load is taking longer than X milliseconds to complete (to avoid jarring/sudden UI changes for really quick async loads). Once the loading spinner is showing however, I want it to stick around for Y milliseconds before rendering the new data. Is this ux possible in Compose?
    v
    l
    +2
    • 5
    • 7
  • s

    SrSouza

    05/20/2020, 5:42 PM
    Hi folks, I'm writing a project that I download dynamically a font family and store at the device, there is anyway in Compose right now to generate a Font Family from this downloaded Files (Not resource ones) ?
    l
    s
    • 3
    • 6
  • f

    flosch

    05/21/2020, 6:40 PM
    Hey, I need a CoroutineScope that lives as long as the current composition. is this valid?
    @Composable
    internal fun composeCoroutineScope(
        coroutineContext: CoroutineContext = SupervisorJob() + Dispatchers.Main.immediate
    ): CoroutineScope {
        val scope = remember { CoroutineScope(coroutineContext) }
        onDispose { scope.cancel() }
        return scope
    }
    z
    a
    +2
    • 5
    • 48
  • g

    Guy Bieber

    05/21/2020, 9:08 PM
    I have a class I am using GSON to convert into the body of a REST request. When the class is marketed @Model for compose it adds “$record” and “frameId” into the json which breaks the request. Any good way to get around this?
    Expected (without @Model):
    {"public_key":"","user":{"email":"<mailto:me@me.com|me@me.com>","password":"fun"}}
    
    Actual (with @Model): 
    {"$record":{"user":{"$record":{"me":"<mailto:guy@me.com|guy@me.com>","password":"fun","frameId":1}},"frameId":1},"public_key":""}
    z
    • 2
    • 26
Powered by Linen
Title
g

Guy Bieber

05/21/2020, 9:08 PM
I have a class I am using GSON to convert into the body of a REST request. When the class is marketed @Model for compose it adds “$record” and “frameId” into the json which breaks the request. Any good way to get around this?
Expected (without @Model):
{"public_key":"","user":{"email":"<mailto:me@me.com|me@me.com>","password":"fun"}}

Actual (with @Model): 
{"$record":{"user":{"$record":{"me":"<mailto:guy@me.com|guy@me.com>","password":"fun","frameId":1}},"frameId":1},"public_key":""}
z

Zach Klippenstein (he/him) [MOD]

05/21/2020, 9:39 PM
@Model
is getting deprecated. Is your class immutable? Then you should mark it
@Immutable
instead.
g

Guy Bieber

05/21/2020, 9:40 PM
the app model needs to be mutable.
how is @Model going to be deprecated?
z

Zach Klippenstein (he/him) [MOD]

05/21/2020, 9:41 PM
https://twitter.com/intelligibabble/status/1261044551705227264?s=20
👍 1
Check out that PR linked in the tweet, more info there.
👍 1
g

Guy Bieber

05/21/2020, 9:42 PM
Any way around the problem in the short term?
Wow. Big change.
When is this going beta?
z

Zach Klippenstein (he/him) [MOD]

05/21/2020, 9:46 PM
It seems a bit unusual to have your JSON model type double as a live app model. My first instinct would be to make your JSON model immutable, and store it in a
MutableState
. If you need to change your json model, just put a new instance into the state. If you can’t use an immutable value for some reason, then you can make a wrapper that maintains
MutableState
properties for every property on your JSON object.
The team has declined to give a date for beta. The
@Model
deprecation is landing in the next dev release though.
g

Guy Bieber

05/21/2020, 9:50 PM
I have a message that can go over multiple transports. For messages that go only over one transport the message data structure becomes a field in the model. This avoids lots of translation.
not an easy way to have a class be a @Model and not @Model
z

Zach Klippenstein (he/him) [MOD]

05/21/2020, 9:56 PM
I still don’t understand why your can’t just put your message values in
MutableState
holders in your UI layer. How are your JSON model objects mutated?
g

Guy Bieber

05/21/2020, 10:00 PM
GSON
RequestData (user name, user pass, public key)
ResponseData (units (id, public key))
z

Zach Klippenstein (he/him) [MOD]

05/21/2020, 10:02 PM
IIRC, GSON will return a new instance when deserializing, not mutate an existing one, is that not true?
g

Guy Bieber

05/21/2020, 10:03 PM
Correct.
But I can’t have the ResponseData be both model and not model
z

Zach Klippenstein (he/him) [MOD]

05/21/2020, 10:03 PM
So what’s mutating your ResponseData?
g

Guy Bieber

05/21/2020, 10:04 PM
it gets copied into the app model, however it could be changed in other ways.
will @Immutable still change the compose view
for instance the user can change the name and password.
that’s on the outgoing though
meh
z

Zach Klippenstein (he/him) [MOD]

05/21/2020, 11:16 PM
In general, it’s a good practice to decouple your UI state from your backend data transfer layer.
View count: 1