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

    Manuel Wrage

    01/14/2020, 9:34 PM
    Will we get something like
    rootAmbient(MyAmbient
    ) or maybe all instances of the ambient above the tree?
    a
    c
    • 3
    • 3
  • i

    Ian Warwick

    01/15/2020, 9:15 AM
    Hey folks, got this issue where I compose some UI based on a model which shows either
    TextInput
    or
    Text
    when I double click on the text it turns the
    Text
    into a
    TextInput
    in the compose tree
    @Composable
    private fun Text(
        element: TextElement,
        inEdit: Boolean = false
    ) {
        val textStyle = TextStyle(
            background = Color.Transparent,
            fontWeight = element.fontWeight,
            fontSize = TextUnit.Em(element.fontSize),
            color = element.color
        )
    
        val spacing =
            Spacing(element.spacingLeft.dp, element.spacingTop.dp, element.spacingRight.dp, element.spacingBottom.dp)
    
        if (inEdit) {
            TextField(modifier = spacing, value = element.text, textStyle = textStyle, onValueChange = {
                element.text = it
            })
        } else {
            Text(modifier = spacing, text = element.text, style = textStyle)
        }
    }
    It seems that even though
    Text
    is being displayed Compose is still receiving text input via the missing
    TextInput
    (see video) possibly.. I would expect that if a recompose occurs then it would not exist in this part of the compose graph anymore 🤔 any ideas?
    text_input_issue.mov
    m
    • 2
    • 4
  • g

    gpaligot

    01/15/2020, 2:04 PM
    Hello! I’m trying to add a
    TextField
    in my screen but the component have a weird behavior. When I type any text in the text field, there isn’t any visual in the component on the screen. Someone has already encountered this issue? You can find my code here:
    @Composable
    fun Password(data: LoginForm) {
        MyTextField(
            hint = "Password",
            keyboardType = KeyboardType.Password,
            imeAction = ImeAction.Done,
            onValueChange = { data.email = it }
        )
    }
    
    @Composable
    fun MyTextField(
        hint: String,
        onValueChange: (text: String) -> Unit,
        keyboardType: KeyboardType = KeyboardType.Text,
        imeAction: ImeAction = ImeAction.Unspecified
    ) {
        val typography = +MaterialTheme.typography()
        val model = +state { "" }
        Padding(left = 8.dp, right = 8.dp, top = 8.dp) {
            Column {
                Text(
                    text = hint,
                    style = typography.subtitle1
                )
                HeightSpacer(height = 8.dp)
                TextField(
                    value = model.value,
                    onValueChange = onValueChange,
                    keyboardType = keyboardType,
                    imeAction = imeAction,
                    textStyle = typography.body1,
                    modifier = ExpandedWidth
                )
            }
        }
    }
    s
    • 2
    • 2
  • s

    seb

    01/15/2020, 2:14 PM
    Ping? https://kotlinlang.slack.com/archives/CJLTWPH7S/p1578991868120600
    a
    • 2
    • 31
  • c

    codeslubber

    01/15/2020, 10:55 PM
    For me, the worst part about Compose is having to find all the dumb little tweaks to make the UI not look stupid, I got a
    TextField
    working (yay), but it looks awful and I wasted way too much time trying to figure out what I am supposed to ask for to get the border off the input…
    i
    m
    • 3
    • 3
  • c

    codeslubber

    01/16/2020, 12:33 AM
    I think this shows that Compose is not ready for its Hello World yet: https://gist.github.com/ErikHellman/d95ba1fa789e598a2ec6d40e69512b8d takes a lot of ugly little tweaks to make a form with 2 input fields..
    f
    c
    +4
    • 7
    • 14
  • i

    Ian Warwick

    01/16/2020, 11:37 AM
    Is there any known issue with having
    @Model
    annotated data classes in a different gradle module to where they are used in a compose tree? Just tried to move my model and when I run my app there are not recompositions when my model changes? 😞
    d
    • 2
    • 4
  • i

    Ian Warwick

    01/16/2020, 2:46 PM
    I added a
    <group>
    tag into my vector drawable xml to rotate it 90 degrees and it shows up in preview but not in app with
    DrawVector
    shows up blank 🤔
    l
    • 2
    • 2
  • r

    Roar Gronmo

    01/16/2020, 6:42 PM
    Any update on release date for 'dev04' ?
    🔝 5
    a
    i
    m
    • 4
    • 7
  • k

    Klaas Kabini

    01/17/2020, 7:56 AM
    @Leland Richardson [G] I previously saw your reply to one of the post here on slack where you shared a github gists link of a scrappy version of navigation arch component implementation that can be used with compose. Would you mind sharing that link again because i had a difficulty this morning finding that post you replied to with a link.
    a
    • 2
    • 2
  • k

    Klaas Kabini

    01/17/2020, 8:07 AM
    Giving a Surface composable a fixed height through modifiers does not work. Is that an expected behaviour of the Surface composable or a bug?
    m
    • 2
    • 6
  • a

    amar_1995

    01/17/2020, 12:31 PM
    I am using
    +onCommit
    and it is working perfectly fine. But I am unable to understand when
    onDispose
    is called.
    var user : User? = null
            // Active type use-case
            +onCommit(1) {
                user = UserAPI.getUserData()
                onDispose {
                    UserAPI.letDiscompose() // It contains only println line
                }
            }
    m
    z
    • 3
    • 5
  • k

    Klaas Kabini

    01/18/2020, 3:29 PM
    Is support for coroutines in compose coming soon or is it something not on the list of priorities yet?
    a
    • 2
    • 3
  • i

    itnoles

    01/19/2020, 1:14 AM
    I have two Column on FlexRow. One of the Column has
    Arrangement.End
    it doesn't expand into the right side of the view. Am I missing something?
    m
    • 2
    • 8
  • j

    Joseph Cheng

    01/19/2020, 1:50 PM
    Hi, I try to render a blue rectangle with fixed width and height, but it always fill the parent.
    setContent {
                MaterialTheme {
                    ColoredRect(color = Color.Blue, width = 100.dp, height = 50.dp)
                }
            }
    But once I put a
    Container
    as the parent, it works as expected. May I know why?
    setContent {
                MaterialTheme {
                    Container {
                        ColoredRect(color = Color.Blue, width = 100.dp, height = 50.dp)
                    }
                }
            }
    k
    m
    • 3
    • 6
  • i

    Ian Warwick

    01/19/2020, 7:55 PM
    I was reading there is a limitation using coroutines at the moment, what is the nature of the problem? I got this
    Caused by: java.lang.IllegalStateException: Not in a frame
            at androidx.compose.frames.FramesKt.currentFrame(Frames.kt:180)
    Is it related? happens when I use
    IO
    scope and not sure if its just me doing something wrong or I hit a known issue
    z
    a
    • 3
    • 5
  • s

    shikasd

    01/20/2020, 6:53 PM
    Hi, I've been playing around trying to implement recycler "view" on Compose and this far for now: https://gist.github.com/ShikaSD/30ce3afc9376767f9ac090457733f627 Currently it only scrolls down and displays items correctly if you do it slowly 🙂 I have encountered an issue that layout in compose cannot add children synchronously. E.g. if recycler has some space at the bottom, it cannot be sure how many items it should lay out at once, as you cannot add and measure new items in the middle of layout pass. Currently my workaround is to keep a window of visible elements and increase/decrease it when items go out of the visible area. However, I add elements one by one (as I don't know how much space they will take) which is a bit slow (and require multiple passes to fill the screen for the first time). Do you have any suggestions on how to approach this better?
    👍 1
    k
    z
    +2
    • 5
    • 17
  • i

    Ian Warwick

    01/21/2020, 8:28 PM
    Hey composers, anybody got this stack yet? Not sure if prob between chair and keyboard or something known :)
    Untitled
    a
    • 2
    • 4
  • a

    amar_1995

    01/22/2020, 11:24 AM
    I am trying to use Room with compose and kotlin. I know there is compability issue with
    kapt
    and
    compose
    and so that it throws
    backend IR
    error. But now in build gradle file i removed below line and it worked.
    buildFeatures {
            compose true
    }
    Now even removing this line I am able to call compose function and load ui. So, what does this line means and its purpose.
    👍 1
    m
    s
    +3
    • 6
    • 18
  • m

    Manuel Wrage

    01/22/2020, 2:21 PM
    We have to mark our classes with a @StableMarker annotated annotation in order to allow the compiler to perform the function skipping transformations. My question is why did you make this feature opt-in? We either have to annotate every class we use in compose with one of the annotations or we don't get the optimizations. Are there any plans to improve or change that behavior?
    j
    c
    • 3
    • 2
  • j

    jetzajac

    01/25/2020, 4:51 PM
    That is interesting. As it can often be the case that computation itself is cheaper than the args comparison. Doesn’t it make sense to opt-in for such behavior rather than having it as default?
    r
    • 2
    • 1
  • k

    Klaas Kabini

    01/26/2020, 10:21 AM
    Is there a simpler way to apply transformations such as rotate, scale, alpha and translate on composable in compose?
    i
    • 2
    • 2
  • c

    carbaj0

    01/26/2020, 4:33 PM
    how is the way to call a composable inside an onClick?
    a
    • 2
    • 2
  • c

    carbaj0

    01/26/2020, 4:33 PM
    FloatingActionButton(
        text = "aa",
        elevation = 7.dp,
        textStyle = (+typography()).body1.copy(color = Color.White),
        onClick = { Snackbar(text = "dsaf") }
    )
    java.lang.IllegalStateException: Composition requires an active composition context
    b
    a
    +2
    • 5
    • 15
  • k

    Klaas Kabini

    01/27/2020, 5:46 AM
    When the ripple animation is bounded, it works fine on a rectangular shape but does not respect the bounds of a circular shape. In the short clip attached, you can see the animation respect the bounds on the list item not matter where you click or tap on the list item but with circular shape it is the opposite. Why is that so? Shouldn't the ripple behave the same with all shapes?
    ripple.webm
    a
    • 2
    • 3
  • a

    amar_1995

    01/27/2020, 11:21 AM
    I am trying to retrive data from server(using retrofit). I am retrieving this data on
    IO
    thread. But as, I use this in below code, It will throw eroor
    Not in a frame
    fun<T> observer(data: LiveData<T>) = effectOf<T?> {
        var result = +state<T?> { data.value }
        val observer = +memo { Observer<T> { result.value = it }}
    
            +onCommit(data) {
                data.observeForever(observer)
                onDispose { data.removeObserver(observer) }
            }
    //        commit()
    
        result.value
    
    }
    z
    b
    +2
    • 5
    • 19
  • n

    Nikita Prokopov

    01/27/2020, 1:24 PM
    Hi! I have a pretty basic application. Basically it shuffles a list of ~150 strings. I’m concerned with performance. Recompose alone takes ~50ms each time. Full rendering is ~100-120ms / per shuffle. I realize this is a worst case for Compose (fully reshuffling 150 elements). Anything ideas how to improve performance? Code https://gist.github.com/tonsky/bca64aeb0c0e79151c39dd0e5a508d22
    l
    z
    +2
    • 5
    • 18
  • c

    carbaj0

    01/27/2020, 2:58 PM
    +imageResource(R.drawable.ic_arrow_core_lines_white)
    do Compose support vectors?
    g
    a
    • 3
    • 9
  • m

    marstran

    01/27/2020, 9:55 PM
    Hi, I’m trying out Compose for the first time. I got a little stuck on the first tutorial where I’m supposed to draw an image with
    DrawImage
    . But I cannot seem to import the
    DrawImage
    function. Do anyone know what I might be doing wrong?
    c
    • 2
    • 3
  • a

    amar_1995

    01/28/2020, 2:10 PM
    I am trying to use VerticalScroller but it is not working properly. Whole ui lags
    @Composable
    private fun ShowArticle(
        articleList: List<NewsArticle>
    ) {
        val scrollerPosition: ScrollerPosition = +memo {ScrollerPosition(0f)}
        if(scrollerPosition.isAtEndOfList) {
            newArticleModel.loadMoreNationData(2)
        }
        VerticalScroller(scrollerPosition = scrollerPosition) {
            Column(Expanded) {
                articleList.forEach {
                    ArticleTicket(
                        backgroundColor = (+MaterialTheme.colors()).background,
                        article = it
                    )
                }
            }
        }
    }
    val ScrollerPosition.isAtEndOfList: Boolean get() = value >= maxPosition
    m
    c
    +2
    • 5
    • 13
