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

    lib

    03/20/2021, 8:05 AM
    how to create a nested graph in navigation?
    n
    b
    3 replies · 3 participants
  • r

    Rafs

    03/20/2021, 8:38 AM
    Is there a way to use stickyHeaders with paging in LazyRow/Columns? Without paging, i can just group the data based on a common property and show a sticky header for each grouped data.
    c
    6 replies · 2 participants
  • c

    Colton Idle

    03/20/2021, 12:29 PM
    Anyone have any ideas why my icon is always black and not Red?
    val collapsedPathData = "M 12 13.17 L 7.41 8.59 L 6 10 L 12 16 L 18 10 L 16.59 8.59 L 12 13.17"
        val collapsedPathNodes = remember { addPathNodes(collapsedPathData) }
        Icon(
            contentDescription = "",
            painter = rememberVectorPainter(24.dp, 24.dp, 24f, 24f,) { _, _ ->
                Path(pathData = collapsedPathNodes, fill = SolidColor(Color.Red),) }
        )
    s
    4 replies · 2 participants
  • s

    smallshen

    03/20/2021, 12:38 PM
    Anyone have idea how to enable window transparency in compose desktop?
    t
    1 reply · 2 participants
  • n

    Namig Tahmazli

    03/20/2021, 3:18 PM
    Hi everyone. I am issuing one funky stuff with State and LazyColumn. Basically updating list item does not make the UI update right away but only after scrolling.
    @Composable
    fun Test() {
      var items by remember {
        mutableStateOf(
          mutableListOf(
            1,
            2,
            3,
          )
        )
      }
    
      LazyColumn {
        items(items) {
          Box(
            modifier = Modifier
              .fillMaxWidth()
              .height(100.dp)
              .clickable {
                val list = items
                list[0] = 6
                items = list // this does not make the list to recompose
                items = mutableListOf(6,2,3) // this does not work either
                items = mutableListOf(6,3,2) // this makes the list to recompose
              },
            contentAlignment = Alignment.Center,
          ) {
            Text(text = it.toString(), fontSize = 50.sp)
          }
        }
      }
    }
    If you know why or got an idea please let me know. P.S. Compose version is
    1.0.0-beta02
    a
    a
    5 replies · 3 participants
  • d

    Deepak Gahlot

    03/20/2021, 4:11 PM
    Hi All, Facing a crash while using Navigation in Compose
    java.lang.IllegalStateException: ViewModelStore should be set before setGraph call
    i
    2 replies · 2 participants
  • v

    Vsevolod Ganin

    03/20/2021, 4:29 PM
    Should we use
    SideEffect
    for atomicity on operation on local state? The doc is a bit unclear:
    SideEffect can be used to apply side effects to objects managed by the composition that are not backed by snapshots so as not to leave those objects in an inconsistent state if the current composition operation fails.
    So this applies also to snapshot-backed objects when we need to make atomic change on them, right?
    a
    6 replies · 2 participants
  • n

    Ngenge Senior

    03/20/2021, 6:37 PM
    Hello all. I have two fragments and each fragment hosts a composable. I have a Composable defined as seen below
    c
    s
    9 replies · 3 participants
  • s

    Stanley Gomes

    03/20/2021, 6:37 PM
    Good day everyone. I’m just playing around with compose and was hoping to get some help with animations. Specifically animating between two composables when state has changed. I’m trying to animate using two
    AnimatedVisibility
    composables like here to slide in/out the composables My issue is that only the top
    AnimatedVisibility
    plays the animation. I would like to play them both in parallel so it looks like a seamless sliding in and out transition like a viewPager. Thanks!
    c
    d
    9 replies · 3 participants
  • a

    Adam Powell

    03/20/2021, 6:44 PM
    Hey folks, we're up to over 3,600 people in this channel! If you would like to post a code snippet or stack trace longer than 4-6 lines, please post a quick description in the main channel here and then post the snippet as a threaded reply to yourself. :thread-please: This helps everyone have their messages seen.
    ➕ 8
    ☝️ 9
    👍🏼 2
    👍 31
    t
    1 reply · 2 participants
  • c

    Colton Idle

    03/20/2021, 7:02 PM
    Is there any way to "slow down" animation in compose? I'm trying to slow down my AnimatedVisibility composable with the 3 scale options available in dev options but none of them seem to affect it.
    s
    v
    +2
    5 replies · 5 participants
  • n

    Nat Strangerweather

    03/20/2021, 9:45 PM
    Hi again guys, this is partly a Compose question which is why I am posting here, hoping for the best. Please see details in 🧵
    t
    d
    6 replies · 3 participants
  • t

    Tash

    03/21/2021, 3:36 AM
    Compose integration question: for teams that use static analysis tools like detekt, etc the introduction of Compose and it’s conventions might violate a lot of rules that come with “vanilla” Kotlin programming, such as long parameter lists, “magic number”s in
    dp
    declarations, top level constants named in PascalCase etc., that we see used in the Compose source code. Is Compose declarative-tree style programming heralding a new set of coding styles/conventions for Kotlin? Wondering if anyone has had to justify “this is how its done in Compose” with regards to style/convention to their coworkers who may not be too familiar with Compose just yet.
    e
    2 replies · 2 participants
  • t

    theapache64

    03/21/2021, 8:03 AM
    Reposting for better reach : https://kotlinlang.slack.com/archives/C01D6HTPATV/p1616312597091600
    t
    2 replies · 2 participants
  • c

    carbaj0

    03/21/2021, 3:21 PM
    is there a way to know the maximum height and maximum width of a Column or (Row)? I just know about BoxWithConstraints
    a
    k
    30 replies · 3 participants
  • c

    Colton Idle

    03/21/2021, 5:18 PM
    I was given a design to basically create a Container (will try to accomplish this via "slot api") that can accept any component but the background of the container should be 50% of the child that it's hosting. So the container still has to be big enough to fit the child... it's just that they want to create this "offset" effect with the color. Brute force solution in thread:
    s
    a
    9 replies · 3 participants
  • s

    Shivam Sethi

    03/21/2021, 8:08 PM
    Please help: I want camerax preview use case to fill the whole size of the screen in compose, I am using a PreviewView in AndroidView and it is not filling the full screen, I tried creating same activity with xml (no compose) and is working as expected ? Or is there a direct way in compose to not use PreviewView() at all to show a preview use case full screen ? In xml I had it
    match_parent
    for height and width not sure how can achieve that here, it just put black screen top and bottom but preview size remains the same if I do 
    Modifier.fillmaxSize()
    j
    n
    +1
    14 replies · 4 participants
  • j

    Jakub Ledwon

    03/21/2021, 9:18 PM
    I encountered pretty weird behaviour while using
    infiniteRepetable
    : I'm using
    tween
    as
    animation
    and while having
    durationMillis < 1000*48
    (48s) everything works perfectly fine, but while trying to animate with
    durationMillis
    greater than 48s (which seems super weird), it justs snaps from
    initialValue
    to
    targetValue
    . Do you have any idea why is it not working correctly? Am i doing something wrong? Here is super simple
    Composable
    that allows to reproduce my problem:
    @Composable
    fun Test() {
        val infTrans = rememberInfiniteTransition()
    
        val value = infTrans.animateFloat(
            initialValue = 0f, targetValue = 1f, animationSpec = infiniteRepeatable(
                animation = tween(1000 * 60, easing = LinearEasing),
            )
        )
    
        Text(value.value.toString())
    }
    d
    r
    5 replies · 3 participants
  • o

    orangy

    03/22/2021, 8:40 AM
    I’m developing a number of components for 9-slices scaling of images, like a button, background, etc. Asking community for a good name for this 🙂 Like how would you name a class that holds ImageBitmap and information about left, top, right and bottom sizes to render it?
    b
    m
    +5
    14 replies · 8 participants
  • s

    Smorg

    03/22/2021, 8:58 AM
    I have a
    LazyVerticalGrid
    in a
    Column
    in a
    ComposeView
    that’s a child of a
    NestedScrollView
    and I am getting this:
    java.lang.IllegalStateException: Nesting scrollable in the same direction layouts like ScrollableContainer and LazyColumn is not allowed.
    ...
    I have seen a couple of this in here as well, but can’t find any that matches the state of my layout. Please how can I fix this?
    a
    c
    +2
    13 replies · 5 participants
  • k

    krzysztof

    03/22/2021, 10:03 AM
    Is there a way to add delay to spring animation spec?
    v
    a
    +1
    6 replies · 4 participants
  • l

    Lukas

    03/22/2021, 11:40 AM
    Hi, small question regarding
    ConstraintLayout
    . How can I prevent the text from getting out of bounds as in the screenshot? Constraining the the textend to
    parent.end
    doesn't seem to work in this case.
    f
    j
    +1
    5 replies · 4 participants
  • c

    Chachako

    03/22/2021, 2:59 PM
    It seems that using
    State
    in
    ViewModel
    is much simpler than
    LiveData
    . Should I use
    MutableState
    in
    ViewModel
    ? Is this correct?
    :yes: 1
    a
    o
    +4
    19 replies · 7 participants
  • c

    Chachako

    03/22/2021, 3:03 PM
    In addition I currently have two interfaces. The first interface has some data, which I have to send when navigating to the next interface. But navigation seems to be unable to pass the object, is my following method correct? If not, what should be the best practice?
    i
    6 replies · 2 participants
  • j

    Jorkoh

    03/22/2021, 3:45 PM
    How can I draw text where the color transparency depends on the y value? Text() doesn't take a Brush so I can't use a vertical gradient
    s
    c
    +3
    18 replies · 6 participants
  • o

    Olivier Patry

    03/22/2021, 5:10 PM
    Do you any materials to better understand how to reach "low level" related to """""view bounds"""""" in the Compose world? I need 2 distinct things • where is the "view" on the Window (I'd like to anchor a dialog to a view) • what is the size of my "view" (≃`View.getMeasuredWidth()` or the value we get from
    View.onSizeChanged()
    ), what is the DPI of the screen where my "view" is (≃`Context.resources.displayMetrics`) → I'm aware there is no such "view" in the 100% Compose world, what I'd like is the have such thing within the layout for the result of a given composable
    h
    a
    16 replies · 3 participants
  • r

    Rick Regan

    03/22/2021, 5:43 PM
    In this example, the selected text and the highlighting fades with the
    Crossfade
    , but the "thumbs" do not (they abruptly disappear when the animation ends). Is there something I need to do differently to get them to fade as well?
    d
    s
    7 replies · 3 participants
  • g

    gagarin55

    03/22/2021, 6:09 PM
    Hello All! Looking for samples without using ViewModel at all. Since we have Desktop now. Thank you
    🎉 3
    a
    3 replies · 2 participants
  • c

    clhols

    03/22/2021, 6:12 PM
    We have Compose composables in a submodule and have issues with the Preview annotation. Why does @Preview need a "androidx.lifecycle.viewmodel.R$id class?
    java.lang.ClassNotFoundException: androidx.lifecycle.viewmodel.R$id
    at com.android.tools.idea.rendering.classloading.RenderClassLoader.getNonProjectClassData(RenderClassLoader.java:218)
    at com.android.tools.idea.rendering.classloading.RenderClassLoader.loadClassFromNonProjectDependency(RenderClassLoader.java:185)
    ...
    at androidx.lifecycle.ViewTreeViewModelStoreOwner.set(ViewTreeViewModelStoreOwner.java:50)
    at androidx.compose.ui.tooling.preview.ComposeViewAdapter.init(ComposeViewAdapter.kt:615)
    :thread-please: 4
    f
    5 replies · 2 participants
  • f

    Francois Morvillier

    03/22/2021, 6:40 PM
    I find that many of the custom components I want to write rely on being able to access the layout positions of child views. Typically, I'll want to select a certain child view (highlight it and make a callback) depending on how much the view was scrolled (for instance selecting the middle child in a carousel selector assuming varying child sizes). I have been able to solve this by writing a custom layout that saves the child positions to a remembered value but it feels like too much work and ideally I'd like to be able to use any existing layout without having to redo it. Is there a better way to access the child layout positions?
    k
    5 replies · 2 participants
Powered by Linen
Title
f

Francois Morvillier

03/22/2021, 6:40 PM
I find that many of the custom components I want to write rely on being able to access the layout positions of child views. Typically, I'll want to select a certain child view (highlight it and make a callback) depending on how much the view was scrolled (for instance selecting the middle child in a carousel selector assuming varying child sizes). I have been able to solve this by writing a custom layout that saves the child positions to a remembered value but it feels like too much work and ideally I'd like to be able to use any existing layout without having to redo it. Is there a better way to access the child layout positions?
k

Kirill Grouchnikov

03/22/2021, 6:57 PM
Where do you want to access that information from? From inside the parent measure pass, or somewhere else?
f

Francois Morvillier

03/22/2021, 7:32 PM
Here's a simplified version of how I'd like to write it:
val scrollState = rememberScrollState()
val selectedIndex = // compute the selected child index using scrollState.value and child layout info
Row(modifier = Modifier.horizontalScroll(scrollState)) {
    // children declarations
    for(i in 1..N) {
         Child(i, selectedIndex)
    }
}
The question is how to I get the layout positions of the children so I can compute selectedIndex?
k

Kirill Grouchnikov

03/22/2021, 10:17 PM
Maybe in this particular case, you don't need the positions of all the child views. If you need to set the selected index based on which child is in the middle, that can be a
State
variable at the parent level which is updated in your measure pass.
It's a bit of a perspective shift to not look at the layout information for this
f

Francois Morvillier

03/22/2021, 11:01 PM
So basically it does require a custom layout? In that case it may indeed be smarter to compute the selected index in the layout measure pass.
View count: 3