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

    Noé Casas

    01/20/2021, 7:35 AM
    Is it Ok to use non-local state from a Composable function? An example would be a Composable that shows a Text with a String taken from a 
    MutableState
     stored as a member of an object retrieved through an Ambient, like this:
    data class ServiceX (
       val whateverString: MutableState<String>("meow")
    )
    
    
    @Composable
    fun Whatever() {
       val serviceX = AmbientServiceX.current
       Text(serviceX.whateverString)
    }
    Will the Composable function repaint when 
    whateverString
     changes? Are there any problems with this?
    j
    a
    10 replies · 3 participants
  • c

    Cyril Find

    01/20/2021, 9:35 AM
    Hi, I have a preview composable defined like this:
    @Preview
    @Composable
    fun PostHeader_Preview() {
        MyAppTheme {
            PostHeader(Post.PLACEHOLDER)
        }
    }
    that has a render problem that looks like this:
    java.lang.NoSuchMethodException: com.example.myapp.components.PostHeaderKt.PostHeader_Preview
    (full stacktrace in thread :thread-please: ) I have no idea how to fox that since the method actually exists, what can I do ?
    j
    j
    4 replies · 3 participants
  • a

    Ahmet Delibaş

    01/20/2021, 1:53 PM
    I have a state
    var current by remember { mutableStateOf(0) }
    after any change on current value, AndroidView component does not recompose. Does anybody know the answer? How can I update the AndroidView() part?
    a
    9 replies · 2 participants
  • v

    Vitor Prado

    01/20/2021, 3:36 PM
    which theme should be used in manifest? I need to create a light and a dark theme in xml too? or compose has a default for that?
    o
    a
    +2
    8 replies · 5 participants
  • o

    Oussama Haff.

    01/20/2021, 3:52 PM
    Hello 👋 What is the best way/practice to change the color of the ripple effect in default Material Buttons ? Knowing that what I have done in this example doesn’t work because internally in the
    Button
    Composable, the
    indication
    modifier is set to
    .indication(interactionState, AmbientIndication.current())
    or should I build my own Button to have control over the indication ?
    b
    2 replies · 2 participants
  • s

    Shakil Karim

    01/20/2021, 7:09 PM
    Is there any Pull to refresh Composable?
    👀 2
    ✅ 1
    c
    1 reply · 2 participants
  • h

    Hallefy

    01/20/2021, 7:36 PM
    Hi guys, anyone are using Compose in production ? im ask because on my team we are thinking if we use in production or not.. if anyone is using, are having some troubles, or crashs ?
    m
    a
    +2
    6 replies · 5 participants
  • l

    Lilly

    01/20/2021, 8:25 PM
    Wrong title on android libraries documentation page detected. @Adam Powell @jim https://developer.android.com/jetpack/androidx/releases/compose-compiler
    j
    1 reply · 2 participants
  • l

    Lilly

    01/20/2021, 8:33 PM
    Sorry wasn't sure how to inform about this. Whats the right way?
    h
    j
    +1
    5 replies · 4 participants
  • t

    Tony Kazanjian

    01/20/2021, 10:16 PM
    Hello folks. I'm wondering if anyone might have a more elegant solution to handling focus for multiple TextFields when triggering the ImeAction. I basically have a column of TextFields, and it seems like each field in the column scope must have its own
    FocusRequester
    . But perhaps
    FocusOrderModifier
    is what this is for...anyone have an example of how to use that? Here's what I have working so far:
    val firstNameFocus = remember { FocusRequester()}
        val lastNameFocus = remember { FocusRequester() }
        val emailFocus = remember { FocusRequester() }
        val passwordFocus = remember{ FocusRequester() }
    
        Column(Modifier.padding(16.dp)) {
            onActive {
                firstNameFocus.requestFocus()
            }
            CommonTextField(
                value = firstName,
                onTextChange = onFirstNameChange,
                modifier = Modifier.padding(8.dp).fillMaxWidth().focusRequester(firstNameFocus),
                label = { Text("First Name") },
                onImeAction = {lastNameFocus.requestFocus()}
            )
            CommonTextField(
                value = lastName,
                onTextChange = onLastNameChange,
                modifier = Modifier.padding(8.dp).fillMaxWidth().focusRequester(lastNameFocus),
                label = { Text("Last Name") },
                onImeAction = {emailFocus.requestFocus()}
            )
    
            CommonTextField(
                value = email,
                onTextChange = onEmailChange,
                modifier = Modifier.padding(8.dp).fillMaxWidth().focusRequester(emailFocus),
                label = { Text("Email") },
                onImeAction = {passwordFocus.requestFocus()}
            )
            PasswordTextField(
                value = password,
                onTextChange = onPasswordChange,
                modifier = Modifier.padding(8.dp).fillMaxWidth().focusRequester(passwordFocus),
                label = { Text("Password") },
                isPasswordVisible = remember { mutableStateOf(true) },
                onImeAction = {viewModel.registerUser(firstName, lastName, email, password)}
            )
    m
    s
    +1
    4 replies · 4 participants
  • a

    Alexa_Gal

    01/21/2021, 12:24 AM
    Hi guys What are some good practices for keeping code readable and simple when styling Views. i come from RN and getting each day in love with Android Compose. what im exactly looking for is a way to keep the modifiers in one place. in react native i would do something like
    const styles = StyleSheet.create({
    contaienr: {
    ....
    ...
    ...
    },
    box: {
    ...
    ...
    }
    })
    is there any good practice to do this with android compose?
    👍 1
    g
    11 replies · 2 participants
  • l

    Lilly

    01/21/2021, 1:18 AM
    It seems that
    Icon
    can't be resized:
    Icon(
    	imageVector = Icons.Default.SentimentVerySatisfied,
    	modifier = Modifier.size(40.dp) // has no effect
    )
    Image on the other hand works. It's a bit confusing when to use
    Icon
    and when
    Image
    .
    ImageVector
    ,
    ImageBitmap
    Painter
    makes it even more confusing. Can someone enlighten me here please?
    v
    c
    3 replies · 3 participants
  • l

    Lauren Yew

    01/21/2021, 1:30 AM
    Hi all, for
    LazyColumn
    , I want to hide things if I’ve scrolled on my list. I’ve tried
    LazyListState
    , but nothing is jumping out to me. Do we have an API to do this?
    c
    2 replies · 2 participants
  • l

    Lauren Yew

    01/21/2021, 1:42 AM
    Does anyone know how far
    remember{…}
    can work on a list of Bitmaps? I was trying to use it to remember the state of a Bitmap I loaded from Picasso for list items, but scrolling back and forth on a list, I still see the bitmaps having to reload. Following example here: https://stackoverflow.com/questions/58594262/how-do-i-load-url-into-image-into-drawimage-in-compose-ui-android-jetpack
    val imageState = remember(id) { loadPicture(url = item.photoUrl) }
    private fun loadPicture(url: String?): State<ImageState> {
    val imageState: MutableState<ImageState> = mutableStateOf(ImageState.Empty)
    ... //Picasso
    }
    
    sealed class ImageState {
        data class Success(val image: Bitmap) : ImageState()
        object Failed : ImageState()
        object Loading : ImageState()
        object Empty : ImageState()
    }
    ➕ 1
    d
    j
    5 replies · 3 participants
  • f

    Fudge

    01/21/2021, 6:11 AM
    Is there a guide for using the Compose Compiler only for building tree-like structures? This example from 6 months ago is using a prebuilt "compose wrapper" to work: https://github.com/ShikaSD/compose-server-side/tree/master/compose-wrapper Is there any simpler way, idealy only requiring adding dependencies in build.gradle?
    ➕ 1
    1 reply · 1 participant
  • n

    Noé Casas

    01/21/2021, 9:14 AM
    Is there any pattern in Jetpack Compose to add actions to the
    TobAppBar
    from a Composable that does not have access to it? I am thinking in something like SwiftUI’s
    toolbar
    and
    ToolbarItem
    (e.g. see https://swiftwithmajid.com/2020/07/15/mastering-toolbars-in-swiftui/) . Also, is there a mechanism or pattern to set the `TopAppBar`’s title from somewhere else, like SwiftUI’s
    navigationTitle
    ?
    j
    k
    2 replies · 3 participants
  • j

    julioromano

    01/21/2021, 12:42 PM
    Question about recomposition granularity Given this composable with state:
    data class State(
        val firstCounter: Int = 0,
        val secondCounter: Int = 0
    )
    
    @Composable
    fun MyScreen(
        stateFlow: StateFlow<State>,
        onClick1: () -> Unit,
        onClick2: () -> Unit,
    ) {
        val state by stateFlow.collectAsState()
        Column {
            Button(onClick = onClick1) {
                Text(text = "One ${state.firstCounter}")
            }
            Button(onClick = onClick2) {
                Text(text = "Two ${state.secondCounter}")
            }
        }
    }
    If only one field of the
    state
    object changes will it trigger recomposition of only one (the one that’s reading that field) or both buttons ? Can someone point to some docs or examples to learn a bit more how recomposition actually works? :thank-you:
    :thank-you: 1
    k
    a
    +1
    29 replies · 4 participants
  • j

    Jakub Ledwon

    01/21/2021, 8:09 PM
    Is there any out of the box solution for handling long press on button, and for handling long presses in general? I've found
    LongPressTimeout
    , but can't find any example of it being used, have anyone tried it and could share some experience?
    👀 1
    i
    a
    +1
    5 replies · 4 participants
  • l

    Logan Knight

    01/21/2021, 9:19 PM
    My intuition is failing me. I'm not sure if this is a bug in desktop, or a failure of my understanding. See thread.
    z
    a
    14 replies · 3 participants
  • l

    Lilly

    01/22/2021, 3:25 AM
    Can we avoid using xml files for theming like colors.xml, theme.xml in the near future? Currently theming is a mix of xml and
    MaterialTheme
    composable. Another question would be if we can set the color of the system bar via compose or is it only via theme.xml possible?
    a
    c
    +1
    15 replies · 4 participants
  • r

    rnett

    01/22/2021, 7:41 AM
    Is there any support for popups or tooltips from AnnotatedString, or from text in general? For Desktop, specifically, but it seems like it would be a general compose API and thus more appropriate here. I looked into rolling my own, but the closest thing I could find is SelectionHandle & related things, but most of it relies on private stuff.
    j
    3 replies · 2 participants
  • p

    pawegio

    01/22/2021, 8:49 AM
    I’m used to extracting navigation logic from android layer (hiding the impl details behind the interface), but I decided to give compose navigation a try. That involves tight coupling of navigation with the ui, triggering navigation from callbacks inside composable functions. I’m wondering if effects such as
    onDispose()
    are safe to perform such action or it’s rather considered as an anti-pattern/might lead to unexpected state (is there a risk of recomposition causing not intended navigation?). See example code below (where
    isInProgress
    is a part of collected state
    false
    by default):
    if (isInProgress) {
        CircularProgressIndicator()
        onDispose {
            navigateToDone()
        }
    }
    j
    a
    6 replies · 3 participants
  • a

    allan.conda

    01/22/2021, 9:59 AM
    We’re getting this non-sensical crash. Just a wild guess that this is compose-related. Any ideas what could be the cause? This doesn’t crash on my environment, but it does from another computer.
    Caused by: java.lang.ClassNotFoundException: Didn't find class "com.example.SomeScreen.SomeScreenKt$SectionTitle$1" on path: DexPathList[[zip
    Untitled.kt
    j
    2 replies · 2 participants
  • i

    Ian Warwick

    01/22/2021, 10:20 AM
    Morning composers, I got a
    Box
    in a
    Box
    and I want to offset the inner box by
    x
    dps from the left, I tried left padding and offset though nothing seems to work
    Box(Modifier.background(Color.Red).width(128.dp).height(128.dp)) {
            Box(Modifier.background(Color.Green).width(32.dp).height(128.dp)) {
    
            }
        }
    I want the inner box to have some space on the left hand size that I can specify hope that makes sense
    a
    21 replies · 2 participants
  • v

    vipulasri

    01/22/2021, 11:56 AM
    Is compose compatible with android wear?
    b
    2 replies · 2 participants
  • v

    Vivek Sharma

    01/22/2021, 12:55 PM
    How can we make date picker in compose, Is there a way to do it?
    l
    k
    3 replies · 3 participants
  • l

    Logan Knight

    01/22/2021, 1:47 PM
    From the docs over the
    Surface
    dec:
    Elevation: Surface elevates its children on the Z axis by elevation pixels, and draws the appropriate shadow.
    Does that mean that the
    Surface
    sets the
    Modifier.zIndex()
    value of all it's children?
    a
    2 replies · 2 participants
  • j

    Jason Ankers

    01/22/2021, 1:54 PM
    Does State/SharedFlow work well in compose? Does anyone have any experience using these over LiveData in a compose app?
    :yes: 3
    j
    1 reply · 2 participants
  • p

    Pablo Costa

    01/22/2021, 2:45 PM
    Hi there! 👋 This maybe an x-y question but... If I have this:
    Modifier
        .fillMaxWidth()
        .padding(horizontal = 16.dp, vertical = 8.dp)
    And want to keep the 
    fillMaxWidth
     down the chain but remove the padding, is that possible? Thanks!!!
    j
    2 replies · 2 participants
  • a

    alorma

    01/22/2021, 3:52 PM
    Hi. Just a dummy question... is there any tutorial on how to convert a compose projecte to a compose-desktop one?
    o
    a
    +1
    10 replies · 4 participants
Powered by Linen
Title
a

alorma

01/22/2021, 3:52 PM
Hi. Just a dummy question... is there any tutorial on how to convert a compose projecte to a compose-desktop one?
o

olonho

01/22/2021, 4:18 PM
probably more relevant for #compose-desktop, but IIRC @Arkadii Ivanov did it for TODO app, which become one of Compose for Desktop demos: https://github.com/JetBrains/compose-jb/tree/master/examples/todoapp. Also note, that you not have to convert, you could keep both.
a

alorma

01/22/2021, 4:45 PM
thanks, do I need IntelliJ to test it? not works with AS
a

Arkadii Ivanov

01/22/2021, 5:00 PM
I'm using Android Studio Beta currently for Desktop Compose. It works just fine. The TODO example was always multiplatform. It was using Jetpack Compose + SwiftUI. Its original location was in the Decompose repository. Then based on the existing example, I created a new one in the JB Compose repository. It had only Android and Desktop targets with shared UI. And later I added the iOS app with SwiftUI.
a

alorma

01/22/2021, 5:03 PM
i don't see the run on desktop
a

Arkadii Ivanov

01/22/2021, 5:09 PM
There should be
./gradlew :desktop:run
task, it can also be launched from AS
a

alorma

01/22/2021, 5:11 PM
oh, ok not from selector then
I Not see the option from As
a

Arkadii Ivanov

01/22/2021, 5:15 PM
AFAIK there is no option in the dropdown menu, but you can use
Gradle
panel on the right side of the screen
a

alorma

01/22/2021, 5:18 PM
thks. Following the example from repo above, i got this :S
s

Sebastian Sellmair [JB]

01/24/2021, 8:07 PM
this: KotlinAndroidProjectExtension
implies, that you applied the Kotlin Android Gradle Plugin. If you want to opt into MPP, you would like to use
kotlin("multiplatform")
instead!
View count: 1