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

    natario1

    02/16/2021, 12:01 PM
    How do I request focus for a composable as soon as it enters composition?
    j
    t
    • 3
    • 3
  • v

    vipulasri

    02/16/2021, 12:14 PM
    Whats the issue with warning like these:
    'Surface(Modifier = ..., Shape = ..., Color = ..., Color = ..., BorderStroke? = ..., Dp = ..., () -> Unit): Unit' is only available since Kotlin 1.4.30 and cannot be used in Kotlin 1.4
    P.S:
    kotlin_version = '1.4.30'
    compose_version = '1.0.0-alpha12'
    a
    • 2
    • 2
  • y

    Yuri Drigin

    02/16/2021, 12:32 PM
    Is there native way to hide softKeyboard inside Composable? Or need to use activity / fragment?
    p
    p
    • 3
    • 6
  • p

    Piotr Prus

    02/16/2021, 12:48 PM
    I am experimenting with gesture detection in compose. Here is the code snipped:
    Surface(color = MaterialTheme.colors.background) {
                        Box(modifier = Modifier.size(100.dp).background(Color.Yellow)
                            .pointerInput(Unit) {
                                detectVerticalDragGestures(
                                    onDragCancel = { Log.d("AAAA", "onDragCancel") },
                                    onDragEnd = { Log.d("AAAA", "onDragEnd") },
                                    onVerticalDrag = { change, dragAmount -> Log.d("AAAA", "Drag change: $dragAmount") }
                                )
                            })
                    }
    It is a simple Box. The issue:
    onDragEnd
    and
    onDragCancel
    are never called. The
    onVerticalDrag
    works like a charm. Is there any mistake in my code or should I file a bug? Compose version : alpha12
    j
    • 2
    • 2
  • j

    József Szilvási

    02/16/2021, 1:07 PM
    I know it has been asked before, but I haven’t seen any answers yet. Is there any way to strip the vertical padding off of the fonts? Something like a replacement for:
    android:includeFontPadding="false"
    android:lineSpacingExtra="0dp"
    ➕ 1
    d
    r
    • 3
    • 7
  • a

    Alex Bieliaiev

    02/16/2021, 2:09 PM
    Hey guys. After
    7.0.0-alpha04
    to
    7.0.0-alpha06
    Android Gradle plugin migration I'm getting
    This version (1.0.0-alpha12) of the Compose Compiler requires Kotlin version 1.4.30 but you appear to be using Kotlin version 1.4.21 which is not known to be compatible.
    error. That is sort of expected, since I have a
    classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:1.4.21")
    top-level dependency. Prior to the upgrade, however, I could explicitly specify
    kotlinCompilerVersion
    in the
    ComposeOptions
    section. As of now, this property seems to be deprecated. Do I have options other than complete project migration to Kotlin v1.4.30?
    d
    • 2
    • 4
  • a

    Ahmet Delibaş

    02/16/2021, 3:17 PM
    I want to use LazyRow to show LazyPagingItems in it. I do it, but when I refresh the list, list does not change. Is there anyone who know the solution ? I am sharing my code in the thread:
    • 1
    • 1
  • n

    Noé Casas

    02/16/2021, 3:19 PM
    when using a WebView through AndroidView, sometimes the page is not shown. It appears to be random (the same page appears sometime, but sometimes it does not). When the problem happens, sometimes the following error shows up in logcat:
    2021-02-16 16:08:34.866 9683-9698/... E/System: Uncaught exception thrown by finalizer
    2021-02-16 16:08:34.909 9683-9698/... E/System: java.lang.IllegalStateException: Warning: Router objects should be explicitly closed when no longer required otherwise you may leak handles.
            at w4.finalize(chromium-TrichromeWebViewGoogle.aab-stable-432415233:4)
            at java.lang.Daemons$FinalizerDaemon.doFinalize(Daemons.java:289)
            at java.lang.Daemons$FinalizerDaemon.runInternal(Daemons.java:276)
            at java.lang.Daemons$Daemon.run(Daemons.java:137)
            at java.lang.Thread.run(Thread.java:919)
         Caused by: java.lang.Exception: AutocloseableRouter allocated at:
            at w4.<init>(chromium-TrichromeWebViewGoogle.aab-stable-432415233:4)
            at vu.<init>(chromium-TrichromeWebViewGoogle.aab-stable-432415233:8)
            at org.chromium.content.browser.framehost.RenderFrameHostImpl.<init>(chromium-TrichromeWebViewGoogle.aab-stable-432415233:10)
            at org.chromium.content.browser.framehost.RenderFrameHostImpl.create(chromium-TrichromeWebViewGoogle.aab-stable-432415233:1)
            at J.N.MZAK3_Tx(Native Method)
            ...
    The way I instantiate webview is :
    @Composable
    fun WebViewView(html: String, ...) {
        AndroidView({ context ->
            val webView = WebView(context)
            // configure webview
            webview
        })
    }
    This have been happening in all compose versions I have tried. I have not found any similar problem in the bug tracker. Am I doing something wrong? Should I report a bug?
    m
    • 2
    • 1
  • k

    Kshitij Patil

    02/16/2021, 4:26 PM
    How can bring the cross button above the box? The Text & Icon are being defined inside a box which is managing stroke & background color as well as shape. I tried putting cross button in parent box and with zIndex of this child box less than the icon’s but didn’t work. Do I need to write custom layout for this?
    d
    y
    +2
    • 5
    • 9
  • r

    Rick Regan

    02/16/2021, 5:47 PM
    I'm trying to reconcile the single source of truth/state hoisting principle with the discrete
    Slider
    . As far as I can tell, it's not possible to hoist the discrete slider state and have it control the slider, meaning the local continuous slider state is the actual source of truth (see code in thread -- you of course can't reset the slider from the callback). You need to maintain continuous slider state so that the slider moves smoothly -- instead of jumping -- between discrete values. Obviously I could fix this by hoisting the continuous state, but then the slider is no longer conceptually discrete at that level; I'd have to move the "discreteness processing" up there. I don't think there's anything to be done about it; I guess I'm just saying that the discrete slider abstraction is "leaky".
    m
    • 2
    • 8
  • y

    Yofou

    02/16/2021, 5:49 PM
    is it possible to either replace or turn off the ripple effect on a clickable?
    d
    t
    • 3
    • 3
  • k

    Ky

    02/16/2021, 10:58 PM
    Has anyone had issues with
    ComponentActivity.setContent
    after updating to alpha12? on alpha11, something like this worked fine
    someFrameLayout.setContent(Recomposer.current()) {
                CommonMdcTheme {
                    SomeComposeView(viewModel)
                }
            }
    After updating to alpha 12, it complains about receiver mismatch. I’ve tried both deprecated method from
    androidx.compose.ui.platform.setContent
    and new method
    androidx.activity.compose.setContent
    m
    i
    +2
    • 5
    • 24
  • m

    Mehdi Haghgoo

    02/17/2021, 9:14 AM
    Seems like LazyColumn has an issue with layout when scrolling, in that if we have defined a shadow for the column, the shadow height is added to column height when an item is being scrolled out at the top. The result is that part of the item sticks out of the shadow-border boundary. Please see the screen shots.
    a
    • 2
    • 1
  • m

    Mehdi Haghgoo

    02/17/2021, 1:05 PM
    Does Jetpack Compose have easy integration with gallery and storage access for picking files?
    🇳🇴 1
    🔜 1
    i
    z
    +2
    • 5
    • 15
  • k

    Kshitij Patil

    02/17/2021, 1:09 PM
    if
    scrollState.smoothScrollBy()
    (blocking) is deprecated, what are we supposed to replace it with (suspending) ? I didn’t understand the replacement from deprecated message. Who has
    smoothScrollBy
    method apart from Scrollable?
    m
    • 2
    • 3
  • i

    Ilias Zosimadis

    02/17/2021, 1:55 PM
    What is the best way to animate the shape of a
    Surface
    ? Should I use a custom shape with
    createOutline
    or create a custom surface composable with
    Canvas
    ?
    a
    a
    a
    • 4
    • 6
  • m

    Marko Novakovic

    02/17/2021, 2:28 PM
    will it be supported to pass
    Composable
    function as a reference?
    posts.map(::PostCard)
    for example
    👀 5
    d
    • 2
    • 1
  • d

    Daniele B

    02/17/2021, 2:42 PM
    I have a master/detail app, using NavHost. I get a strange warning when I hit the back button from the Detail screen, and the screen goes back to Master:
    D/InputDispatcher: Waiting to send key to Window{1bda786 u0 myapp.MainActivity} because there are unprocessed events that may cause focus to change
    I am posting the code in a comment to this message. Am I setting up the NavHost incorrectly? Is this warning meaningful or should I disregard it? The app still works well.
    • 1
    • 1
  • k

    Kevin Aude

    02/17/2021, 2:52 PM
    Hi all, I'm currently working on a launcher app in Compose. In order to move an app from the app drawer to the home screen I'd need to be able to drag and drop an element from one composable to another one (not sure if the terminology is correct here). Any idea how to do that? I would need the full experience, with a drop shadow and everything and I can't seem to find anything that remotely compares to the system that existed in the traditional view system.
    a
    • 2
    • 6
  • m

    Mehdi Haghgoo

    02/17/2021, 5:08 PM
    I think I have made a horrible mistake when trying to read a state from Room-backed ViewModel. Error: java.lang.IllegalStateException: Reading a state that was created after the snapshot was taken or in a snapshot that has not yet been applied. Code follows in thread.
    j
    a
    • 3
    • 30
  • r

    rsktash

    02/17/2021, 6:04 PM
    SOLVED
    d
    • 2
    • 5
  • b

    bohregard

    02/17/2021, 7:14 PM
    I’m seeing an issue with
    itemsIndexed
    in
    LazyColumn
    when I clear the item list I have I get a
    java.lang.IndexOutOfBoundsException: index: 0, size: 0
    . Is there a secret way to clear a list?
    🤣 4
    • 1
    • 2
  • a

    aperfilyev

    02/17/2021, 8:26 PM
    why does my factory being invoked when I navigate back to this composable? I’m using jetpack navigation as well
    private val factory = InvalidatingPagingSourceFactory { FeedSource(pages.value, api) }
    
        val items: Flow<PagingData<FeedItem>> = Pager(PagingConfig(20)) {
            factory.invoke()
        }.flow
    composable
    @Composable
    fun FeedScreen(factory: ViewModelProvider.Factory, onItemClick: (Long) -> Unit) {
        val viewModel = viewModel<MainViewModel>(factory = factory)
        val items = viewModel.items.collectAsLazyPagingItems()
    
        LazyColumn(content = {
            items(items) { item ->
                if (item != null) {
                    RealRowItem(item = item, onItemClick = onItemClick)
                } else {
                    PlaceholderRowItem()
                }
            }
        })
    }
    i
    • 2
    • 3
  • l

    Lilly

    02/17/2021, 8:28 PM
    Hi, is there a trend what navigation library to use. I'm currently using
    compose-router
    which is relative outdated. It feels like in the long run there will be only
    navigation-compose
    . I would be fine with switching to navigation-compose, but would like to hear some thoughts and feedback
    d
    i
    +2
    • 5
    • 15
  • t

    Tash

    02/17/2021, 9:18 PM
    Trying to create an “animation/modifier state” class similar to SwipeableState, with `AnimatedFloatModel`s inside. Is there a way to animate multiple
    AnimatedFloatModel
    s together and then listen for the end of the collective animation?
    @Stable
    class FooDragState { 
     val animatedOffsetX = AnimatedFloatModel(initialValue = 0f, clock)
     val animatedOffsetY = AnimatedFloatModel(initialValue = 0f, clock)
     
     (animatedOffsetX, animatedOffsetY).animateTo(1f, animationSpec, onEnd = { /** do something **/ })
    }
    d
    • 2
    • 3
  • r

    radzio

    02/17/2021, 9:27 PM
    Hi, I'm playing with Jetpack Compose I've faced one problem - soft keyboard +
    TextField
    focus inside scrollable
    Column
    . I don't know how to scroll
    Column
    to the selected/focused
    TextField
    I've creates stackoverflow question too: https://stackoverflow.com/questions/66249829/jetpack-compose-scroll-to-focused-composable-in-column Can someone tell me what is the best approach for this? I don't need/want use LazyColumn (not so many TextFields)
    t
    s
    +2
    • 5
    • 12
  • r

    rsktash

    02/18/2021, 1:13 AM
    Hi. Is there something built-in for shared transition animation between screens?
    d
    a
    • 3
    • 13
  • t

    Tlaster

    02/18/2021, 3:09 AM
    Does anyone get
    java.lang.RuntimeException: Parcel: unable to marshal value androidx.compose.runtime.SnapshotMutableStateImpl
    error after alpha 12?
    p
    s
    a
    • 4
    • 11
  • c

    Colton Idle

    02/18/2021, 4:05 AM
    Trying to implement this in compose, but I'm running out of ideas. This banner will say things like "Free" and "Paid" but my designer wants to have this little "tail"/"wraparound" going on for the banner. Offsetting a rectangle that holds text isn't hard, but the tail is killing me. Ideas?
    h
    s
    n
    • 4
    • 6
  • m

    Mehdi Haghgoo

    02/18/2021, 7:44 AM
    Does every composable necessarily create UI?
    h
    d
    +2
    • 5
    • 13
