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

    Kevin Hester

    02/15/2020, 8:16 PM
    Hi ya'll. Alas - I've been looking but can't find it. What is the Compose function for an editable text box?
    1 reply · 1 participant
  • m

    mbonnin

    02/15/2020, 8:20 PM
    Has anyone started working on something like 'Flutter Gallery' but for compose ? Or maybe just listing the available
    @Composable
    components ?
    f
    t
    8 replies · 3 participants
  • b

    Bruno_

    02/15/2020, 8:41 PM
    dev05 coming out anytime soon? I'm still on 03 and not sure if it's worth to upgrade at this point cus it's been a while since 04 came out
    ➕ 1
    m
    r
    6 replies · 3 participants
  • k

    Kevin Hester

    02/15/2020, 10:04 PM
    ok - I found TextField, but is there any Compose equivalent for the material design TextInputLayout https://material.io/develop/android/components/text-input-layout/ ? i.e. a text field with all the hint/border/background goodness? Stuff like: https://material.io/components/text-fields
    f
    s
    3 replies · 3 participants
  • t

    Tim Strehlow

    02/16/2020, 9:56 PM
    Hey everyone, I'm just getting started with Compose. Is it possible to start with transforming one view of an existing codebase into a Composable and somehow use that within the old UI system?
    💡 1
    m
    2 replies · 2 participants
  • k

    Kevin Hester

    02/17/2020, 3:00 AM
    Hi ya'll my app in coming along nicely, I should have an early ugly version up on github this week. Another noob question (because I'm cribbing from jetnews). What is the dev04 equivalent to the following removed modifier?
    /**
     * A layout modifier that forces a target component to fill all available width.
     *
     * Example usage:
     * @sample androidx.ui.layout.samples.SimpleExpandedWidthModifier
     */
    val ExpandedWidth: LayoutModifier = object : LayoutModifier
    this is a lot of fun.
    1 reply · 1 participant
  • k

    Kevin Hester

    02/17/2020, 3:53 AM
    btw - will the JetNews app (which seems to be the most complete example out there) be getting updated to dev04/dev05?
    i
    a
    +3
    20 replies · 6 participants
  • i

    itnoles

    02/17/2020, 4:37 AM
    I really hate to ask your guys about the Material Components Support.
    k
    a
    6 replies · 3 participants
  • a

    amar_1995

    02/17/2020, 10:36 AM
    I am trying to render html page using androidview but getting this error while importing the dependancy.
    ERROR: Failed to resolve: androidx.ui:ui-android-view:0.1.0-dev04
    d
    f
    2 replies · 3 participants
  • k

    Kevin Hester

    02/17/2020, 5:49 PM
    Hmm - it seems the cursor in TextField is always black (rather than being white if using a dark palette). Also it doesn't seem to blink. Am I doing something wrong?
    TextField(
        value = message.value,
        onValueChange = { message.value = it },
        textStyle = TextStyle(
            color = colors.onSecondary.copy(alpha = 0.8f)
        ),
        imeAction = ImeAction.Send,
        onImeActionPerformed = {
            <http://MessagesState.info|MessagesState.info>("did IME action")
        },
        modifier = LayoutPadding(4.dp)
    )
    1 reply · 1 participant
  • k

    Kevin Hester

    02/17/2020, 6:33 PM
    A question on modifiers "
    Modifier elements may be combined using `+` Order is significant; modifier elements to the left
    * are applied before modifier elements to the right.
    Does the last applied operator override previous modifers of the same type? i.e. if I have something like lA = LayoutSize(...) lB = LayoutSize(...) modifer = lA + lB Is this doc saying that lB will be the layout size for the modifier?
    m
    2 replies · 2 participants
  • k

    Kevin Hester

    02/17/2020, 6:49 PM
    Is this the preferred way to merge TextStyles (in this case picking a standard style and then bumping down the opacity)?
    Text(
        text = "9:49 AM",
        modifier = LayoutPadding(left = 8.dp),
        style = MaterialTheme.typography().caption.merge(
            TextStyle(
                color = palette.onSecondary.copy(
                    alpha = 0.2f
                )
            )
        )
    )
    If so, what about letting TextStyles have an + operator to make their usage more similar to Modifiers?
    l
    9 replies · 2 participants
  • k

    Kevin Hester

    02/17/2020, 8:43 PM
    I'm having a hard time figuring out how to have items inside a column expand to fill most of the available space. How do I say: I want the first item in the column to get most of the space, and the second item to get only a little space? I've tried LayoutSize.Min, but it seems Fill always just covers everything - rather than taking what it can get? i.e. my layout looks like:
    fun MessagesContent() {
        Column(modifier = LayoutSize.Fill) { // want to fill entire screen
            Column(modifier = LayoutSize.Fill) {             
                 messages.value.forEach { // I want this list of messages to fill most of the view
                    MessageCard(
                        it, modifier = LayoutPadding(
                            left = sidePad,
                            right = sidePad,
                            top = topPad,
                            bottom = topPad
                        )
                    )
                }
            }
    
            Surface(
                modifier = LayoutPadding(8.dp) + LayoutSize.Min(40.dp, 40.dp),
                color = backgroundColor,
                shape = RoundedCornerShape(4.dp)
            ) {
                TextField(
                   ...
                )
            }
        }
    }
    l
    30 replies · 2 participants
  • k

    Klaas Kabini

    02/18/2020, 5:54 AM
    I am trying to implement a deck of cards whereby I want to rotate the topmost card in the deck at 20 degrees. I have added a Draw composable to the current Stack composable code to do the rotation but the issue is that the Draw composable rotate all the children not only the topmost. How do you tell the Draw composable which child to rotate in layout?
    s
    i
    +1
    4 replies · 4 participants
  • k

    kyleg

    02/18/2020, 8:54 PM
    Trying to learn Compose. I see lots of samples people have written using
    …, style=+textThemeStyle
    but cannot for the life of me figure out what
    textThemeStyle
    is. There’s a Github project I found that suggests it’s in
    androidx.ui.material
    but I don’t see it there for me. Probably something that was removed/deprecated-and-removed. What is it replaced by? I have one of my
    Composable
    functions wrapping a
    Scaffold
    with
    CustomTheme
    , and inside there I want to style a
    Text
    with a
    Typography
    defined inside the
    CustomTheme
    .
    l
    r
    6 replies · 3 participants
  • r

    Rodrigo Fonseca

    02/18/2020, 9:28 PM
    have any example with calls to api with compose?
    t
    5 replies · 2 participants
  • s

    spierce7

    02/18/2020, 10:56 PM
    I’m curious - I know the compose team has talked about releasing some parts of compose as multiplatform libraries separate from android, in the future after we have something stable for compose. I remember the tree analyzer was specifically mentioned around this. Was anything else discussed? Can anyone speak to how close that would get us to a compose api across multiple platforms?
    t
    2 replies · 2 participants
  • s

    SrSouza

    02/18/2020, 11:42 PM
    Hi guys, I'm getting this exception when I try to run the app using Compose, anyone knows this exception and why could be the cause?
    Untitled
    m
    1 reply · 2 participants
  • k

    kyleg

    02/19/2020, 6:04 AM
    Where are the samples mentioned in the source code? For instance, in
    Flex.kt
    , part of
    androidx.ui.layout
    the doc comment block above
    fun Column
    says
    @sample androidx.ui.layout.samples.SimpleColumn
    , but I cannot locate that in the package or the source or anywhere googling that string.
    l
    l
    6 replies · 3 participants
  • a

    ahulyk

    02/19/2020, 10:01 AM
    Hi folks :) I'm looking for documentation related to dev03 -> dev04 changes. Thank you in advance!
    j
    h
    7 replies · 3 participants
  • a

    amar_1995

    02/19/2020, 11:32 AM
    Compose app crash with error
    java.lang.IllegalStateException: Current layout is not an ancestor of the provided child layout
    Note: It is occuring only sometime and most of time it is working with no issue
    a
    2 replies · 2 participants
  • v

    Vitor Prado

    02/19/2020, 7:45 PM
    I’m trying to add compose to my app (currently using databinding) .. but it not compile.. can I have compose and databinding running side-by-side? (Maybe kapt is the main problem)
    👀 1
    s
    5 replies · 2 participants
  • t

    tcracknell

    02/19/2020, 9:22 PM
    Hello! The Jetpack Compose dev05 drop has just been released as part of our new continuous release model and you can get it now on Google’s Maven Repository. Release notes are available at https://developer.android.com/jetpack/androidx/releases/compose and https://developer.android.com/jetpack/androidx/releases/ui. Please note that the majority of the documentation including codelabs, tutorials, and samples will only be updated for major releases. Feedback is always welcome; please log issues at https://issuetracker.google.com/issues/new?component=612128!
    🎉 10
    🤩 6
    ❤️ 4
    👍 34
    z
    l
    +2
    6 replies · 5 participants
  • k

    Klaas Kabini

    02/20/2020, 12:30 PM
    Will the next release after 0.1.0-dev05 be alpha?
    🇳🇴 2
    🤦 2
    j
    a
    +1
    6 replies · 4 participants
  • a

    ahulyk

    02/20/2020, 4:02 PM
    Looks like right now we are not getting 60fps, phone Pixel 2 XL.
    z
    s
    +2
    27 replies · 5 participants
  • k

    Klaas Kabini

    02/20/2020, 7:12 PM
    @Leland Richardson [G] Can you confirm if I understood the content of your presentation very well (

    https://www.youtube.com/watch?v=6BRlI5zfCCk▾

    ) . May you point out any knowledge gaps in my understanding and help me in understand this better. The
    @Model
    annotation will make the count property inside the
    LabelState
    data class observable which in turn gives it the ability to trigger recompositions on subsequent mutations.
    @Model
    data class LabelState(var count:Int)
    Sample 1: Composable functions are positionally memoized meaning the inputs to composable functions, and their corresponding outcome resulting from composable functions calls are cached to avoid unneccessary recompositions when a composable function is called with the same inputs multiple times. In case where a composable function is called with the same inputs multiple times, compose runtime will check against the Slot table whether the same inputs have corresponding outputs that were previously cached. If yes, then the compose runtime will retrieve the previously cached results otherwise insert new inputs and their corresponding results to the Slot Table. Given that understanding, it means that the
    LabelState
    passed as input parameter to a composable in the following code snippet will be positionally memoized despite that is is not wrapped inside
    remember
    composable. Did I understood this correctly? If yes, then is this only applicable to situations where the state is hoisted? - in other words passed down the composable hierarchy from the owner to called composable functions?
    @Composable
    fun LabelThatPassStateAsParameter(labelState: LabelState){
        Text(text = "$labelState.count",
             style = MaterialTheme.typography().body1)
    }
    Sample 2 Alternatively, when the state is not passed as input to composable function, it can be obtained by a keeping a local variable that references the state by calling composable function such as
    state
    or a combination of
    @Model
    class wrapped inside
    remember
    composable as in code snippet below.
    val labelState = state {0}
    is equivalent to
    val labelState = remember { mutableStateOf(0) }
    where both does referential equality between old and new value to prior to mutation of state.
    @Composable
    fun LabelWithStateComposableThatDoesReferentialEquality(){
       val labelState = state {0}    
       Text(text = "$labelState.count", 
            style = MaterialTheme.typography().body1)
    }
    Otherwise if you want to do structural equality on state mutations, you can possible achieve by through the following. val
    labelState2 = remember { LabelState(0) }
    is equivalent to
    val labelState2 = remember { mutableStateOf(value = 0, areEquivalent = StructurallyEqual) }
    where both does structural equality between old and new value to prior to mutation of old state value.
    l
    p
    10 replies · 3 participants
  • k

    Klaas Kabini

    02/20/2020, 7:46 PM
    One of the exciting project that we are currently working on which is built completely with compose. It is still in early stage development and will be probably be ready for going live once compose reaches its production ready stages.
    device-2020-02-20-213533.webm
    👍 3
    l
    3 replies · 2 participants
  • k

    Kevin Hester

    02/20/2020, 10:29 PM
    Dear compose geeks. I know you said don't use this project for anything shipping, but just FYI - here's a hobby project that is using it for something shipping 😉. Don't worry - I'll keep updating to your newer builds and if needed (because ya'll decide you need to bail) it wouldn't be too painful for me to decomposemotize my app: https://www.meshtastic.org/
    👍 1
    m
    l
    2 replies · 3 participants
  • p

    pula

    02/20/2020, 11:31 PM
    does anyone have any working samples of testing composable functions? im getting
    E/TestRunner: java.lang.RuntimeException: Could not launch activity
    when I attempt to use
    createComposeRule()
    . or am I trying to use something that isn’t ready?
    @RunWith(JUnit4::class)
    class SampleTests {
    
        @get:Rule
        val composeTestRule = createComposeRule(disableTransitions = true)
    
        @Test
        fun twoComponents_areChecked() {
            composeTestRule.setContent {
                MaterialTheme {
                    Surface {
                        Column {
                            Checkbox(checked = true, onCheckedChange = null)
                            Checkbox(checked = true, onCheckedChange = null)
                        }
                    }
                }
            }
    
            findAll(isOn())
                .assertCountEquals(2)
                .forEach {
                    it.assertIsOn()
                }
        }
    }
    r
    c
    +1
    12 replies · 4 participants
  • t

    Thierry

    02/21/2020, 12:10 AM
    I still think I'm doing something wrong with the drawables, or there is a bug
    l
    11 replies · 2 participants
Powered by Linen
Title
t

Thierry

02/21/2020, 12:10 AM
I still think I'm doing something wrong with the drawables, or there is a bug
I have a reaction display composable as such
@Composable
fun ReactionDisplay(counts: Map<String, Int>) {

    val reactionIcons = mapOf(
        "like" to "\uD83D\uDC4D", "love" to "\u2764\uFE0F", "haha" to "\uD83D\uDE02",
        "wow" to "\uD83D\uDE32", "sad" to  "\uD83D\uDE41", "angry" to "\uD83D\uDE21"
    )


    Column {
        Surface(color=Color.Black) {

            Row(modifier = LayoutPadding(10.dp)) {
                for ((icon, count) in counts) {
                    Text(
                        text = reactionIcons[icon]!!,
                        style = TextStyle(color = Color.Red),
                        modifier = LayoutPadding(4.dp)
                    )
                    if (count > 1) {
                        Text(
                            text = "${count}",
                            style = TextStyle(color = Color.White),
                            modifier = LayoutPadding(4.dp)
                        )
                    }

                }
            }

        }
        VectorImage(id=R.drawable.stream_tail_incoming, tint=Color.Red)

    }

}
vector image does this
@Composable
fun VectorImage(
    modifier: Modifier = Modifier.None, @DrawableRes id: Int,
    tint: Color = Color.Transparent
) {
    val vector = vectorResource(id)
    Container(
        modifier = modifier + LayoutSize(vector.defaultWidth, vector.defaultHeight)
    ) {
        DrawVector(vector, tint)
    }
}
and loads this vector
<vector xmlns:android="<http://schemas.android.com/apk/res/android>"
    android:viewportWidth="25"
    android:viewportHeight="26"
    android:width="25dp"
    android:height="26dp">
    <group
        android:translateX="-274"
        android:translateY="-152">
        <group
            android:translateX="251"
            android:translateY="145">
            <path
                android:pathData="M46.891359 6.98775263C48.9803761 11.4859833 47.7147563 15.565241 46.3806948 17.9902209C45.0465335 20.4152008 42.4982945 22.7020908 40.5 26.2043725C39.167837 28.5391937 38.9979804 31 38.9979804 33C37.3571807 30.011653 35.2609596 27.7464773 32.5727539 26.2043725C29.8844483 24.6622678 26.3289084 23.9254878 23.0601981 23.9941325"
                android:fillColor="#000000"
                android:fillAlpha="1" />
        </group>
    </group>
</vector>
i would expect the vector to draw with a width of 25dp, but instead its tiny
note the red dot...
l

Louis Pullen-Freilich [G]

02/21/2020, 12:18 AM
Are you sure the vector resource you are using works properly normally? Did you try with another vector? From a brief look it looks suspicious that the viewportWidth is 25, but commands are way outside of that coordinate space
t

Thierry

02/21/2020, 12:23 AM
yes that vector works normally in a regular android app. other vectors do work for me, so its probably some edge case
l

Louis Pullen-Freilich [G]

02/21/2020, 12:24 AM
There might be some different behaviour in scaling then in the framework vs Compose, since this vector looks weird, I would recommend filing a bug in any case because there is some difference of behavior, but the vector you are using just doesn't look right
View count: 1