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

    therealbluepandabear

    03/13/2021, 5:37 AM
    If you want to join my #androidui channel please do so - I am looking for new people that are eager to share their ui to join. Cheers,
    👎 4
    👍 1
    🤦 2
    a
    j
    k
    • 4
    • 3
  • j

    jaqxues

    03/13/2021, 9:41 AM
    Is it possible to use Compose without an AppCompatActivity, and just
    android.app.Activity
    ? I see that it requires a
    ViewTreeLifecycleOwner
    , which can be instantiated and set manually. However the
    ViewTreeSavedStateRegistryOwner
    cannot be instantiated, so it must be used with an AppCompatActivity, right? Is there any way for me to get a
    ViewTreeSavedStateRegistryOwner
    without AppCompatActivity or get Compose (specifically
    ComposeView
    , which checks for these) to work?
    l
    g
    m
    • 4
    • 10
  • l

    Lauren Yew

    03/13/2021, 11:19 AM
    Hi all, I'm trying to import a library with Jetpack compose
    1.0.0-beta01
    (Android Gradle plugin 7.0.0-alpha09) into an app that doesn't have jetpack compose and android gradle plugin 4.1.0. I'm getting an error
    java.lang.NoClassDefFoundError: Failed resolution of: Landroidx/compose/runtime/internal/ComposableLambdaKt;
    when I try to open up my compose views from the library. Has anyone seen this kind of issue before / know a fix? I thought compose could be used in a library only and then not be required for the app (my client app has product requirements limiting it from updating the AGP / going to compose).
    s
    a
    c
    • 4
    • 10
  • g

    Gabriel

    03/13/2021, 12:09 PM
    Hey folks, is there an easy way to say tell a Button to use secondary colours without having to go through and define all the properties for ButtonColors ?
    j
    s
    • 3
    • 2
  • m

    mannodermaus

    03/13/2021, 1:37 PM
    Is it a known issue that TextField icons and text are impossible to align to a common baseline, or am I missing an obvious API here? This icon is centered correctly, but the text is way too far up. I’ve seen the same thing on all the submissions to the Compose Challenge that I came across on Twitter, so I’m wondering if it might be a problem with the custom font
    ☝️ 4
    b
    s
    • 3
    • 4
  • y

    Yasin Kaçmaz

    03/13/2021, 3:58 PM
    Hey folks, I am using Compose version
    1.0.0-beta02
    and
    MaterialTheme.colors.isLight
    does not change when we give light and dark themes with a Boolean mutable state. It was working before. Is there anyone else with the same situation.
    ➕ 1
    m
    l
    s
    • 4
    • 20
  • s

    Shakil Karim

    03/13/2021, 4:07 PM
    Is there any difference between usage of remember below ?
    @Composable
    fun ClubItem(club: Club,
                 selectedClubs: List<Club> = emptyList(),
                 onItemClicked: (Club) -> Unit) {
        val isSelected by remember { derivedStateOf { selectedClubs.contains(club) } }
    }
    
    @Composable
    fun ClubItem(club: Club,
                 selectedClubs: List<Club> = emptyList(),
                 onItemClicked: (Club) -> Unit) {
        val isSelected by remember { mutableStateOf(selectedClubs.contains(club)) }
    }
    a
    • 2
    • 9
  • a

    Afzal Najam

    03/13/2021, 4:16 PM
    Is there a difference between
    fillMaxSize()
    and using
    fillMaxHeight().fillMaxWidth()
    ?
    a
    • 2
    • 2
  • a

    alorma

    03/13/2021, 4:54 PM
    Hi. Dummy question: This week dev challenge asks to create a typography in CAPS, is there a way to do that, without set the
    "".toUpperCase()
    ?
    ➕ 3
    a
    • 2
    • 1
  • s

    Slackbot

    03/13/2021, 6:54 PM
    This message was deleted.
    a
    l
    • 3
    • 3
  • s

    Se7eN

    03/13/2021, 7:02 PM
    Does anyone experience random crashes on a compose app? My app crashes randomly like I have my app running on the emulator and then I switch to Android Studio to write some code, then when I switch back to the emulator I find out the app has been crashed already and there's no error in logcat. Sometimes it crashes while navigating the app too. This might be an issue with the emulator and not compose related but I've only experienced it in compose apps.
    🇳🇴 1
    :yes: 4
    e
    r
    a
    • 4
    • 4
  • n

    Noop

    03/13/2021, 8:54 PM
    ScrollableColumn or ScrollableRow function is delete? https://developer.android.com/reference/kotlin/androidx/ui/foundation/package-summary#scrollablerow
    g
    • 2
    • 3
  • j

    Jan Skrasek

    03/14/2021, 12:16 AM
    I have a Row with elements with different heights. How can I say, that one row element should have the max. available height of the Row (i.e. the maximum of inner element heights)? Something like "matchParentHeight".
    Row {
        Column() { ... }
        Column(Modifier.matchParentHeight()) { ... }
    }
    a
    n
    • 3
    • 2
  • f

    fal

    03/14/2021, 3:07 AM
    Hi, I'm learning compose and I come from a background where I like the redux way of doing things. So I normally would have an immutable data class describing the state of the whole screen, and this up-to-date state would be exposed through StateFlow to the view side. So I've tried to keep doing that here and I have something like this
    @Composable
    fun HelloScreen(helloViewModel: HelloViewModel = viewModel()) {
        val state: HelloState by helloViewModel.stateFlow.collectAsState(initialState)
        Column {
            Text(state.title)
            SomeStatelessComponent(state.componentValue)
            SomeOtherStatelessComponent(state.otherComponentValue)
            ...
        }
    }
    The idea is that every composable used in HelloScreen are simply stateless composables. My worry is that this won't work out great if compose simply does a reference check (===) instead of an equals to check if it should recompose these stateless composables. If compose simply does a reference check, I see three ways out of this: • Wrapping every object in this state class in mutableStateOf and adjust the reducer on the viewmodel side -> seems terrible, does this even work? • Having a stateflow per state value -> seems clunky if your screen has a lot of state properties. • Orrr find a way to selectively "subscribe" to the stateFlow properties, like
    stateFlow.map { state -> state.componentValue }.distinctUntilChanged()
    Is this okay? I'm up for other ideas
    a
    j
    • 3
    • 10
  • p

    prudhvi reddy

    03/14/2021, 6:44 AM
    frames skipping a lot with simple textfield and remember
    a
    • 2
    • 1
  • d

    david.bilik

    03/14/2021, 7:02 AM
    Hello, is there a way how to absolutely position child composable within
    Box
    ? I have a code like this
    @Preview("Positioning", widthDp = 300, heightDp = 300)
    @Composable
    fun Positioning() {
        Box(
            modifier = Modifier.size(300.dp)
                .background(Color.Blue)
        ) {
            Box(
                modifier = Modifier.size(20.dp)
                    .background(Color.Red)
                    .absoluteOffset(20.dp, 20.dp)
            )
        }
    }
    and I’d like to position inner
    Box
    but the result is not positioned. I know that it does not make sense probably to apply offset to
    Modifier
    of inner
    Box
    because I’d need to affect outer
    Box
    somehow but I did not find a way how to position just a single child. I know I can achieve it easily with Canvas drawing but I’m just thinking what if I’d want to position some other
    Composable
    . Thanks
    r
    • 2
    • 2
  • m

    Mel D.

    03/14/2021, 9:51 AM
    Hi! I’m trying to build a row similar to this one(img below): If I use two harcoded strings it works just fine, but in my case, I obtain the first string from the activity intent and the second one from string resources. I don’t get why, when I do so, it breaks the UI. Only the first string is shown, and the rest of the elements of the screen move down a bit. I’m doing it this way because the second string should be clickable and in a different colour. There are probably different ways of doing this, but I can’t see what I am doing wrong here.
    @Composable
      fun Subtitle(modifier: Modifier = Modifier, first: String, second: String) {
        Row(modifier = modifier.padding(8.dp)) {
          Text(
            text = first,
            color = colorResource(id = R.color.textLight),
            fontSize = 16.sp
          )
          Text(
            modifier = modifier.padding(start = 2.dp),
            text = second,
            color = colorResource(id = R.color.textBrand),
            fontSize = 16.sp
          )
        }
      }
    Subtitle(first = args.summary, second = stringResource(R.string.general_more_info))
    p
    • 2
    • 2
  • n

    Nat Strangerweather

    03/14/2021, 10:36 AM
    Is it possible to apply different styles (e.g. colour) to each word of a given String? I have turned the String into a list of words like this:
    val convertedString = textState.value.text.splitToSequence(' ')
            .filter { it.isNotBlank() }
            .toList()
    But I can't find how to differentiate the words to decorate them differently:
    Text(textState.value.text,  style = TextStyle(color = listOfColors.random()))
    j
    m
    • 3
    • 7
  • m

    Mjahangiry75

    03/14/2021, 11:56 AM
    hey I'm building an editor toolbar so I need to pass
    MaterialTheme.Typography
    through
    data class
    property
    and it's not possible because the
    MaterialTheme.Typography
    is a
    Composable
    so we can't use it in
    non-composable
    . and now the question is how can I achieve that? the code is in thread to take less space.
    • 1
    • 1
  • s

    Shakil Karim

    03/14/2021, 12:28 PM
    I'm using graphicsLayer to update the alpha of composable while scrolling. But it causing performance issue. Is it a know issue?
    a
    • 2
    • 11
  • c

    curtjrees

    03/14/2021, 1:54 PM
    I just wanted to sense check my usage of
    BoxWithConstraints
    Feels I might need to use a Layout/SubcomposeLayout instead, but I’m not sure I’m using the maxWidth and maxHeight to calculate sizes and positions for items on a “grid”
    a
    • 2
    • 9
  • o

    oday

    03/14/2021, 2:41 PM
    staticAmbientOf
    as well
    j
    • 2
    • 6
  • g

    grandstaish

    03/14/2021, 2:55 PM
    I have a noob contributor question. Trying to play with the compose codebase to debug an issue I’ve found. In order to reproduce it, I’m trying to add
    dev.chrisbanes.accompanist:accompanist-insets:0.6.2
    to
    :compose:foundation:foundation-layout:build.gradle
    . I’ve added it to both
    androidTestImplementation
    for non-MPP builds, and to
    androidAndroidTest.dependencies
    for MPP builds. After a Gradle sync, I still can’t reference accompanist insets in
    BoxTest.kt
    . What am I missing?
    i
    • 2
    • 4
  • s

    Shawn Tucker

    03/14/2021, 3:57 PM
    Is there a way to disable "elevation overlays" for darkColors theme?
    s
    o
    • 3
    • 2
  • c

    Colton Idle

    03/14/2021, 4:41 PM
    My activity is just made up of MyComposablePage but it still has the default Material colors (purple) even though in the Manifest I set the app theme to my typical app theme where the primary color is green. I would have thought that that should work, but it doesn't? Should I file a bug or is that working as expected and I need to pass the theme into my composable page?
    t
    • 2
    • 1
  • t

    Tash

    03/14/2021, 5:22 PM
    Hi y'all. What's the guidance for picking
    mutableStateListOf<Item>()
    vs
    mutableStateOf<List<Item>>()
    ? Trying to assess stability/performance in the case of a
    List
    (size ~200) that will undergo random removals/insertions (that will be either displayed in a
    LazyColumn
    or
    LazyGrid
    )
    a
    • 2
    • 2
  • j

    jaqxues

    03/14/2021, 5:27 PM
    I have a TransformableState that is used for zooming and moving an image around freely. How would I optimally measure the image location so it does not get moved outside of the window and change the pan/offsets of the transformableState so this does not happen. I have the Modifier.onGloballyPositioned which gives me the LayoutCoordinates. How can I get the Window size to calculate by how much i need to change the offsets (or are there better approaches?)
    a
    t
    t
    • 4
    • 10
  • h

    Halil Ozercan

    03/14/2021, 6:46 PM
    I'm trying to fully understand
    composed
    modifier that is used for custom stateful modifiers. My first question is what are the limitations around it? It's a compose function so it lets me call any other composable function that may or may not emit widgets. For example it makes sense to use
    remember
    but it's a little strange calling
    Box
    .
    a
    z
    • 3
    • 6
  • m

    mbonnin

    03/14/2021, 8:30 PM
    Is try/catch supported in
    @Composables
    now? I tried using
    runCatching
    and I got a weird error where the result was interpreted as a
    T
    (and not a
    Result<T>
    , see screenshot the debugger sees two types for the same lvalue ?!?). I ended up using try/catch and now it's all working but searching the backlog of this channel (https://kotlinlang.slack.com/archives/CJLTWPH7S/p1603737209131700), it looks like this might be dangerous?
    j
    • 2
    • 11
  • c

    Colton Idle

    03/15/2021, 12:48 AM
    I'm looking for a way to show a Modal BottomSheet in a way that doesn't force it to be in my view hierarchy in any way. I'm currently using ModalBottomSheetLayout but that does show in LayoutInspector, so I'm curious if I can use Compose to do that. If not and I really want a modal (different Window) then I suppose the only thing left to do is use https://material.io/develop/android/components/bottom-sheet-dialog-fragment ?
    i
    s
    +2
    • 5
    • 15
