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

    Brian G

    10/18/2021, 10:07 PM
    Is it possible to observe scroll offset? This code does not seem to work:
    val state = rememberScrollState()
    LaunchedEffect(state) {
      snapshotFlow { state.value }.collect {
        Log.v(TAG, "$it") // This is never called?
      }
    }
    Box(Modifier.fillMaxSize().verticalScroll(state)) {
       // ... Lot of box contents
    }
    😢 1
    a
    z
    • 3
    • 7
  • t

    Tomasz Krakowiak

    10/18/2021, 10:30 PM
    Is it possible to embed Skika "view" inside compose ande vice-versa? (Also interested in web and desktop)
    c
    z
    • 3
    • 2
  • s

    Scott Kruse

    10/18/2021, 10:37 PM
    Is there a way to specify a source set to be shared between Android + Desktop targets for compose? I also have a compose web target so i cannot support compose foundation / material inside commonMain sourceset
    • 1
    • 3
  • m

    mattinger

    10/19/2021, 12:13 AM
    Does anyone know if it’s even possible to create a Compose rule based test in a library module? I’m not having much luck, and it keeps saying it’s not finding any tests. I would prefer unit tests to androidTest but i don’t that’s really doable either.
    a
    • 2
    • 2
  • t

    Tash

    10/19/2021, 12:16 AM
    I apologize if this has been asked already, but wanted to double check here. what are the effective differences between the two (apart from one being a composable function) ?
    // Using derivedStateOf
    fun nameA(name: String): State<String> {
        return derivedStateOf { "Hello $name" } 
    }
    
    // Using rememberUpdatedState
    @Composable
    fun nameA(name: String): State<String> {
        return rememberUpdatedState("Hello $name")
    }
    m
    a
    a
    • 4
    • 18
  • p

    prudhvi reddy

    10/19/2021, 12:48 AM
    Hey everyone. i am getting this exception when navigating to a
    fragment with ComposeView
    Fatal Exception: java.lang.IllegalStateException 
    ViewTreeLifecycleOwner not found from androidx.constraintlayout.widget.ConstraintLayout{aace22b V.E...... ......ID 0,0-1080,2358 #7f0a114e app:id/root}
    versions used
    fragment - 1.3.1 
    compose - 1.0.2
    i
    • 2
    • 13
  • a

    Arjun Achatz

    10/19/2021, 1:51 AM
    Is it possible to render an AbstractComposeView in Android Studio ? Ex: I have a class
    MyCustomComposeView : AbstractComposeView
    , in the split view, even if a select Custom view, nothing shows up
    i
    e
    • 3
    • 3
  • m

    mingkangpan

    10/19/2021, 8:54 AM
    Guys, I don’t understand how to make a Image with inner padding
    Icon(
                painter = painterResource(id = R.drawable.ic_baseline_delete_24),
                modifier = Modifier.align(Alignment.TopEnd)
                    .size(40.dp)
                    .padding(8.dp)
    )
    Still there is not inner padding applied somehow…
    g
    z
    • 3
    • 10
  • m

    Matti MK

    10/19/2021, 9:16 AM
    Is there a way to animate change in a `Button`s
    ButtonColors
    based on the
    enabled
    property value? I have a button for which I’ve defined the disabled and enabled colors as shown below. How can I animate the color change when the
    enabled
    property changes?
    colors = ButtonDefaults.buttonColors(
                backgroundColor = colors.primaryVariant,
                disabledBackgroundColor = colors.secondaryVariant
            ),
    g
    t
    +2
    • 5
    • 24
  • j

    jannis

    10/19/2021, 9:38 AM
    Is there any elegant way to hide the BottomBar when the keyboard is shown? I'm using the Accompanist Insets library which gives me my desired keyboard behavior, but I want my TextField directly above my keyboard after the user clicked on it.
    👀 1
    c
    c
    • 3
    • 5
  • d

    dimsuz

    10/19/2021, 11:26 AM
    I need to inform the grand-grand-[grand]-parent of LazyRow that scroll is in progress. What is the most idiomatic way to do this? Code in thread.
    a
    • 2
    • 3
  • d

    Daniele Segato

    10/19/2021, 11:51 AM
    Is there some documentation explaining the differences from
    Layout
    and
    SubcomposeLayout
    ? what changes in performances? Why do we need a
    SubcomposeLayout
    for
    BoxWithConstraints
    ? A lot of the time all you want is the size (width / height) of the composable, which you can get with
    Modifier.onSizeChanged {}
    or
    Modifier.onGloballyPositioned {}
    but it is asynchronous: you need to wait for the first composition before you get a callback to that, which means if you need the size of the widget to do something on the UI you'll have a flickering. Can someone give me an in-depth answer or a link with an in-depth answer to these things? What I'm most interest in is what are the drawback of using subcompositions and what are all the options to get the layout constraints / why we need subcomposition to get them before composing (modifiers have access to them). EDIT: for instance
    IntrinsicSize
    stop working if a child has
    BoxWithConstraints
    right? Thanks
    a
    z
    a
    • 4
    • 4
  • n

    Napa Ram

    10/19/2021, 12:16 PM
    HI Team anyone integrated ktlint with compose project ?
    c
    j
    • 3
    • 5
  • a

    Ashu

    10/19/2021, 12:33 PM
    Are preview functions removed from release build by Proguard or R8?
    p
    d
    c
    • 4
    • 5
  • v

    Vivek Sharma

    10/19/2021, 12:35 PM
    Is there something I can use to erase things, like kinda erasing images or text on gesture, do I need Canvas for that?
    d
    • 2
    • 1
  • m

    Marcello Galhardo

    10/19/2021, 1:42 PM
    What is the appropriated way to load a dimension resource as SP? Currently
    dimensionResource
    returns a DP value and it looks like there is no support to SP at all in the docs: https://developer.android.com/jetpack/compose/resources
    f
    • 2
    • 2
  • a

    Anton Shilov

    10/19/2021, 2:31 PM
    Hello folks! Is there a way to get the current progress of
    Transition
    on a more granular level rather than current/target state? I'm trying to use
    Transition.playTimeNanos
    and
    Transition.totalDurationNanos
    . But total duration is calculated only in seek mode, which as I assume is reserved for tooling. cc @Doris Liu
    z
    d
    • 3
    • 4
  • c

    Chris Fillmore

    10/19/2021, 3:58 PM
    Is there a way to make text wrap in a
    BasicTextField
    , while still enforcing
    singleLine
    ? I don’t want newline characters, and I don’t want the user to have to horizontal scroll.
    • 1
    • 1
  • r

    Rick Regan

    10/19/2021, 5:39 PM
    I'm trying to determine the best way to manage changes in UI state when the screen configuration changes. I use the width provided within
    BoxWithConstraints
    to compute the number of a particular UI element that can fit on the screen. Let’s say I want two elements when the width is “portrait” and three when it is “landscape”. These elements display editable state that I want retained across rotations, so that when the third element is rotated off screen and then back on, it displays its old data. (My state is “global”, so I’m not talking about
    rememberSaveable
    .) The composable I've written that detects the rotation puts out the appropriate number of elements and then uses a
    SideEffect
    to tell the state what the number of elements is. This seems backwards, since it’s like the state change is reacting to the UI change. (Another detail that may be relevant: I have a button that “tabs through” the visible elements, so that button’s callback needs to check the state to know what’s on screen.) Now I’m thinking that instead I should use a
    LaunchedEffect
    (with key the number of elements) to update the state and then use the number of elements as recorded in the state (rather than in the local variable as above) to generate the elements. This seems more natural, almost like making configuration change a callback. In any case, I wanted to ask about best practices before I got too far off track. Thanks.
    a
    • 2
    • 14
  • d

    Danish Ansari

    10/19/2021, 7:24 PM
    Since the
    LazyVerticalGrid
    is experimental. Is there any workaround to create grid list using
    LazyColumn
    ?
    a
    v
    • 3
    • 7
  • a

    Aram Sheroyan

    10/19/2021, 11:51 PM
    If I want the text color be different for light and dark mode, should I replace my typography for both modes like it is done for colors, or there is a way to just reference theme's color so it changes automatically? I was thinking that I could do something like this
    @Immutable
    data class CustomTypography(
        val title_s: TextStyle = TextStyle(fontSize = 32.sp, color = CustomTheme.colors.customPrymaryColor)
    )
    but it says that
    Composable invocations can only happen from the context of composable function
    c
    a
    • 3
    • 7
  • c

    Colton Idle

    10/20/2021, 2:19 AM
    Woot! https://twitter.com/chrisbanes/status/1450394964307976196
    👍 5
    🎉 1
    🙌🏼 4
    👍🏻 1
    👍🏼 2
    🙌 13
    c
    j
    • 3
    • 3
  • s

    Spikey Sanju

    10/20/2021, 3:51 AM
    Hi Team 👋, How can I add a
    stickyHeader
    to
    LazyVerticalGrid
    ? Is there any workaround solution for this?
    c
    d
    f
    • 4
    • 6
  • m

    Mohammad Jahidul Islam

    10/20/2021, 5:36 AM
    Hi, I am a beginner. Cay you give me a road map how can I learn android development with jetpack compose. I already know kotlin basics.
    g
    • 2
    • 2
  • c

    carbaj0

    10/20/2021, 8:48 AM
    How to do partial and full swipe on a list of items? I would like to implement this behavior. https://github.com/rambler-digital-solutions/swipe-layout-android
    c
    • 2
    • 2
  • c

    Clament John

    10/20/2021, 8:57 AM
    Q: How to share a viewmodel between NavGraph components (only) I would like to share a viewmodel between many composables. Just like how we share a viewmodel between fragments within an Activity. But when I try this
    setContent {
        val navController = rememberNavController()
    
        NavHost(navController = navController, startDestination = "home") {
            navigation(startDestination = "username", route = "login") {
                // FIXME: I get an error here
                val viewModel: LoginViewModel = viewModel()
                composable("username") { ... }
                composable("password") { ... }
                composable("registration") { ... }
            }
        }
    }
    I get an error
    @Composable invocations can only happen from the context of a @Composable function
    Need • The viewmodel should only be active in the NavGraph Scope. • When I go to a different route and come back I should initialize a new viewmodel (this is why I'm calling it in the NavGraph) Almost similar solution 1. Answer by [Philip Dukhov](https://stackoverflow.com/users/3585796/philip-dukhov) for the question [How to share a viewmodel between two or more Jetpack composables inside a Compose NavGraph?](https://stackoverflow.com/a/68857871/5698740) a. But in this approach the viewmodel stays in the scope of the activity that launched it and so is never garbage collected.
    c
    i
    • 3
    • 17
  • c

    Colton Idle

    10/20/2021, 10:05 AM
    How can I blur the persons legs? Code in thread
    👀 2
    s
    j
    +4
    • 7
    • 31
  • z

    Zoltan Demant

    10/20/2021, 10:37 AM
    I always run into
    NoSuchMethodError
    after making tweaks to composables in my design system - cleaning & rebuilding the project fixes it (the design system is in a separate module). Any ideas on what I can do to narrow the issue down before I post a bug-report? 🧵👀
    • 1
    • 1
  • m

    Mehdi Haghgoo

    10/20/2021, 11:39 AM
    I don't find anything in Compose docs regarding how to request Android permissions? ...
    d
    i
    • 3
    • 7
  • j

    Jonas Frid

    10/20/2021, 12:07 PM
    I have a LazyColumn with a template defined for each item. Is there a way to have a container composable around those items that scrolls with the items?
    m
    c
    • 3
    • 5
Powered by Linen
Title
j

Jonas Frid

10/20/2021, 12:07 PM
I have a LazyColumn with a template defined for each item. Is there a way to have a container composable around those items that scrolls with the items?
This is what I got:
LazyColumn(modifier = Modifier
    .fillMaxWidth()
    .wrapContentHeight()
    .clip(RoundedCornerShape(OneAppTheme.cornerRadius.listItemRadius.dp))
    .background(OneAppTheme.colors.listItemColor.toColor())
) {
    items(countries) {
        Text(it.name)
    }
}
But that is not a container around the items that will scroll with the items, it is styling on the LazyColumn itself.
m

martinsumera

10/20/2021, 12:22 PM
LazyColumn {
    items(countries) { country ->
        Box(modifier = Modifier.whatever()) {
            Text(country.name)
        }
    }
}
Is this what you had in the mind?
j

Jonas Frid

10/20/2021, 2:31 PM
No. That will create a box around each item. I want a container around all items that scrolls with the items.
c

cb

10/20/2021, 4:03 PM
The only way to do what you're asking is to add a single item with a
Surface { Column { ... } }
. You can't add arbitrary background containers to a group of items.
j

Jonas Frid

10/20/2021, 5:07 PM
To bad. Hope they will add that. Thanks!
View count: 1