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

    spierce7

    04/14/2021, 7:10 PM
    I tried out vector drawables a few months ago with Compose. The loading of the vector drawables was async, which created issues for me with pop-in after the page was being displayed. Is there a way around that?
    d
    a
    • 3
    • 5
  • y

    YASAN

    04/14/2021, 7:20 PM
    For supporting dark theme, the documentation says I have to use
    private val DarkColors = darkColors(
        primary = Yellow200,
        secondary = Blue200,
        // ...
    )
    private val LightColors = lightColors(
        primary = Yellow500,
        primaryVariant = Yellow400,
        secondary = Blue700,
        // ...
    )
    but these can hold like 10 variables, I need my own custom color variables which change depending on the theme. Its super easy to do using XML resources but I am unsure if that's what I should do. Should I just use xml resources for this? or is there a way to handle those in Compose?
    b
    s
    • 3
    • 3
  • y

    YASAN

    04/14/2021, 10:07 PM
    Is there anything similar to animateLayoutChanges on Compose? I am trying to toggle the visibility of a layout using AnimatedVisibility but the final animation does not run as smoothly as animateLayoutChanges would but just toggling the visibility of a View. Also my Spacer fully disappears when its placed in an AnimatedVisibility which I am not sure why
    c
    i
    +2
    • 5
    • 13
  • j

    Jason Ankers

    04/15/2021, 2:26 AM
    Do navigation routes have a length limit? seeing some weird behaviour where if my route is over a certain length (i.e.
    workouts/{id}/edit
    ) it navigates to the next shortest route instead (
    workouts/{id}
    )
    ➕ 1
    i
    • 2
    • 5
  • d

    Deepak Gahlot

    04/15/2021, 6:38 AM
    Hi All, After updating to beta04 for compose. I'm seeing a lots of unresolved references regarding the Kotlin based ArrayList that i was using
    s
    • 2
    • 7
  • y

    Yuri Drigin

    04/15/2021, 8:23 AM
    Please help. Didn’t find way to make it. I need shadow with offset and alpha 0.08 but elevation don’t allow it. See attached
    b
    • 2
    • 3
  • h

    Heikki Rauhala

    04/15/2021, 10:25 AM
    In beta04 the keyboard navigation indeed works out of the box, but I find that if modifiers are in order
    Modifier.focusModifier().onFocusChanged { ... }
    , the
    onFocusChanged
    handler is not called, while if they're reversed
    Modifier.onFocusChanged { ... }.focusModifier()
    , it is called.
    • 1
    • 2
  • d

    Daniele Segato

    04/15/2021, 11:08 AM
    Where can i find documentation / samples on compose for the web and desktop? What i found for the web wasn't what i expected coming from Android. Instead of using
    Box
    ,
    Row
    ,
    Column
    , it used functions like
    h1
    which are closer to html.
    c
    • 2
    • 2
  • s

    ste

    04/15/2021, 12:07 PM
    Hi all, not sure if this is the right channel. Given the following minimal code (not sure this is Android / Compose specific),
    class MainActivity : ComponentActivity() {
    
        override fun onCreate(savedInstanceState: Bundle?) {
            super.onCreate(savedInstanceState)
    
            setContent {
                var clicksAmount by remember { mutableStateOf(0) }
    
                fun onItemClick(index: Int): () -> Unit = { repeat(index) { clicksAmount++ } }
    
                BasicText(text = "Clicks: $clicksAmount")
                LazyRow(
                    contentPadding = PaddingValues(12.dp),
                    content = { items(listOf(1, 2, 3)) { Example(it, onItemClick(it)) } }
                )
            }
        }
    }
    
    @Composable
    fun Example(index: Int, onClick: () -> Unit) {
        Column(
            horizontalAlignment = Alignment.CenterHorizontally,
            modifier = Modifier.padding(top = 12.dp).clickable { onClick() }
        ) {
            Image(painterResource(android.R.drawable.star_on), contentDescription = null)
            BasicText(text = index.toString())
        }
    }
    I get a huge build error when trying to build it. By the way, the combination of
    by
    (
    var clicksAmount by
    ) and
    ++
    (
    clicksAmount++
    ) is the cause. For instance,
    var clicksAmount = remember { ... }
    or
    clicksAmount += 1
    builds just fine. Is this an issue? I tried to google but didn't find anything, probably missed the right keywords
    :thread-please: 3
    j
    • 2
    • 1
  • a

    aiidziis

    04/15/2021, 12:26 PM
    Is it possible to run Compose with older Android Gradle Plugin versions? Looks like 7.0.+ versions causes
    ./gradlew check
    to fail with weird lint errors we never had before.
    ✅ 1
    👍 1
    b
    • 2
    • 2
  • p

    PHondogo

    04/15/2021, 12:58 PM
    Hello! Is it possible to have 'ThreadLocal' anolog for compossibles? I need to put parameter of the composable function to such structure to be able to take it from subcomposables without passing it as parameter. Globals can't solve this, cause it is possible to call such function with different parameter values and each should hold it's own 'ThreadLocal' value.
    o
    c
    • 3
    • 2
  • j

    james

    04/15/2021, 1:10 PM
    If I have a suspend function with some important long running code, and want to trigger it from a composable function, what is the standard way to start this long running function so that it is not cancelled when the component recomposes? Not clear on how to use the effect stuff for this
    f
    • 2
    • 1
  • c

    Colton Idle

    04/15/2021, 4:52 PM
    Is there any way to force all items in a Row to show? For example, if I have a row with text and a checkbox, then it looks good, but if the text is really long, it pushes the checkbox out of the row.
    a
    • 2
    • 5
  • s

    Socheat KHAUV

    04/15/2021, 5:33 PM
    is there a way write a composable screen which support keyboard awareness, which mean when keyboard show or hide, it will re-compose.
    z
    a
    • 3
    • 2
  • y

    YASAN

    04/15/2021, 6:20 PM
    I am trying to use
    val parentViewModel = hiltNavGraphViewModel<ParentViewModel>("Parent")
    but no matter what I do it imports the wrong hiltNavGraphViewModel which takes backStackEntry as a param and does not work in the end. When I type hiltNavGraphViewModel I can see the option for the one that has a String param but even after I select it and Android Studio auto completes the code to
    hiltNavGraphViewModel(route = )
    it is still the one that requires backStackEntry and route is red
    i
    • 2
    • 6
  • f

    FunkyMuse

    04/16/2021, 12:04 AM
    Is LocalSoftwareKeyboardController.current Supposed to return a new instance every time it's called? Cause currently it does return a new instance every single time I call it
    f
    • 2
    • 4
  • s

    Spikey Sanju

    04/16/2021, 5:55 AM
    Is there any way to achieve
    Reorder LazyColumn
    items with
    drag & drop
    ?
    j
    • 2
    • 1
  • y

    Yoshio Schermer

    04/16/2021, 7:05 AM
    Is it possible for a Composable to have its size modifier recomposed, but say a gesture modifier on the same Composable not?
    🙌 1
    p
    • 2
    • 2
  • y

    YASAN

    04/16/2021, 7:10 AM
    How can I vertically center a composable in a Row? If I use fillMaxHeight it will fill the whole screen. I cannot find a way to make it just fill the parent height.
    p
    j
    +2
    • 5
    • 10
  • p

    Piotr Prus

    04/16/2021, 7:21 AM
    Hi compose geeks. I am struggling a bit with state management, bottomNavigationBar and the map 😛 . I am using the approach from
    AdvancedNavigationSample
    , so every Tab has its own navGraph. I got three main screens: Map, List and settings(which is also the list TBH). The screens with lists works fine, the scroll position is maintained, nested fragments are maintained, etc. The Map view is recreated each time. Not all the components, but the map, which is added in
    AndroidView
    composable is recreated. I am saving the last location as a state, so the map shown the exact same place when I am coming back to it, but it always “calculates” or draw tiles again. Is that something for map specific that cannot be changed or something might be wrong with my
    AndroidView
    implementation?
    • 1
    • 1
  • y

    YASAN

    04/16/2021, 9:23 AM
    It is recommended to only use Compose navigation? or should we use fragments etc instead? It doesnt look like Compose navigation supports animations yet.
    j
    • 2
    • 11
  • m

    Maxr1998

    04/16/2021, 9:39 AM
    Can I somehow disable the clipping behavior for scrollable lists? I'm trying to build a drag & drop and want to be able to move items (horizontally) out of the list, but they're clipped at the list bounds when using offsets.
    f
    • 2
    • 2
  • o

    orangy

    04/16/2021, 3:04 PM
    I’m thinking about an alternative way to augment component appearance in response to
    interactionSource
    .
    Indication
    only allows to draw something, but not change how component renders itself, e.g. pseudo-3d button actually moving slightly when pressed, or a component shaking a bit if attempted to interact with it, doing component-specific hover effects, etc. I wonder if anyone already gave it a thought and have ideas/approaches on how to design it?
    z
    a
    k
    • 4
    • 17
  • c

    Cicero

    04/16/2021, 3:04 PM
    Do we have something for when we want to use one value for Preview and another one for Build?
    y
    j
    • 3
    • 6
  • m

    Mjahangiry75

    04/16/2021, 4:14 PM
    is there a way to add a header(like a
    Text
    ) to the a
    LazyVerticalGrid
    ?
    c
    • 2
    • 5
  • e

    enighma

    04/16/2021, 6:40 PM
    Is there a suggested way to create a preview if I use a ViewModel? Create a preview with mocked data? I just saw the IDE said it didn't support for viewmodels, so I was curious what the best practice will be
    j
    d
    +2
    • 5
    • 5
  • y

    YASAN

    04/16/2021, 7:01 PM
    Is it better to use LiveData in a ViewModel or use
    by remember { mutableStateOf(X) }
    Using remember takes less time but I am not sure if its recommended over livedata? Although I am not sure if it matters in the end of the day at all or not
    j
    a
    +3
    • 6
    • 29
  • s

    Se7eN

    04/16/2021, 10:18 PM
    So I released a compose app for beta testing a few days ago and one of the testers experienced crashes while casually browsing the app. However, I don't see any crashes on crashlytics or ANRs on play console. Could this be related to compose?
    c
    • 2
    • 2
  • r

    rnett

    04/17/2021, 1:54 AM
    Possibly related: it seems as though the compose compiler plugin is somehow deleting
    init
    blocks my plugin adds. Things work fine without the compose plugin, but adding it causes the my init blocks to not be present in bytecode (despite them showing up when dumping the IrClass from my plugin). Any idea how to debug this?
    • 1
    • 1
  • c

    Colton Idle

    04/17/2021, 2:07 AM
    Using
    setContent
    in an Activity seems to kill the ability to use
    Activity.onTouchEvent()
    Is this a bug? 🧵
    a
    • 2
    • 9