Powered by Linen
Title
c

Colton Idle

03/15/2021, 12:48 AM
I'm looking for a way to show a Modal BottomSheet in a way that doesn't force it to be in my view hierarchy in any way. I'm currently using ModalBottomSheetLayout but that does show in LayoutInspector, so I'm curious if I can use Compose to do that. If not and I really want a modal (different Window) then I suppose the only thing left to do is use https://material.io/develop/android/components/bottom-sheet-dialog-fragment ?
i

Ian Lake

03/15/2021, 1:31 AM
I'm getting some vibes of https://xyproblem.info/ - can you explain what problem you're trying to solve?
➕ 1
c

Colton Idle

03/15/2021, 1:34 AM
I've been using a debug drawer as shown in Jake Wharton's u2020 https://github.com/JakeWharton/u2020 but having the drawer in my view hierarchy has given me a few issues in terms of view focus (android tv and a11y). Now that I'm moving my app to Compose I want to show a debug drawer in a new "Window" so that it's completely isolated. So I'm considering dropping my debug drawer into a bottom sheet modal.
i

Ian Lake

03/15/2021, 1:43 AM
What makes you think those view focus issues exist in Compose? Wouldn't you rather those problems be fixed rather than warp the structure of your app?
s

Shakil Karim

03/15/2021, 5:40 AM
You can create your own bottomsheet layout, and put condition to show or hide that ways it will not shows in LayoutInspector when it's hidden.
a