Powered by Linen
Title
m

Mehdi Haghgoo

02/18/2021, 7:44 AM
Does every composable necessarily create UI?
h

Halil Ozercan

02/18/2021, 8:07 AM
are you trying to summon Jake?
😆 2
🤣 1
😀 4
Joking aside, the answer is no. Composables can return state, launch effects, etc. without drawing any UI at all.
d

Denis

02/18/2021, 10:01 AM
Are there any public use cases for non-UI Composables?
k

kioba

02/18/2021, 10:30 AM
stringResource
👍 1
d

Denis

02/18/2021, 10:46 AM
I thought maybe somebody could expand on what kind of projects are possible with it
Each of my three projects built on Compose do not use the new Compose UI toolkit.
https://jakewharton.com/a-jetpack-compose-by-any-other-name/
j

jw

02/18/2021, 2:36 PM
The output of a Composable function call hierarchy is a tree of objects which have properties. What you do with those objects is up to you and your imagination.
🙏🏻 1
d

Denis

02/18/2021, 2:37 PM
What you do with those objects is up to you and your imagination
Yeah... That's exactly what I have problems with 😃
j

jw

02/18/2021, 2:38 PM
You could build serialization trees and then send only diffs as the tree changes. You could use it as the output of your presentation layer and send diffs to the UI layer. You could target alternative UI rendering such as the View tree, RemoteView, Slices, GL, etc.
You could maintain a binary tree and have an
invert: Boolean
and ace the Google interview
:party-parrot: 1
:mind-blown: 6
💥 3
😁 4
d

