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

    Rick Regan

    03/26/2021, 1:26 AM
    Why does this compile?
    var text: String by mutableStateOf(text)
    (At runtime it gets "Attempt to invoke interface method 'java.lang.Object androidx.compose.runtime.State.getValue()' on a null object reference.)
    z
    a
    • 3
    • 6
  • a

    Albert Chang

    03/26/2021, 2:50 AM
    getValue
    not automatically imported fixed in AS Canary 12 🎉
    👍 14
    🔥 36
    s
    c
    k
    • 4
    • 4
  • s

    shahroz

    03/26/2021, 3:21 AM
    Planning to shift my SDK on compose, but worried for backward support or any other
    needs X version of Y dependency in the host application
    kind of issues that might arise. Anyone who made the switch, have any pointers to share?
    d
    • 2
    • 1
  • t

    Tash

    03/26/2021, 3:44 AM
    Looking into achieving
    ItemAnimator
    -esque animations for additions/removals into a
    LazyColumn/Row
    : I see we have this example in the codebase that wraps each item around
    AnimatedVisibility
    . However, the example is rather simplistic in that the
    visible
    flag to
    AnimatedVisibility
    is computed via indices; the actual list backing the
    LazyColumn
    doesn’t mutate. In most app scenarios, lists mutate based on some source of truth (domain/business layer). Can
    AnimatedVisibility
    still be used in some capacity to animate mutating lists, or are there any other Compose constructs we can use?
    c
    • 2
    • 3
  • e

    escodro

    03/26/2021, 10:52 AM
    Hello, everyone! 👋 I’m having some difficult to implement my custom
    Saver
    to be used with
    rememberSaveable
    . Could you please help me? I have a list of items that, when clicked, shows a
    BottomSheet
    with the item data. Implementing my custom
    Saver
    works only or the first time and the first item saved will show every time the screen is rotate. When in portrait or landscape, if I click in any item, it shows the item correctly. But when rotate, the first one saved is shown again. Code is in the comments. Thanks a lot in advance! ❤️
    a
    • 2
    • 23
  • w

    wisdom

    03/26/2021, 12:07 PM
    Hello devs, please how can i achieve the image in the TopBar and also not showing the topbar divider line?
    o
    • 2
    • 3
  • p

    pawegio

    03/26/2021, 4:17 PM
    Is there a way to declare
    NavHost
    without state restoration mechanism? I’d like to recompose it and return to start destination when state is lost.
    i
    • 2
    • 8
  • s

    Shawn Tucker

    03/26/2021, 8:26 PM
    In jetpack compose api guidelines, under hoisted state types (https://github.com/androidx/androidx/blob/androidx-main/compose/docs/compose-api-guidelines.md#hoisted-state-types It says that it is best to provide
    VerticalScrollerState
    instead of
    scrollPosition: Int,
    scrollRange: Int,
    onScrollPositionChange: (Int) -> Unit,
    onScrollRangeChange: (Int) -> Unit
    The issue I am experiencing with this approach is that now I can not update my viewModel when
    "onSomethingHappened"
    . I tried adding a callback to my custom state object but it just did not feel right. Is there a suggestion/best practice about how I can observe changes to my custom state object (and each of the parameters in it)?
    a
    • 2
    • 1
  • v

    Vinay Gaba

    03/27/2021, 6:25 AM
    Curious to hear if there is an equivalent of
    AccessibilityChecks.enable().setRunChecksFromRootView(true)
    available for Compose or if that already is capable of running on Compose views. I haven’t tested it yet so unsure about what its current behavior is.
    ➕ 3
    a
    j
    • 3
    • 2
  • s

    Simon

    03/27/2021, 9:04 AM
    Hello. I'm trying to migrate my app from fragments to compose. I've planned to do it fragment by fragment with a
    Composeview
    inside each, but I'm facing an issue with state restoration when using navigation component. When put on the backstack, the fragment's view is destroyed, but
    onSaveInstanceState
    is not called and there is no
    saveHierarchyState
    mechanism on
    ComposeView
    . So when a fragment's view is recreated when i pop the backstack, all scroll state of LazyColumn is lost for example. Is there a way to save this state inside fragments ? Thanks
    a
    i
    v
    • 4
    • 11
  • e

    elye

    03/27/2021, 10:51 AM
    Hi, can I store a composable function as a variable? https://stackoverflow.com/questions/66829497/can-i-store-a-composable-function-in-a-variable
    a
    m
    a
    • 4
    • 6
  • n

    Nat Strangerweather

    03/27/2021, 4:31 PM
    Hey guys 👋, I am trying to save a canvas as bitmap in my external drive. Is it at all possible in Compose to use something like:
    val b:Bitmap = canvas.drawToBitmap(Bitmap.Config.ARGB_8888)
    Or is there an alternative to save a canvas?
    n
    • 2
    • 1
  • o

    orangy

    03/27/2021, 5:56 PM
    Is it possible to make clipping occur with a certain offset from the measured rectangle? Looking at the
    GraphicsLayerScope
    , but there is no suitable property as far as I understand. It creates outline for clipping based on the
    measuredSize
    and I don’t see any way to influence that… It would be nice to have something like
    clipInsets
    property in the scope, which would be taken into account to calculate clip rectangle. I understand I can use another node around with some padding, but I’d like to do it via
    Modifier
    a
    • 2
    • 1
  • c

    Colton Idle

    03/27/2021, 7:04 PM
    I was expecting to see two boxes from this code, but only see one. I understand that I can try to use weight, but I want to be able to add more boxes programmatically and so I don't want to set weight to .5f now, then .33 for 3 boxes, .25 for 4 boxes, etc. Shouldn't the boxes inside the row resize to meet their aspect ratio so other boxes can fit in the same row?
    Row(modifier = Modifier.fillMaxWidth()) {
        Box(modifier = Modifier.border(1.dp, Color.Blue).aspectRatio(16/9F))
        Box(modifier = Modifier.border(1.dp, Color.Blue).aspectRatio(16/9F))
    }
    d
    • 2
    • 3
  • f

    FunkyMuse

    03/27/2021, 8:36 PM
    Hey guys, how did you fix the problem with compose navigation when you click restart activity and the screen is blank?
    i
    • 2
    • 6
  • c

    Colton Idle

    03/27/2021, 10:11 PM
    If I center text then everything works fine... but if I try to a long piece of text then I get a poorly cut off piece of text. Am I doing something wrong or is this a bug in compose? Code in thread.
    a
    • 2
    • 4
  • c

    Colton Idle

    03/28/2021, 12:03 AM
    If I want to create a new module that just houses my composables... would that be a "android app module" or "android library module"? Looks like the difference is id 'com.android.application' vs id 'com.android.library'
    s
    j
    • 3
    • 4
  • s

    Shivam Sethi

    03/28/2021, 1:43 AM
    I am using an AndroidView in Compose, the update callback executes every-time any state property changes, is there a way that I can make update callback to only execute on some selected state property change ?
    c
    • 2
    • 1
  • e

    elye

    03/28/2021, 6:58 AM
    Hi, I got a checkbox that can once click will change a mutable state boolean false to true and vice versa… and works in compose Beta01… But after move to Compose Beta02, it doesn’t work anymore… Is the behavior change already, did I code it wrong, or it’s a but in Beta02? https://stackoverflow.com/questions/66839056/mutablestate-variable-cannot-be-changed-again-on-the-subsequent-click-of-jetpack
    o
    a
    • 3
    • 3
  • m

    mmaillot

    03/28/2021, 1:29 PM
    There is an API or an easy way to animate an
    Image
    to move to a specific point ? I have an image at the top of my screen and an another image at the bottom. I want to translate the top image to the bottom. I’m starting with animation and I’m looking if there is an easy way to do that. I found the
    translateY
    method but how to get the dp between the top image and the bottom image ?
    o
    t
    • 3
    • 4
  • t

    Tymmm1

    03/28/2021, 3:04 PM
    Hey, I'm having some trouble finding a way to control the selection state of an item in a
    LazyColumn
    . Anyone knows how to do this? What I'm trying to achieve is getting to the selected state on a click (not a long click).
    t
    • 2
    • 5
  • s

    Se7eN

    03/28/2021, 7:17 PM
    I have two product flavors,
    free
    and
    pro
    . How can I make a different composable with the same name for each flavor?
    d
    n
    • 3
    • 6
  • m

    Marco Pierucci

    03/28/2021, 8:12 PM
    Small doubt about recomposition, snippet in the 🧵
    👍 1
    a
    • 2
    • 12
  • s

    Sanendak

    03/29/2021, 10:57 AM
    Hello everyone! How to inject viewModel with Dagger 2 (not Hilt) into composable? Yes, i may inject VM into Activity and send as parameter into composable function. But i don't like this method because what to do if i have many VM's? Earlier i inject VM's into fragments and this was fine.
    j
    l
    • 3
    • 5
  • e

    escodro

    03/29/2021, 1:03 PM
    Hello, everyone! 👋 I’m having some difficulties with
    SnackBar
    . I have a list of items with
    Checkbox
    and when the user clicks, it “completes” the item and removes from the list. My implementation tries to shown an “Undo Snackbar” when the user performs this action, which brings the item back to the list. The problem is that the
    Snackbar
    disappears in less than one second due to the recompostion when the item disappears from the list.
    LazyColumn() {
        items(
            items = taskList,
            itemContent = { task ->
                TaskItem(
                    task = task,
                    onItemClick = onItemClick,
                    onCheckedChange = {
                        onCheckedChange(it)
                        coroutineScope.launch { snackbarHostState.showSnackbar("Task Completed", "Undo") }
                    }
                )
            }
        )
    }
    I tried using
    LaunchedEffect
    but AFAIK, this will associate the effect to a state, not the user click, right? Do you have any idea on how to make the
    Snackbar
    keep visible while the screen is recomposing? Thanks a lot in advance! ❤️
    a
    • 2
    • 4
  • o

    oscarg798

    03/29/2021, 1:46 PM
    Hello, I got one question, can I use assisted injection in a composable ? meaning my view model has an assisted parameter, but I do not know how to get the factory in the composable function to pass it to the
    viewModel
    method
    d
    m
    • 3
    • 5
  • n

    Nthily

    03/29/2021, 2:08 PM
    How do I use jetpack compose to select images from my phone album to add to the user interface? (edited)
    a
    s
    s
    • 4
    • 32
  • a

    Abhishek Dewan

    03/29/2021, 2:20 PM
    hey everyone sorry if this is a stupid question but is there a place which documents all of out of the box composables that android provides as building blocks, something akin to the widget directory that flutter provides to developers.
    j
    f
    • 3
    • 3
  • s

    Se7eN

    03/29/2021, 2:48 PM
    Is this the correct way to make sure my view is destroyed when it leaves the composition?
    var bannerView by remember { mutableStateOf<MoPubView?>(null) }
    val context = LocalContext.current
    DisposableEffect(null) {
        bannerView = MoPubView(context).also {
            it.setAdUnitId("...")
            it.adSize = MoPubView.MoPubAdSize.HEIGHT_50
            it.loadAd()
        }
    
        onDispose {
            bannerView?.destroy()
            bannerView = null
        }
    }
    
    bannerView?.let { view ->
        AndroidView(
            factory = { view }
        )
    }
    z
    • 2
    • 3
  • a

    Arkadii Ivanov

    03/29/2021, 2:58 PM
    Hello! Binary compatibility police here again 👮‍♂️ Looks like
    Box
    implementation has changed at some point after
    beta01
    release. It was using the
    BoxScope
    object but now looks like it became an interface, and there is
    BoxScopeInstance
    object instead. As a result there is a crash when a library compiled against
    beta01
    is used with the most recent version of Desktop compose (0.4.0-build177). Writing here because Desktop compose releases are ahead of Jetpack Compose. Checked
    beta03
    version - it is still fine (not affected). Is it expected or by an accident?
    j
    t
    +2
    • 5
    • 7
Powered by Linen
Title
a

Arkadii Ivanov

03/29/2021, 2:58 PM
Hello! Binary compatibility police here again 👮‍♂️ Looks like
Box
implementation has changed at some point after
beta01
release. It was using the
BoxScope
object but now looks like it became an interface, and there is
BoxScopeInstance
object instead. As a result there is a crash when a library compiled against
beta01
is used with the most recent version of Desktop compose (0.4.0-build177). Writing here because Desktop compose releases are ahead of Jetpack Compose. Checked
beta03
version - it is still fine (not affected). Is it expected or by an accident?
j

jim

03/29/2021, 3:04 PM
Intentional breakage: https://issuetracker.google.com/issues/181888051
t

theapache64

03/29/2021, 3:06 PM
😐
m

matvei

03/29/2021, 3:06 PM
Yup, that's the internal api review bug. Here's the public link to the public bug: http://issuetracker.google.com/181869067
:thank-you: 1
j

jim

03/29/2021, 3:06 PM
Mmm, that public bug contains far less information 😞
🤷 1
m

matvei

03/29/2021, 3:07 PM
But the reasoning is still there, so I hope it would be useful to understand it better
a

Arkadii Ivanov

03/29/2021, 3:10 PM
Thanks! I will recompile and publish updates.
🚀 1
:thank-you: 1
z

Zach Klippenstein (he/him) [MOD]

03/29/2021, 3:24 PM
I for one would be very interested to see the api review debates y’all have internally, if you ever make those public 😜
😀 6
➕ 7
View count: 8