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

    Guy Bieber

    06/03/2020, 10:29 PM
    TextField with a Keyboard.password doesn’t work as expected to hide the password as it is typed. Is there something like this for text fields:
    //by default
    edittext.setTransformationMethod(new PasswordTransformationMethod());
    //You can make it custom
    edittext.setTransformationMethod(new AsterPasswordTransformationMethod());
    v
    l
    s
    • 4
    • 48
  • g

    Guy Bieber

    06/04/2020, 3:15 AM
    Has anyone integrated google maps into a compose app? I am looking for example code if it exists.
    j
    • 2
    • 4
  • e

    Elena Boiko

    06/04/2020, 7:44 AM
    Hello 🙂 I came across an interesting case. I added two modifiers to a Row: clickable and ripple. If I add them in this order (Modifier.clickable(...).ripple()), ripple works, but onClick is not invoked. If I change the order (Modifier.ripple().clickable(...)), both modifiers work. So my question is: is there some order by which we should add modifiers?
    m
    • 2
    • 2
  • a

    allan.conda

    06/04/2020, 12:19 PM
    Is compose live preview not working on latest AS Canary 10, compose-dev12, agp, or kotlin version or whatever, or is it just me?
    Untitled
    a
    • 2
    • 1
  • m

    manueldidonna

    06/04/2020, 3:03 PM
    Watch the video till the end. Have you noticed how the touch and the movement of the slider are not synchronized? In practice it is even more noticeable, the finger reaches the end of the screen without completing the slider movement
    z
    m
    • 3
    • 3
  • h

    henrikhorbovyi

    06/04/2020, 5:02 PM
    Hey hey! Why
    title
    (and others too) property appears and it is implemented but when I call it shows an error highlight?
    l
    • 2
    • 10
  • p

    pavi2410

    06/04/2020, 6:33 PM
    How do I close
    AlertDialog
    ? I want to implement an Exit Dialog but it is neither closing when
    onCloseRequest
    is called nor when
    confirmButton
    is clicked
    @Composable
    private fun ExitDialog() {
        val (show, setShow) = state { true }
        if (show) {
            AlertDialog(
                text = {
                    Text("Do you want to really quit???")
                },
                confirmButton = {
                    Button(modifier = Modifier.padding(16.dp), onClick = { setShow(false) }) {
                        Text(text = "OK")
                    }
                },
                onCloseRequest = { setShow(false) }
            )
        } else {
            return
        }
    }
    h
    z
    • 3
    • 18
  • h

    henrikhorbovyi

    06/04/2020, 11:54 PM
    Is there a way to achieve this result:
    s
    l
    • 3
    • 12
  • c

    coolchandrakumar

    06/05/2020, 7:41 AM
    Facing unresolved reference while using TextView/WebView inside composable.
    @Composable
    fun inflateAndroidView() {
        Column(modifier = Modifier.fillMaxWidth().wrapContentSize(), horizontalGravity = Alignment.Start) {
            Text(text = "AndroidView-Compose", modifier = Modifier.padding(all = 16.dp))
    
            AndroidView(view = TextView(ContextAmbient.current).apply {
                text = "InsideTextView Android Widget"
            })
    
            AndroidView(view = WebView(ContextAmbient.current).apply {
                loadData("InsideWebView Android Widget", "text/html", "UTF-8")
            })
        }
    }
    Looking to achieve the same in developement
    p
    m
    z
    • 4
    • 14
  • d

    dagomni

    06/05/2020, 11:10 AM
    Hi, I've written a simple modifier that creates a skeleton view from layout. I'm sharing in case anyone would like to use it. It could probably be improved somehow, but it's enough for my purposes. Example in the next message https://gist.github.com/dgomolka/c8af2ea84d8ec95eda9aa861e38e955f
    👍 7
    • 1
    • 1
  • k

    Kazemihabib1996

    06/05/2020, 3:10 PM
    There is no slot for
    BottomNavigation
    in
    Scaffold
    is the
    bottomAppbar
    slot is for both
    BottomAppBar
    and
    BottomNavigation
    ? if so, is the name of
    bottomAppbar
    parameter will change in future?
    m
    • 2
    • 1
  • c

    carbaj0

    06/05/2020, 5:24 PM
    hi!
    Card(
        modifier = Modifier.clickable(onClick = { someaction() }).ripple()
    )
    onclick isn't working, it shows the ripple but not perform the action
    l
    • 2
    • 2
  • h

    henrikhorbovyi

    06/05/2020, 5:32 PM
    ?
    l
    v
    r
    • 4
    • 7
  • h

    henrikhorbovyi

    06/06/2020, 6:52 AM
    Hello, I have the following code in my project (I saw it in JetNews repo)
    @Model
    object AppNavigator {
        var currentScreen: Screen = Screen.Home()
    }
    
    /**
     * Temporary solution pending navigation support.
     */
    fun navigateTo(destination: Screen) {
        AppNavigator.currentScreen = destination
    }
    But now I'm using dev12, and we know that
    @Model
    is deprecated. How do you guys would fix it? I've tryied:
    object AppNavigator {
        var currentScreen: MutableState<Screen> = state { Screen.Home() }
    }
    But it does not work, states must be called inside composables
    k
    v
    +2
    • 5
    • 19
  • m

    Mikael Alfredsson

    06/06/2020, 5:07 PM
    Does compose give you a way to de-saturate an image? The ImageView can use ColorMatrices as color filters (and the ColorMatrix class even has a helper method for
    setSaturation
    but I can’t find any similar function for Composable Images? (I’m very new to Compose so I can easily have missed something)
    n
    • 2
    • 1
  • h

    henrikhorbovyi

    06/06/2020, 11:24 PM
    Is there a plan to create a
    Center
    composable? example
    Center {
        Text("I'm in the center now")
    }
    m
    • 2
    • 5
  • d

    Diego Marulanda

    06/07/2020, 3:45 AM
    hi, how can I make my
    HorizontalScroller
    scroll to a specific point? I mean, I have several images in a
    HorizontalScroller
    and I need that when the user performs the scroll this movement continues so that the image that is seeing at that moment it is centered, for example, if the user stops scrolling in the middle of the first and the second image, the scroll completes the movement until only one of the 2 images is seen
    z
    h
    • 3
    • 4
  • z

    Zach Klippenstein (he/him) [MOD]

    06/07/2020, 7:05 PM
    Has the Compose team (or anyone else) thought about what “shared element transitions” might look like for Compose-based navigation?
    ➕ 10
    k
    • 2
    • 7
  • t

    Tash

    06/07/2020, 7:27 PM
    Is there a Compose construct for handling back button presses? So far I've just been trying to use the Activity's
    OnBackPressedDispatcher
    , but wondering if there's a better way...
    a
    z
    +2
    • 5
    • 16
  • v

    Vinay Gaba

    06/07/2020, 11:47 PM
    Trying to use the
    testTag
    Modifier on a Text composable that’s a part of the AdapterList. I’m getting this error
    java.lang.IllegalStateException: merge function called on unmergeable property TestTag. Existing value: Composable1, new value: Composable2. You may need to add a semantic boundary.
    	at androidx.ui.semantics.SemanticsPropertyKey.merge(SemanticsProperties.kt:95)
    Do I need to use this differently when used inside an AdapterList?
    l
    r
    • 3
    • 10
  • v

    Vinay Gaba

    06/08/2020, 12:29 AM
    Another question - I’m using
    AndroidComposeTestRule
    to start a custom activity to test it. The individuals tests work fine but they fail when running them together. This is because I’m not doing anything in the
    @Before
    method to clean and restart the activity. That causes the state to be shared between the test cases. I know in Espresso I’ve used a custom test rule for avoiding this. Can I get any direction on whether something like that already exists in compose?
    • 1
    • 1
  • k

    kenkyee

    06/08/2020, 1:33 AM
    Anyone see this weird runtime behavior where it crashes looking for a DefaultPreview method if it's removed? It also seems to run that DefaultPreview method at runtime even though it's supposed to be only for the IDE preview window (breakpoints get hit there instead of the one created in the onCreate method) Preview window doesn't work too...layout is super simple...two buttons and a textview. Code compiles fine....though another super weird thing is you have to click the run or debug button 3 times before it actually builds and runs (error msg is D:\Work\Android\table-timer\app\build\intermediates\compile_and_runtime_not_namespaced_r_class_jar\debug\R.jar: The process cannot access the file because it is being used by another process.) Using Gradle 6.5-milestone-1 because of bug with AGP 4.1.0-alpha10 not liking Gradle 6.5.
    Untitled
    l
    • 2
    • 4
  • h

    henrikhorbovyi

    06/08/2020, 4:57 AM
    Has anyone tried to use Koin inside a
    @Composable
    function?
    g
    • 2
    • 2
  • m

    Manuel Wrage

    06/08/2020, 8:28 AM
    Are there any examples of using Dagger with Compose?
    g
    a
    • 3
    • 8
  • h

    henrikhorbovyi

    06/08/2020, 2:52 PM
    Koin + Compose What do you think about this approach?
    Injectable {
        val myDependency: MyDependecy by inject() 
        HomeScreen(myDependency)     
    }
    z
    p
    • 3
    • 19
  • p

    pavi2410

    06/08/2020, 5:04 PM
    Also, how to remove toolbar from Preview?
    v
    • 2
    • 7
  • k

    Klaas Kabini

    06/08/2020, 5:27 PM
    When will a ViewPager be built into compose?
    ➕ 5
    m
    c
    • 3
    • 3
  • k

    Klaas Kabini

    06/08/2020, 5:31 PM
    Can you guys add a multi-range slider in compose?
    m
    l
    • 3
    • 6
  • m

    Marc Reichelt

    06/08/2020, 9:50 PM
    Hey there! What is the latest way to load an image from the URL? I tried to set this up with Coil (I saw a blog post by @Colin White, but that’s against an old version of compose), but in the end I sort of gave up. I didn’t find any api or any docs on how to load an image from the web. Did someone get this working with the latest Compose?
    z
    k
    • 3
    • 3
  • z

    Zach Klippenstein (he/him) [MOD]

    06/08/2020, 9:52 PM
    I don’t expect polished documentation at this point, but are there any code comments or anything that would helpful to read to learn about the composition “commit lifecycle” in more detail? E.g.
    launchInComposition
    launches the coroutine on commit, and cancels it on dispose, but it’s not clear if there’s any case in which a coroutine could be launched again in the same point in the composition, after being cancelled. Or whether
    onDispose
    is called if the composition fails before
    onCommit
    gets invoked.
    a
    c
    +2
    • 5
    • 10
Powered by Linen
Title
z

Zach Klippenstein (he/him) [MOD]

06/08/2020, 9:52 PM
I don’t expect polished documentation at this point, but are there any code comments or anything that would helpful to read to learn about the composition “commit lifecycle” in more detail? E.g.
launchInComposition
launches the coroutine on commit, and cancels it on dispose, but it’s not clear if there’s any case in which a coroutine could be launched again in the same point in the composition, after being cancelled. Or whether
onDispose
is called if the composition fails before
onCommit
gets invoked.
@Adam Powell mentions avoiding having to “try to rollback” when the composition fails, but if
onCommit
will only be called once for a given point in the composition, then as long as
onDispose
is called on composition failure it seems like rolling back would be fairly trivial. I feel like I’m missing some piece of the puzzle here. Maybe
onCommit
can be called multiple times? https://kotlinlang.slack.com/archives/CJLTWPH7S/p1591565761398100?thread_ts=1591558024.394400&amp;cid=CJLTWPH7S
a

Adam Powell

06/08/2020, 11:21 PM
Good callout, we've been talking about improving a bunch of the docs in this area soon 🙂
🙏🏼 5
onDispose
is not called on composition failure, it is called to dispose the result of a previous successful composition
👍 1
launchInComposition
is a sort of task that exists at its position in the composable function; just like a UI element it runs when it becomes present and is cancelled if it leaves the composition before finishing. It does not run again unless you provide it with comparison values that change from one recomposition to another, in which case it will cancel the currently running task block before launching the new one.
we've considered renaming it to
Task
or similar to reinforce this noun-entity behavior of presence in the composition (and joked about calling it
AsyncTask
in particular)
😅 6
c

Chuck Jazdzewski [G]

06/08/2020, 11:59 PM
To clarify some underlying semantics not covered by Adam,
onCommit
's lambda is only called once the composition succeeds that contains the
onCommit
.
onDispose
is only called if
onCommit
is called and only after composition succeeds that removes the
onCommit
from the composition. Calling the
onCommit
and
onDispose
lambdas is the last step of composition after it has committed to using the results of composition. The quote from Adam above was regarding side-effects in an
@Composable
function outside of
onCommit
. For example, if you launched a coroutine directly using the main dispatcher in the
@Composable
function, this might start a job that is unnecessary and need to be cancelled. However, we currently do not have an API to inform a
@Composable
function that its results were discarded. We, therefore, recommend all effects be contained in an
onCommit
or similar effect such as
launchInComposition
which uses
onCommit
internally (well, actually, it uses
CompositionLifecycleObserver
which is what
onCommit
uses too, but that is an implementation detail).
💯 1
🙏 1
⭐ 1
v

Vinay Gaba

06/09/2020, 12:06 AM
Just to be clear I understood this correctly, the recommendation is to wrap mutations/side effects inside the onCommit block? So something like this?
val count by state {0}

onCommit {
 count = count + 1
}
I am almost certain I misunderstood the discussion in the previous thread that Zach linked 😅
t

Tash

06/09/2020, 12:11 AM
This discussion is already offering a lot more clarity than the existing code docs so thank y’all. Also curious how
onPreCommit
comes into play here, as I see it is used in some internal Compose components.
➕ 1
😅 1
z

Zach Klippenstein (he/him) [MOD]

06/09/2020, 2:55 AM
Thanks a lot for the explanation, Chuck & Adam! Good to know exactly how initializing any kind of resource in a Composable function outside of commit is a potential leak. I am also curious about how
onPreCommit
fits into all of this, and a little curious in what scenario, without multi-threading, a composition could fail, but that’s not as interesting as knowing how compose behaves when it happens, so thanks again.
➕ 1
View count: 1