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

    Rosen Dimov

    08/17/2020, 8:12 AM
    Hello everyone! First of all, I'd like to thank and salute you for your efforts in modernizing the Android SDK! It really looks way better with compose. I'm a web developer using React in my daily routines and I'm currently learning mobile development, right now playing with the Android SDK. So applying programming styles from React in Android really appeals to me. I have a few questions for you, guys: 1 - What is the state of compose in terms of performance (more specifically list-displaying composables)? I tried using
    LazyColumnFor
    , because I wanted to migrate an adapter which has two view types (both written in constraint layout). I migrated the XML definition of the CL to the equivalent
    ConstraintLayout
    composable, using
    createRefs
    for describing constraints, and
    start.linkTo
    ,
    top.linkTo
    , etc. (part of 0.1.0-dev16 version). Scrolling was very slow, compared to the adapter approach where things are smooth. Here's a gist of the composable. Here's some relevant code: The activity which sets the root composable (the list) - grabs first a bunch of data from a Firestore and calls
    setContent
    The list, based on LazyColumnFor The repeating item - with ConstraintLayout, and with Row and Column RoundedImage composable - a simple card view with circle shape The customized button 2 - Have you considered taking an approach similar to JSX in React, something like files with both Kotlin code and some sort of markup for definition of the view itself. Seems like the main drawback of the composables is the nesting of objects that happens in code, and to me at least, it seems more natural to express certain hierarchy of components through a markup language (don't get me wrong, moving to composables in their current state is already a big step, just my thoughts as React dev 😉 ) 3 - For beginners like me, is it worth diving deep into things like activities, fragments, navigation in its stable state, lifecycles of fragments/activities, different kind of layouts, etc.? I'll probably not be working on professional Android projects (if I decide to take up mobile dev in my work) by the time stable version of compose is released (in the beginning of 2021, from what I know). Thanks and have a great day! 🙂
    c
    m
    +3
    • 6
    • 27
  • y

    Yamila Gammeri

    08/17/2020, 8:47 AM
    Hey was wondering how do you handle scrolling when typing into a text field using the keyboard?
    a
    • 2
    • 5
  • j

    Julius Marozas

    08/17/2020, 9:49 AM
    Can I set a custom key (instead of element index) in
    LazyColumnFor
    composable?
    z
    • 2
    • 8
  • p

    Philip Blandford

    08/17/2020, 11:10 AM
    Is there a way to specify the scroll position of a LazyColumnFor? As far as I can see, all the scroll state is hidden away in private functions.
    h
    z
    • 3
    • 4
  • m

    mattinger

    08/17/2020, 6:08 PM
    Hi all. I’m curious how one would properly implement composables based on screen width/height selectors.
    j
    t
    • 3
    • 3
  • m

    mattinger

    08/17/2020, 7:55 PM
    Anyone know if AdapterList uses RecylerView? And if it does, how does it distinguish between the different row types? It seems like it would be very hard for it to do that.
    z
    v
    • 3
    • 4
  • c

    Colton Idle

    08/17/2020, 7:55 PM
    Not sure if this is something compose can help with, but going off of the question asked yesterday "Hi, is it possible to implement edge-to-edge by compose atm?" I just want to say that I hope implementing e2e with compose is a bit easier. Right now having to inset every one of my recyclerviews on each screen is annoying and clipToPadding = false, etc, but having apps that go off of @cb presentation where he said drawing under nav and status bar is recommended strongly it would be nice if this was like a first class thing.
    c
    • 2
    • 2
  • a

    amar_1995

    08/17/2020, 8:07 PM
    What is a difference between
    var expanded by state { sieveData.first }
    var expanded by remember { state { sieveData.first } }
    I have seen in some project using the later one
    r
    z
    • 3
    • 4
  • g

    Guy Bieber

    08/17/2020, 8:45 PM
    So I am making the jump from dev11 to dev16 and taking on the model change. Previously I had a reusable view class that took in state (@Model) at construction. The the composable functions all used that state. In this way I can inject the bit of app state that a view needs to know about into each view.
    class LoginView(
        private var dataModel : LoginDataModel
    )  : Component () 
    
    ...
    
        @Composable
        override fun view () {
            BottomDrawerLayout(
                drawerState = dataModel.drawerState,
    
                gesturesEnabled = true,
                drawerContent = {
                    drawerView()
                },
                bodyContent = {
                    baseView()
                }
            )
        }
    My application model was all defined in one library with @Model. Now I am trying to move to the recommended porting described in dev12:
    class Position(x: Int, y: Int) {
     var x by mutableStateOf(x)
     var y by mutableStateOf(y)
    }
    
    // source of Example is identical to original
    @Composable fun Example() {
     var p = remember { Position(0, 0) }
     PositionChanger(
       position=p,
       onXChange={ p.x = it }
       onYChange={ p.y = it }
     )
    }
    However, if you look at mutableStateOf it says you should use state and stateOf instead. Then there is a bunch of talk of snapshots. This all leaves me scratching my head wondering how I create a reusable view that can be injected with state. Any good examples, explanations, or other help out there?
    v
    • 2
    • 34
  • d

    Daniele B

    08/17/2020, 10:22 PM
    I get a strange error with 0.1.0-dev16@aar I guess I updated my Android Studio to the newest Kotlin compiler and it doesn’t work with Compose anymore?
    v
    • 2
    • 3
  • m

    mattinger

    08/17/2020, 11:42 PM
    Anyone know if imageResource is broken in dev14?
    v
    • 2
    • 2
  • h

    Halil Ozercan

    08/18/2020, 5:20 PM
    Is next(dev17) release going to use kotlin 1.4 release version?
    a
    j
    l
    • 4
    • 7
  • r

    Ricardo C.

    08/18/2020, 8:33 PM
    I've been playing around with the new NavHost. But I'm wondering: if it completely replaces the composable, how are we gonna keep the scroll position 🤔 Right now it seems to lose it. I'm also not sure about passing arguments. The api doesn't seem to support it?
    z
    i
    +2
    • 5
    • 21
  • g

    Guy Bieber

    08/18/2020, 10:58 PM
    I want to animate a power bar, by changing the width of an image. The crop that is part of Image maintains aspect ratio. I want to keep the height the same and very the width. Any ideas.
    z
    n
    d
    • 4
    • 11
  • m

    Marcin Środa

    08/19/2020, 7:21 AM
    Has any change regarding InputField focus been made in the last version? Looks like ImeAction.Next isn’t working anymore.
    👍 1
    a
    • 2
    • 2
  • m

    Marcin Środa

    08/19/2020, 7:24 AM
    Btw, found some weird issue today. It occurs almost every time (except for the first build after clean).
    j
    • 2
    • 5
  • t

    tcracknell

    08/19/2020, 5:25 PM
    Hello! As Jens already noticed, the latest Jetpack Compose minor release, dev17, has just been released! You can get it now on Google’s Maven Repository. Release notes are available at https://developer.android.com/jetpack/androidx/versions/all-channel. As always, feedback is welcome; please log issues at https://issuetracker.google.com/issues/new?component=612128.
    👏 2
    🎉 30
    j
    • 2
    • 2
  • c

    chris

    08/19/2020, 6:36 PM
    From a dependency standpoint, what are the top libraries for compose that I can put in my Gradle file that will resolve all the libraries needed to work with compose?
    z
    t
    • 3
    • 4
  • g

    Guy Bieber

    08/19/2020, 6:58 PM
    Interface functions with default values seem to be ignored if the functions are marked @Compose. This breaks a lot of code. Anyone had this problem on the latest android studio canary, kotlin 1.4, and compose dev16?
    m
    j
    l
    • 4
    • 13
  • g

    Guy Bieber

    08/19/2020, 7:49 PM
    Moving to dev17 I used to draw a RadialGadient with:
    @Composable 
        override fun GradiantScreen() {
            var colors = listOf<Color>(nikolaColors.color2,
                nikolaColors.color1)
            var gradientBrush = RadialGradient(
                colors = colors,
                centerX = getScreenWidth().toFloat() / 2.0f,
                centerY = getScreenHeight().toFloat() / 2.0f,
                radius = getScreenHeight().toFloat() / 2.0f,
                tileMode = TileMode.Clamp
            )
    
            Box(
                Modifier
                    .drawBackground(brush = gradientBrush)
                    .fillMaxSize()
            )
        }
    Unfortunately, drawBackground has been deprecated. What is the recommended way to do this with dev17?
    m
    z
    • 3
    • 3
  • p

    popalay

    08/20/2020, 5:53 AM
    Hey. In dev17 CoroutineContextAmbient has gone. What is the replacement?
    a
    z
    • 3
    • 2
  • w

    William Barbosa

    08/20/2020, 9:24 AM
    Our app is pretty happy about dev17 😂

    https://user-images.githubusercontent.com/535613/90730646-c2566580-e2c8-11ea-8af1-7aeb1556a860.gif▾

    😂 27
    🎉 5
    m
    l
    • 3
    • 4
  • t

    Theo

    08/20/2020, 10:42 AM
    is there an easier way of going through and replacing all the module name changes? some packages I have no idea which package a component is supposed to come from
    a
    • 2
    • 3
  • d

    Daniele B

    08/20/2020, 3:15 PM
    Any idea what’s wrong with this?
    v
    z
    +2
    • 5
    • 9
  • g

    Guy Bieber

    08/20/2020, 5:52 PM
    Idea. It would be nice to have a lint check or a way to designate that compose function is expected to start with a row or column.
    r
    a
    • 3
    • 4
  • a

    amar_1995

    08/20/2020, 6:45 PM
    I am using `avedInstanceState`in dev14 but getting this error
    cannot be saved using the current UiSavedInstanceStateRegistry. The default implementation only supports types which can be stored inside the Bundle. Please consider implementing a custom Saver for this class and pass it to savedInstanceState() or rememberSavedInstanceState()
    z
    f
    • 3
    • 20
  • f

    farzad

    08/20/2020, 8:21 PM
    How can I close drawer on back pressed?
    :stackoverflow: 2
    :google: 2
    h
    • 2
    • 1
  • m

    Mohamed Elfiky

    08/21/2020, 9:00 AM
    i am trying to use animateContentSize but i think i am doing it wrong
    LazyColumn(modifier = Modifier.fillMaxWidth()) {
        items((0..30).toList()) {
            var isExpanded by remember { mutableStateOf(false) }
            Surface(
                color = MaterialTheme.colors.primary,
                shape = CircleShape
            ) {
                Row(modifier = Modifier.animateContentSize()) {
                    IconButton(onClick = { isExpanded = !isExpanded }) {
                        Icon(asset = Icons.Default.AccessTime, tint = Color.White)
                    }
    
                    if (isExpanded) {
                        Text(
                            modifier = Modifier.gravity(Alignment.CenterVertically)
                                .padding(end = 16.dp),
                            text = "some text",
                            style = MaterialTheme.typography.caption,
                            color = Color.White
                        )
                    }
                }
            }
            Spacer(modifier = Modifier.height(8.dp))
        }
    }
    this code make the icons disappear on scrolling and is very lag, but when i put the animateContentSize on the surface it works but the animation is not like the above one. this code is put in another compose but i extract it to see the problem.
    z
    d
    • 3
    • 15
  • h

    Halil Ozercan

    08/21/2020, 12:36 PM
    What is the latest recommended way of loading images in lazy lists? edit: Both from resources and URL
    v
    • 2
    • 3
  • m

    Mehdi Haghgoo

    08/21/2020, 1:00 PM
    What is the difference between
    var count = remember {mutableStateOf(0)}
    and
    var count by state {0}
    ?
    m
    • 2
    • 2
Powered by Linen
Title
m

Mehdi Haghgoo

08/21/2020, 1:00 PM
What is the difference between
var count = remember {mutableStateOf(0)}
and
var count by state {0}
?
m

Mohamed Elfiky

08/21/2020, 1:05 PM
https://kotlinlang.slack.com/archives/CJLTWPH7S/p1597694859239400?thread_ts=1597694859.239400&amp;cid=CJLTWPH7S
m

Mehdi Haghgoo

08/21/2020, 1:07 PM
Thanks @Mohamed Elfiky. So , state{} is going away. This is the pros and cons of playing on the bleeding edge of Compose 😂
View count: 1