Powered by Linen
Title
c

Colton Idle

04/17/2021, 2:07 AM
Using
setContent
in an Activity seems to kill the ability to use
Activity.onTouchEvent()
Is this a bug? 🧵
Here's what I have with xml based layouts
class MainActivity : AppCompatActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)
        findViewById<Button>(R.id.myButton).setOnClickListener {
            Toast.makeText(this, "XML BUTTON CLICKED", Toast.LENGTH_SHORT).show()
        }
    }

    override fun onTouchEvent(event: MotionEvent): Boolean {
        if (event.action == MotionEvent.ACTION_UP) {
            Toast.makeText(this, "ACTIVITY CLICKED", Toast.LENGTH_SHORT).show()
            return true
        }
        return false
    }
}
The xml based layout has a button in the top left corner. When I click the button, I see the XML BUTTON CLICKED toast... and anywhere I click in the Activity I see ACTIVITY CLICKED
This is with compose
class MainActivity : AppCompatActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContent {
            val context = LocalContext.current
            Column(Modifier.fillMaxSize()) {
                Button({
                    Toast.makeText(context, "COMPOSE BUTTON CLICKED", Toast.LENGTH_SHORT)
                        .show()
                }) {
                    Text("Button")
                }
            }
        }
    }

    override fun onTouchEvent(event: MotionEvent): Boolean {
        if (event.action == MotionEvent.ACTION_UP) {
            Toast.makeText(this, "ACTIVITY CLICKED", Toast.LENGTH_SHORT).show()
            return true
        }
        return false
    }
}
Which does not work. The activity clicked never shows. But the COMPOSE CLICKED does. Ideas?
a

Albert Chang

04/17/2021, 2:44 AM
The doc of
onTouchEvent
says
Called when a touch screen event was not handled by any of the views under it.
And ComposeView is intercepting all the touch events.
c

Colton Idle

04/17/2021, 2:47 AM
Is that something I can opt out of? It kinda kills my Kiosk software 😭
a

Albert Chang

04/17/2021, 2:47 AM
No.
😭 1
If you really need that you can try
dispatchTouchEvent
.
c

Colton Idle

04/17/2021, 2:50 AM
Hm. dispathTouchEvent works sort-of. When I click on the compose button, now I get two events. The button AND the activity touch event. Am I missing something, or am I basically stuck with triggering both events in that scenario?
a

Albert Chang

04/17/2021, 2:51 AM
If what you want is to detect unhandled clicks, I don't think it's possible at activity level.
c

Colton Idle

04/17/2021, 2:54 AM
darn. Okay. I guess I'm going to have to rethink this. I've been using fragments in a single activity app, and I have always gone this route and it worked well. Now adding composables into the mix kinda "ruins" it. Will keep trying a few things. I did file a bug for this, so I guess I'll see if there's anyway to get around it
View count: 44