alorma

03/15/2021, 6:30 AM
Need a debug drawer?
https://github.com/alorma/Compose-Debug-Drawer
c

Colton Idle

03/15/2021, 9:17 AM
@ Ian, I guess the ask from my team has really been "Hey, we have a debug drawer and it messes with our testing during development time because it sometimes gives different results than our release builds. Wouldn't it be nice if we didn't have this debug drawer that sits in our view hierarchy" I can definitely see this being an xy problem, but I still think it's somewhat valid to ask if there is any way to show a proper modal/Dialog (whatever opens in a separate Window) with the bottom sheet apis in Compose or do I have to go the route doing that via the view based system.
j

jossiwolf

03/15/2021, 9:56 AM
I totally agree, there should be a way to show a bottom sheet globally. I think what I'm working on rn should help you, but not sure when it's done as I'm only doing it on the side
@Colton Idle I think essentially you'd want something like this: https://gist.github.com/jossiwolf/0b319eb45a93db5ced91365b277867e4 Only with code that is... not that code😄
c

Colton Idle

03/15/2021, 10:59 AM
OooOh! Thanks Jossi. Yeah. We might be going a little off of the path of where I originally brought this question up (and hence Ians concern of "what am I actually trying to do") but the fact that I need to have a bottom sheet as the root composable just doesn't feel right. I thought there would be a way to just somehow show a modal. Not sure how "dialogs" work in compose yet, but maybe I should try that too.
This sentence particularly from material docs really sells me on completely getting rid of
Dialogs
in my app and just replacing it with bottom sheet dialogs (if there was an easy way to go about it)
`BottomSheetDialogFragment`s are a more modern version of Dialogs. They have a nicer-looking entrance animation and since they are pinned to the bottom they may feel easier to use on larger devices.
j

jossiwolf

03/15/2021, 11:22 AM
Yeah, I think Ian's first question is totally pushing you in the right direction This might just be a very special case where your host is variable depending on your root config (which you can do at a top level too, it's just harder/less nice)
s

Shakil Karim

03/15/2021, 11:25 AM
@Colton Idle I'm using Bottom Sheet as separate Composable, it's not pretty by no means. but I'm think creating custom Sheet is simple in Compose which I'm not using here. https://gist.github.com/shakil807g/451958e2cee0d26527467b8aba12c443
👍 1
c

Colton Idle

03/15/2021, 11:36 AM
@jossiwolf yeah for now I'm just using the view based
val bottomSheetDialog = BottomSheetDialog(this)
and it doesn't affect my current view hierarchy since it opens in a Window so I'll be using this for now. I hope that compose ends up having a solution for it so that i can ditch xml land completely.
j

jossiwolf

03/15/2021, 11:56 AM
@Colton Idle Yup, that probably makes the most sense for now. I'll ping you when I have a working (aka not crashing:blob-joy:) prototype for it, shouldn't be long 🙂
👍 3
View count: 1