Denis

02/18/2021, 2:42 PM
Thanks, Jake. I'm gonna meditate on this quote tonight: "The output of a Composable function call hierarchy is a tree of objects which have properties"
j

jw

02/18/2021, 4:09 PM
Think about it like this: for Views, we imperatively instantiated objects and added them to their parents in code to create a tree. Or, we use a declarative tool like XML to do it for us. That tree was made up of objects which happen to know how to render themselves to a canvas. Each has properties to control things like text color, alignment, whatever. Compose UI is very similar to Android Views in that regard. It's a tree of objects which have properties that happen to know how to render themselves. You could create a tree of them imperatively like we did with Android Views! But Compose UI also ships with Composables that allow us to declaratively build that tree using function calls instead of XML. If we wanted to, we could build an XML schema that produced Compose UI trees. We also could create Composable functions that produced Android View trees. The difference is that the view system was tailored for XML whereas Compose UI is tailored for Composables.
👏🏽 2
m

Mehdi Haghgoo

02/18/2021, 6:22 PM
@jw I am not sure if I get what you mean by "you could create a tree them (Compose objects) imperatively Like we did with Android views".
j

jw

02/18/2021, 6:26 PM
Sure. The output of Compose UI's composable functions is a tree of objects which are called LayoutNode. They're somewhat akin to a View in the old system. If you wanted you could create and assign properties to all the LayoutNodes yourself, just like old views.
➕ 1
✔️ 1
👍 1
View count: 5