https://kotlinlang.org logo
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
  • l

    Lilly

    02/20/2021, 4:33 PM
    @Arkadii Ivanov has covered a pure compose navigation example by using
    Decompose
    in one of his recent blog posts. I was interested in decompose and had a look into this example but I can't figure out how it's restoring the scroll position of the
    LazyColumn
    when moving from the details screen back to the list screen. I'm looking for hours but I can't find the responsible piece of code. Can some please have a look and give me a hint? https://github.com/arkivanov/ComposeNavigatorExample
    a
    a
    • 3
    • 7
  • v

    Vivek Sharma

    02/20/2021, 5:34 PM
    I am having two `Text()`composable in a
    column
    , can I control the vertical spacing between them, is there a way
    z
    • 2
    • 6
  • k

    kevindmoore

    02/20/2021, 5:50 PM
    I’m trying to create a Kotlin Multiplatform Compose app and having all kinds of build problems. Is there an example I can start with? Not sure if it is due to the latest alpha
    a
    • 2
    • 1
  • m

    mzgreen

    02/20/2021, 7:31 PM
    https://twitter.com/AndroidDev/status/1363207926580711430?s=19 Does this language have a name? Is it Koxml? 😀
    👍 1
    🙌 1
    j
    c
    +3
    • 6
    • 8
  • h

    Halil Ozercan

    02/20/2021, 11:38 PM
    would it be possible that passing instances whose source code is in java confuse the composition? even when those parameters are wrapped with a kotlin class? I have a setup which includes an AndroidView where it is very easy reproduce that java and kotlin classes behave differently.
    • 1
    • 2
  • s

    Slackbot

    02/21/2021, 1:41 AM
    This message was deleted.
    a
    r
    y
    • 4
    • 3
  • a

    Adriano Celentano

    02/21/2021, 9:52 AM
    Im animating my sine curve indefinetly horizontaly, any better ideas how to do it ?
    LaunchedEffect(key1 = Unit, block = {
        while (isActive) {
            delay(50)
            horizontalAnimation.value = horizontalAnimation.value + 2.dp
        }
    })
    Screen Recording 2021-02-21 at 10.47.58.mov
    a
    j
    d
    • 4
    • 11
  • s

    Shakil Karim

    02/21/2021, 10:10 AM
    Is it expected Behavior to recompose the items of LazyColumn on each scroll event ? I was try to log the composition count
    LazyColumn(
        state = scrollState,
        modifier = Modifier.fillMaxSize()
    ) {
        item {
            LogCompositions("CompetitionDetailsScreenNew header")
             //Some item
         }
    }
    a
    • 2
    • 7
  • e

    Emmanuel Oga

    02/21/2021, 10:51 AM
    Is this a good channel for Skija / Skiko questions? Is there a more specific one? Should there be one? 🙂
    l
    j
    • 3
    • 4
  • o

    orangy

    02/21/2021, 1:35 PM
    I have
    LazyVerticalGrid
    with
    itemsIndexed
    over a property which is
    mutableStateListOf
    . Everything is working fine when I add items, but when I remove items via
    remove
    or
    clear
    on that list I get an exception trying to access non-existing items. It’s a call from inside the
    itemsIndexed
    , looks like it didn’t notice collection has changed. Is it a known issue or am I doing something wrong?
    d
    a
    l
    • 4
    • 14
  • s

    Samir Basnet

    02/21/2021, 3:17 PM
    Well as much exited as i am for jetpack compose i am still worried about the Preview in Android Studio. It is in no way what i would consider usable . Takes forever just to show a simple Text composable . Can't imagine how slow it would be when need to preview complex composables. If we take current xml preview speed as 10 then compose preview is around 3. It's like no matter how productive jetpack compose is Android Studio drags it down
    👌 1
    ➕ 7
    s
    • 2
    • 2
  • o

    orangy

    02/21/2021, 3:37 PM
    I still kinda lost in implementing a grid which would have fixed size of cells (like, square), and will fit as much cells on a single row as possible, and then go to next row. Lazy, scrollable, etc just like
    LazyVerticalGrid
    . I would prefer to have
    GridCells
    variant like
    FixedSize(32.dp, 40.dp)
    out of the box, but there is none. Can anyone give me a clue, please?
    • 1
    • 4
  • r

    robnik

    02/21/2021, 4:32 PM
    Has everyone set the Kotlin plugin channel to early access preview? When I updated to Compose alpha12 I had to do that (I think). My Android Studio is now a disaster. Autocomplete fails, or the suggestion popup disappears immediately so it's unusable. Some files can't open, or hang on "Loading..." or "Analyzing..." while pegging CPU. I can't get work done.
    d
    l
    j
    • 4
    • 5
  • s

    Se7eN

    02/21/2021, 6:29 PM
    I have a sealed class
    CanvasElement
    and two subclasses
    CanvasElement.Text
    and
    CanvasElement.Image
    . Then I have a list like
    val elements = mutableStateListOf<CanvasElement>()
    . How can I recompose my composables when I change an element in my list to the same element but a different property which is only present in
    CanvasElement.Text
    and
    CanvasElement.Image
    and not in
    CanvasElement
    . Something like this:
    sealed class CanvasElement(open val id: String, open val position: Offset) {
        data class Text(val size: Float, override val position: Offset, open val id: String): CanvasElement(id, position)
        data class Image(val size: IntSize, override val position: Offset, open val id: String): CanvasElement(id, position)
    }
    
    val elements = mutableStateListOf<CanvasElement>()
    
    fun modifyElement(id: String, newElement) {
        // find index of id
        ...
        elements[index] = newElement
    }
    Then if I modify one of my text elements by changing its size, I want my Text composable to recompose:
    modifyElement((myElement as CanvasElement.Text).copy(size = newSize))
    
    @Composable
    fun Element(element: CanvasElement) {
        when(element) {
            is CanvasElement.Text -> Text("text", size = element.size) // does not recompose when size changes
            is CanvasElement.Image -> ... // does not recompose when size changes
        }
    }
    But the recomposition isn't happening and the text size stays the same. Is it not possible? Do I have to keep separate lists for
    CanvasElement.Text
    and
    CanvasElement.Image
    ?
    v
    • 2
    • 2
  • c

    Chachako

    02/21/2021, 6:47 PM
    Currently, I have created a compose-blur library to solve the same needs as https://issuetracker.google.com/issues/166927547. Now that I have finished the rendering of the static content, I am going to implement real-time blur, but I currently have some problem: 1. I want to know how to take screenshots of some widgets in compose, or their nodes, similar to the
    findRenderObject().toImage()
    in flutter, I really hope this exists, because the performance cost of cropping the widget area after using
    PixelCopy
    to screenshot the entire window view may be expensive. 2. I'm not sure if there is an api on compose that can monitor the changes of all components, similar to the native
    View.doOnPreDraw
    , if it does not exist, then I will try to refresh the blur by monitoring the changes of window view, but if it is invalid for compose, Then I may need to refresh every 100ms, which would be terrible!
    r
    s
    • 3
    • 9
  • o

    orangy

    02/21/2021, 6:53 PM
    I need to have a badge-like component that basically shows a number inside a circle. I’m trying to center number vertically inside a circle, but it always slightly higher than needed. If I add black background to the
    Text
    it has some space below the number. The text rectangle is centered, but not the text itself. How do I fix it?
    j
    a
    +3
    • 6
    • 23
  • b

    bruno.aybar

    02/21/2021, 8:54 PM
    Hello. On the old Transition API,
    transition
    s had
    onStateChangeFinished
    callback. Does anyone know if there's a similar callback on the new API?
    z
    d
    • 3
    • 9
  • l

    Lukas K-G

    02/21/2021, 9:12 PM
    Beginners question here: When do I use
    ViewModel
    and
    LiveData
    and when should I use
    mutableStateOf
    ?
    ➕ 1
    c
    z
    • 3
    • 8
  • j

    Jason Inbody

    02/21/2021, 9:43 PM
    I've just started learning Compose (like an hour ago). I'm trying to create a google map view from the crane demo app (https://github.com/android/compose-samples/blob/23fef0091a7f952516fcbd489c84760892[…]ain/java/androidx/compose/samples/crane/details/MapViewUtils.kt) and I'm trying to take out the mapview section out of the code and put it into my app. I'm getting an import error for LocalContext and LocalLifecycleOwner.
    import androidx.compose.ui.platform.LocalContext
    import androidx.compose.ui.platform.LocalLifecycleOwner
    Not getting much from google were these renamed possibly? Or do i need to add a dep somewhere
    k
    • 2
    • 17
  • k

    krzysztof

    02/21/2021, 10:16 PM
    Is there a way to do some kind of absolute positioning? I’d like to draw content over other content conditionally, but I could use some tips on how to do so
    k
    r
    a
    • 4
    • 6
  • c

    Chachako

    02/22/2021, 3:13 AM
    Hi, I would like to know if there is an api in current compose that can capture the current composable as a bitmap 🤨? I need to capture the content of the widget separately to present some effects.I have seen that compose is rendered by a LayoutNode tree, so can we get a node content publicly? Although this is a bit against the principles of declarative programming... but it does require
    👀 1
    z
    • 2
    • 4
  • j

    Jason Ankers

    02/22/2021, 4:28 AM
    Referencing my navController inside a
    LazyColumn
    seems to cause an infinite recompose loop. Anyone know why this might be happening?
    i
    a
    • 3
    • 6
  • c

    Chachako

    02/22/2021, 7:39 AM
    I am confused about when to call
    remember
    . Should I wrap
    remember
    in all object initialization places?
    h
    z
    s
    • 4
    • 10
  • y

    Yuri Drigin

    02/22/2021, 11:56 AM
    Is it possible to use different Themes inside NavHost? I try to apply new theme in the
    composable
    but it doesn’t work
    • 1
    • 1
  • m

    Maciej Pigulski

    02/22/2021, 2:41 PM
    Is it just me or
    Column(modifier = Modifier.fillMaxSize())
    is overriding background set in
    Colors(..., background = Color.Red, ...)
    for the Material Theme. Not sure if it is strictly
    Column
    releated but if I remove it from the view hierarchy I am able to see
    Color.Red
    as the background.
    Column
    that I am removing has no background of its own. I fail to pinpoint if there is some material color that is taken by default for
    Column
    background. I have checked the source code and couldn't find any defaults taken f.e. from
    colorPrimary
    or else. Now I see it as a bug but maybe I got something wrong..
    b
    • 2
    • 7
  • i

    itnoles

    02/22/2021, 3:27 PM
    I am trying to put two text on the right side. Here is a code for it Click Here
    k
    • 2
    • 11
  • j

    jaqxues

    02/22/2021, 4:26 PM
    How would you ideally represent an observable list of data, where each element also has a state that can be updated. In case a single element updates its state, the list state should ideally not be updated to avoid unnecessary recomposition, etc I suppose you can do better than a
    mutableStateListOf<StateFlow<StateFulData>>()
    or similar?
    o
    • 2
    • 25
  • s

    Simone Summo

    02/22/2021, 4:32 PM
    I am trying to follow the Android Developer’s guide on Navigating with Compose but it suggest to use
    navController.navigate("yourDirection")
    to navigate from a composable to another and my version of
    navigate
    don’t provide the right implementation. I am using
    androidx.navigation:navigation-compose:1.0.0-alpha06
    ➕ 1
    j
    i
    • 3
    • 5
  • a

    Ayomide

    02/22/2021, 5:24 PM
    Is it possible to give a
    TextDecoration
    a separate colour from the text being decorated? TextDecoration
    s
    • 2
    • 5
  • e

    escodro

    02/22/2021, 6:05 PM
    Hello, eveyone! I’m new to declarative UI and I have a question. 😅 Is there a recommended way in compose to handle complex interactions in a screen? Today my code is something like this and may increase in the future. My first idea is to encapsulate all the high-order functions in a
    TaskDetailActions
    and pass the object instead of all the params. Is there a better/more recommended solution? Thanks a lot in advance! 😊
    ➕ 1
    a
    l
    t
    • 4
    • 7
Powered by Linen
Title
e

escodro

02/22/2021, 6:05 PM
Hello, eveyone! I’m new to declarative UI and I have a question. 😅 Is there a recommended way in compose to handle complex interactions in a screen? Today my code is something like this and may increase in the future. My first idea is to encapsulate all the high-order functions in a
TaskDetailActions
and pass the object instead of all the params. Is there a better/more recommended solution? Thanks a lot in advance! 😊
➕ 1
Basically I’m doing this to avoid passing the
ViewModels
to the components below.
a

Ali Albaali

02/22/2021, 6:10 PM
You can try to pass an arbitrary composable content
content: @Composable () -> Unit
as mentioned in this

video▾

(9:06) by Leland.
🙌 1
l

lewis

02/22/2021, 6:12 PM
I've found that once you start taking Previews seriously, the pattern is somewhat emergent. The screenshot you've shown is pretty typical in my projects.
e

escodro

02/22/2021, 6:12 PM
Well, in my understand I use this type of composable when I want to delegate the composition for another function, right?
The functions in the given TaskDetailRouter are high-order functions that delegate some ViewModel operation for the composable above without passing the ViewModel. They are not related to “how to compose the screen”.
t

Tash

02/22/2021, 10:06 PM
yeah, having individual lambdas for every event/action quickly becomes unscalable. creating a sealed class such as your example of
TaskDetailActions
for the context of your component would be a better replacement for individual event lambdas
👍 1
also, depending on the relationship between the two states you’re passing, you could create a higher level state for your component, so you might end up with just:
fun TaskDetailRouter(state: TaskDetailRouterState, onAction: (TaskDetailRouterAction) -> Unit) { ... }
👍 1
View count: 1