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

    Fudge

    11/15/2020, 3:42 PM
    Looking at
    compose-navigation
    , it seems like the api is quite akward to use. It requires predefining routes with Strings, and then specifying those Strings again when you want to navigate to those routes. And then passing parameters into the routes is a whole world of complication. What will you do when you need to pass real objects? Serialization? Why not a solution that looks like this, in the way Flutter did it?
    onClick = { navigate { TheOtherComposable(obj1, obj2) } }
    ➖ 1
    ➕ 3
    i
    k
    • 3
    • 5
  • z

    zoha131

    11/15/2020, 6:15 PM
    is there any Date/Time picker for compose?
    👀 5
    f
    • 2
    • 1
  • m

    manueldidonna

    11/15/2020, 6:17 PM
    The app should not search immediately when the text changes, but only after an interval.
    var result by remember { mutableStateOf(emptyList<String>()) }
    val (query, changeQuery) = remember { mutableStateOf("") }
    LaunchedEffect(subject = query) {
        delay(300L)
        stations = getResultFromWebServer(query)
    }
    BasicTextField(value = query, onValueChange = changeQuery)
    Is this the correct way to do it?
    📌 1
    z
    t
    k
    • 4
    • 8
  • h

    Hitanshu Dhawan

    11/15/2020, 9:32 PM
    Hey, I want to access
    MaterialTheme.colors.background
    inside my
    transitionDefinition
    but I as this function is not marked with
    @Composable
    I am getting this error
    @Composable invocations can only happen from the context of a @Composable function
    Is the
    transitionDefinition
    function made non-composable on purpose? How can I make access these values inside
    transitionDefinition
    ? My use case is to have different values for light and dark theme. Something like this…
    private val SomeTransitionDefinition = transitionDefinition<SomeState> {
        state(SomeState.State1) {
            this[backgroundColor] = if (MaterialTheme.colors.isLight) MaterialTheme.colors.primary else MaterialTheme.colors.secondary
        }
    }
    d
    • 2
    • 4
  • v

    Vincent tiensi

    11/15/2020, 10:24 PM
    Hi! Sorry I have a dumb question but can’t seem to figure it out. I created a reuseable listing component for pagination here
    fun <T> VerticalListingComponent(
        itemList: List<T>,
        loading: Boolean,
        loadNextPage: () -> Unit
    )
    and am calling it through this
    VerticalListingComponent(
        itemList = itemListingState.listings,
        loading = itemListingState.loading,
        {}
    )
    When I update the itemListingState the VerticalListingComponent seems to be consuming and displaying the new itemList properly, but it seems to be ignoring the loading boolean that I’m passing (I have a loading indicator that shows when loading = true). Does anyone know what I’m doing wrong?
    t
    • 2
    • 1
  • l

    len

    11/16/2020, 9:40 AM
    Is there an existing implementation of a modifier/component to reorder the elements of a LazyColumn with a drag handle?
    d
    • 2
    • 5
  • j

    Jrichards1408

    11/16/2020, 9:56 AM
    Hi, is there a jetpack compose component that loads images from a url like picasso?
    a
    g
    v
    • 4
    • 5
  • r

    Rafs

    11/16/2020, 10:30 AM
    Is there a way to get an undecorated TextField in compose?
    p
    • 2
    • 2
  • y

    Yahor

    11/16/2020, 11:27 AM
    Hello. Has anyone has an sample multi-module project with enabled Compose in some module? I'm trying to migrate some feature to Compose and project can't build at all. As I know, compose has a conflict with kapt and kotlin-android-extensions, but I don't have this one in project.
    j
    • 2
    • 2
  • j

    Jrichards1408

    11/16/2020, 3:06 PM
    anyone came across this error before in compose?
    y
    i
    g
    • 4
    • 19
  • m

    manueldidonna

    11/16/2020, 3:22 PM
    I'm exploring the navigation library with compose, I get that the navigation is string based, so any arguments I want to pass to the composable must be inserted in the route string. I have 2 screens. In the first screen the user creates a
    SearchRequest
    to pass to the second screen that uses it to fetch the items from a web server.
    data class SearchRequest(
        val departFrom: String,
        val arriveAt: String,
        val departureTime: Time, // data class with day, month and year
        val departureDate: Date // data class with minute and hour
    )
    What's the best way to translate this object to a route without parcelizing it?
    🤯 1
    r
    • 2
    • 2
  • v

    Vince Rickey

    11/16/2020, 3:50 PM
    I have a WebComponent Composable that's implemented with the legacy view interop:
    AndroidView(viewBlock = { webView })
    . This will load most webpages, but it fails to load resource intensive iFrames such as an interactive elections map graphic. I added the hardware acceleration tag to the app's Manifest, but still no luck. A log shows that the Fragment's rootview is hardware accelerated, but the Composable's AndroidView is not. The docs state that hardware acceleration is only possible through the Manifest's application or activity tags, or programmatically through the Window. I'm wondering if AndroidView doesn't support this yet if it isn't attached to the Activity or Window under the hood. Has anyone else encountered difficulty with hardware acceleration with AndroidView interop? Code snippet in the thread.
    r
    • 2
    • 5
  • d

    David Attias

    11/16/2020, 5:40 PM
    I'm struggling to implement a rather simple behaviour (automatic navigation without user interaction) using the recommended Architecture pattern where only a ViewModel is passed to a Composable and some navigation block to trigger on a user interaction. I've tried to pass a route as a State to the Composable (which triggers navigation when not null) in order to treat it as simple data in the ViewModel but I'm then stuck because when the user hits Back it navigate him back to the most recent screen automatically. I think I would need some kind of transient state which is restored to null when processed by the Composable view but I really don't know how to do it... Any input/help would be very very appreciated 🙏
    a
    j
    +2
    • 5
    • 30
  • r

    Rafs

    11/16/2020, 6:33 PM
    Is there anyway to Stroke and Fill a path at the same time using jetpack compose. from the source codes I can only see
    Fill
    and
    Stroke
    but i need something like
    StrokeAndFill
    a
    n
    • 3
    • 5
  • y

    Yahor

    11/16/2020, 7:28 PM
    Hello) I try to add Compose into existing project, copy paste all necessary dependencies from sample project but during compilation receive very interesting error 😄 Gradle build tools: 4.2.0-alpha16
    e: androidx.compose.compiler.plugins.kotlin.IncompatibleComposeRuntimeVersionException: You are using an outdated version of Compose Runtime that is not compatible with the version of the Compose Compiler plugin you have installed. The compose compiler plugin you are using (version 1.0.0-alpha07) expects a minimum runtime version of 1.0.0-alpha07.
    • 1
    • 1
  • s

    Sergey B

    11/16/2020, 7:38 PM
    Hey guys. I'm sorry I'm still pretty new to Compose. I want to achieve this type of behavior. could anyone point me in the right direction? Should I use the Swipeable modifier? Thank you in advance
    m
    • 2
    • 2
  • k

    Kirill Grouchnikov

    11/16/2020, 9:59 PM
    Are there APIs for image convolutions in Compose (on
    ImageBitmap
    )? In general, there doesn't seem to be a way, maybe by design, to get access to the underlying pixel information for direct manipulation.
    AndroidImageAsset
    and
    DesktopImageAsset
    go through a somewhat of a contortion to expose the underlying pixel information to the
    ImageBitmap
    , but I don't see any way to get those pixels afterwards.
    c
    n
    • 3
    • 10
  • d

    Denis Sakhapov

    11/17/2020, 2:57 AM
    In the
    Jetchat
    app, if you click on any of the chat messages prior to engaging message input, and then try to type a message, the input field won't trigger the keyboard to show up. Is this a known issue and are there any workarounds for it? I experience pretty much the same behavior in my project when I first click outside an input field and then on it, it seems to obtain the focus but the soft keyboard doesn't appear.
    Screen_Recording_20201117-105809_Jetchat.mp4
    👍 2
    :jetpack-compose: 1
    p
    d
    • 3
    • 7
  • a

    allan.conda

    11/17/2020, 4:46 AM
    I’m trying to
    remember
    a state on each item of a hoisted list. The idea is that an item’s state is remembered even if the list has been updated. Is it possible right now?
    @Composable
    fun Component(list: List<T>) {
      list.forEach { item ->
        // something like this but this won't work
        // this should stay as false if (someCondition) for the unchanged iteems even if the list is updated
        val rememberedFlag = remember(item) { mutableStateOf(true) }
    
        if (someCondition) rememberedFlag.value = false
      }
    }
    Edit: ^Actually works apparently
    z
    • 2
    • 2
  • k

    Kirill Grouchnikov

    11/17/2020, 5:27 AM
    After filing https://github.com/JetBrains/compose-jb/issues/108 I took a look at the implementation of
    ImageAsset
    as
    AndroidImageAsset
    and how it's painted in
    AndroidCanvas.drawImage
    - where it is explicitly checked to be an
    AndroidImageAsset
    . So even though
    Canvas.drawImage
    accepts
    ImageAsset
    , it's going to accept a very specific implementation of that interface - one on Android and one on desktop. Is there a way to create an
    ImageAsset
    at runtime dynamically? Not from a resource, not from a file, but by populating each pixel individually as an int array, and then "wrapping" that array as an implementation of
    ImageAsset
    that is platform agnostic?
    n
    • 2
    • 2
  • k

    Kirill Grouchnikov

    11/17/2020, 5:37 AM
    There are examples of creating an empty
    ImageAsset
    and drawing on it - such as
    ImageAssetSample
    , but it's a chicken-and-egg problem. In order to be able to draw a dynamic "bitmap" onto it, such a bitmap would first need to already exist.
    n
    • 2
    • 5
  • m

    Mehdi Haghgoo

    11/17/2020, 5:47 AM
    What is wrong with this animation? It is supposed to change size to 100.dp when clicked but does nothing.
    val size1 = animate(300.dp)
    val size2 = animate(100.dp)
    
    var aSize by mutableStateOf(size1)
    Image(vectorResource(id = R.drawable.video), modifier = Modifier.size(aSize).clickable(onClick = { aSize = size2 }).background(Color.Red))
    g
    • 2
    • 2
  • a

    allan.conda

    11/17/2020, 6:43 AM
    I haven’t used compose navigation yet, but for those who are, does it prevent accidentally navigating to multiple destinations at a time? For example, a button that navigates to another screen is clicked multiple times, or multiple buttons navigating to different destinations are clicked at the same time. In pre-Compose multiple Activity approach this problem doesn’t happen as the input is blocked when you start an activity immediately on click. Wondering if I need to debounce all my navigation clicks.
    👍 2
    i
    • 2
    • 1
  • m

    Mehdi Haghgoo

    11/17/2020, 11:27 AM
    Is this correct?
    A MutableState only lasts in a single composition and it is lost in the next composition unless we remember it with
    remember
    .
    :yes: 4
    j
    l
    • 3
    • 2
  • n

    nonameden

    11/17/2020, 11:28 AM
    Sorry if this question already been asked, but is it possible to run latest compose alpha with AGP 4.1.1? decided to upgrade from alpha03 to alpha07 but gradle can’t resolve compose-compiler-1.0.0-alpha07 =(
    m
    j
    l
    • 4
    • 7
  • m

    manueldidonna

    11/17/2020, 11:50 AM
    savedInstanceState
    doesn't work in a NavHost. This sample will always print '1'. Am I doing something wrong?
    NavHost(navController, startDestination = "search") {
        composable("search") {
            var counter by savedInstanceState { 0 }
            counter += 1
            Log.d("counter", counter.toString())
        }
    }
    😮 1
    i
    h
    • 3
    • 11
  • c

    ciscorucinski

    11/17/2020, 12:39 PM
    So I am going over a few YouTube tutorials on YouTube. The issue is that Compose is in Alpha and changing. Where can I find what is the most up to date info on component properties? I noticed that on
    OutlinedButton
    we can no longer set
    backgroundColor
    or
    contentColor
    and I am no sure of how to do this. I also noticed that
    verticalGravity
    is gone, but it has been replaced with
    verticalAlignment
    . While that was slightly obvious using auto-completion, I can't find the color properties. Or how I might navigate how to find these changed properties in the future. It seems
    colors
    is something I have to look at, but I am not sure how to execute this in code yet
    s
    l
    • 3
    • 6
  • c

    Chethan

    11/17/2020, 12:58 PM
    How to give Line Spacing for Text view in Compose ?
    v
    • 2
    • 1
  • o

    Omar Miatello

    11/17/2020, 3:13 PM
    I’m trying to enable Compose only on one module of my application, but to do that I need to use the latest version of the Android Gradle plugin. I tried with this:
    buildscript {
        configurations.all {
            resolutionStrategy { force 'com.android.tools.build:gradle:4.2.0-alpha16' }
        }
    }
    but didn’t work 😞 Do you know a solution to enable Compose on a single module?
    b
    a
    +2
    • 5
    • 13
  • t

    Tony Mykhaylovsky

    11/17/2020, 4:27 PM
    Besides using a view model, how can I set a State variable from a child View?
    s
    z
    +4
    • 7
    • 25
Powered by Linen
Title
t

Tony Mykhaylovsky

11/17/2020, 4:27 PM
Besides using a view model, how can I set a State variable from a child View?
I have a boolean defined as isMap and it's set to false by default. I would like to be able to change that to true from a child view. In SwiftUI, this can be accomplished by creating a binding object on the child view. Not sure how to do it in Jetpack Compose. THANK YOU!
s

Se7eN

11/17/2020, 4:31 PM
@Composable
fun Parent() {
    var state by remember { mutableStateof(false) }
    Child(onSomeEvent = { state = true })
}

@Composable
fun Child(onSomeEvent: () -> Unit) {
    Button(onClick = onSomeEvent)
}
☝️ 4
t

Tony Mykhaylovsky

11/17/2020, 4:32 PM
Wow - so you have to define the function in the parent and pass the event. Otherwise, a viewModel is the alternative?
z

Zach Klippenstein (he/him) [MOD]

11/17/2020, 4:33 PM
Using callbacks to avoid data dependencies between components like that is the recommended best practice.
j

Javier

11/17/2020, 4:33 PM
@Tony Mykhaylovsky I think it is better if you pass the actions to the childs and you keep the ViewModel at the parent
p

ppvi

11/17/2020, 4:33 PM
a viewModel is a less preferable alternative
z

Zach Klippenstein (he/him) [MOD]

11/17/2020, 4:34 PM
You could also do something like pass a
MutableState
down to your child and have the child mutate the state itself, but that increases coupling and is considered more of a bad practice.
a

Adam Powell

11/17/2020, 4:35 PM
if you find you need that kind of guaranteed-synchronous behavior it's often better to define an object or interface you pass to the composable
passing
MutableState<MyData>
around is kind of like passing around
Pair<Foo, Bar>
instead of defining a data class for the abstraction you're trying to represent with it
p

ppvi

11/17/2020, 4:36 PM
I think they're just trying to type less Adam 😁
a

Adam Powell

11/17/2020, 4:36 PM
always 😛
I'm foreshadowing some of the work going into `TextField`s at the moment
t

Tony Mykhaylovsky

11/17/2020, 4:41 PM
Very helpful - thank you all
So if I have a busy Child View, it could potentially have 5 parameter functions?
j

Joost Klitsie

11/17/2020, 4:44 PM
you could make your view composable as well
p

ppvi

11/17/2020, 4:44 PM
you can group them in something called
actions
🔝 1
t

Tony Mykhaylovsky

11/17/2020, 4:44 PM
Both parent and child are composable
j

Joost Klitsie

11/17/2020, 4:45 PM
@Composable
fun parent() {
    childContainer(...paremeters) {
         SomeOtherComposable()
    }
}

@Composable
fun childContainer(...paremeters, children: @Composable () -> Unit) {
     SpecialStuff()
     children()
}
t

Tony Mykhaylovsky

11/17/2020, 4:46 PM
Overwhelming amount of help - thank you 🙂
j

Joost Klitsie

11/17/2020, 4:46 PM
I mean if you want to adjust behavior of the child in many ways, you might just want to extract some basic behavior in a child and simply pass on more children to the child, I think this was explained in some interesting video
lemme check it

https://www.youtube.com/watch?v=SMOhl9RK0BA▾

here we go, around 8:50
z

Zach Klippenstein (he/him) [MOD]

11/17/2020, 4:48 PM
To group them, like Adam suggested:
class YourComplicatedState {
  private val _foo: MutableState<Foo> = mutableStateOf(…)
  private val _bar: MutableState<Bar> = mutableStateOf(…)
  val foo: State<Foo> = _foo
  val bar: State<Bar> = _bar

  fun doSomeAction() {
    _foo.value = …
    _bar.value = …
  }
}

@Composable
fun Parent() {
    var state by remember { YourComplicatedState() }
    Child(state)
}

@Composable
fun Child(state: YourComplicatedState) {
    Button(onClick = { state.doSomeAction() })
}
☝️ 1
t

Tony Mykhaylovsky

11/17/2020, 4:48 PM
That's great - thank you
View count: 1