Powered by Linen
Title
a

amar_1995

01/28/2020, 2:10 PM
I am trying to use VerticalScroller but it is not working properly. Whole ui lags
@Composable
private fun ShowArticle(
    articleList: List<NewsArticle>
) {
    val scrollerPosition: ScrollerPosition = +memo {ScrollerPosition(0f)}
    if(scrollerPosition.isAtEndOfList) {
        newArticleModel.loadMoreNationData(2)
    }
    VerticalScroller(scrollerPosition = scrollerPosition) {
        Column(Expanded) {
            articleList.forEach {
                ArticleTicket(
                    backgroundColor = (+MaterialTheme.colors()).background,
                    article = it
                )
            }
        }
    }
}
val ScrollerPosition.isAtEndOfList: Boolean get() = value >= maxPosition
I am loading data as verticalscroller reaches its end..
m

Manuel Wrage

01/28/2020, 2:12 PM
Try to wrap the "isAtTheEndOfList" if statement inside a Observe { ... }
Because you reading the scrollPosition.value the whole list is recomposed any time you scroll. By wrapping the code in a Observe it will only recompose the code inside it.
👍 1
a

amar_1995

01/28/2020, 2:23 PM
val observe  = Observer<Boolean> {
    if (it) {
        newArticleModel.loadMoreNationData(2)
    }
}
observe.onChanged(scrollerPosition.isAtEndOfList)
Like this ?
m

Manuel Wrage

01/28/2020, 2:23 PM
No i mean androidx.compose.Observe
androidx.compose.Observe {
    if(scrollerPosition.isAtEndOfList) {
        newArticleModel.loadMoreNationData(2)
    }
}
Like this
👍 3
a

amar_1995

01/28/2020, 2:27 PM
Yeah thanks
Now, It is working fine
m

Manuel Wrage

01/28/2020, 2:27 PM
Great:)
c

Chuck Jazdzewski [G]

01/28/2020, 11:11 PM
As the above discussion shows
Observe
is a confusing name. Any recommendations for renaming it?
v

Val Salamakha

01/29/2020, 5:01 AM
It’s better to name the component Observe as BodyScope as it “creates a scope which will be the root of recomposition for any reads or writes to Model classes that happen inside of it.
m

Manuel Wrage

01/29/2020, 10:16 AM
I think Observe is ok. The problem is that we have to get used to the fact that each composable lambda without a return type is a scope which can be invoked when ever something has changed.
k

Klaas Kabini

02/12/2020, 4:18 AM
I had a similar problem and this thread helped me in solving it.
View count: 1