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

    Didier Villevalois

    01/16/2021, 9:57 AM
    Hi everyone! Is there a way to reuse the content of a Canvas component ? Canvas redraws fully at each re-composition. How should I proceed if I wanted to draw above currently drawn content and clear the canvas on-demand ? I am trying to make an oscilloscope-like gui from a stream of audio data. I want to draw the new content acquired between each animation frames (web lingo, sorry) and maybe clip/move the old content. Should I use an off-screen canvas ?
    t
    j
    +3
    • 6
    • 97
  • v

    Vsevolod Ganin

    01/16/2021, 1:45 PM
    I wonder why the
    matchParentSize
    modifier is available only in
    BoxScope
    ? It could be useful in any layout scope I think, as well as
    matchParentWidth
    and
    matchParentHeight
    ➕ 2
    t
    r
    a
    • 4
    • 12
  • t

    Timo Drick

    01/16/2021, 7:45 PM
    I want to draw an icon with a shadow. I think this is not possible out of the box yet. But maybe it is possible to create a component which draw its child vectorDrawable with a tint and scales it up a little bit and do a blur filter on it. Anyone tried this already?
    v
    • 2
    • 6
  • a

    aherbel

    01/16/2021, 7:53 PM
    I want to make that TextField the same height as the Icon in the left… this is what I have in my code right now, is there an easy way to do that? like an out of the box solution? I can’t find much examples or documentation on this
    t
    a
    • 3
    • 15
  • s

    Shakil Karim

    01/16/2021, 8:28 PM
    I'm using OutlinedTextField as follows but not sure why it crashes the app
    
    @Composable
    fun OutlinedTextFields() {
        val text = remember { mutableStateOf(TextFieldValue("Text")) }
        OutlinedTextField(
            modifier = Modifier.fillMaxWidth(),
            value = text.value,
            onValueChange = { text.value = it },
            label = { Text("Label") }
        )
    }
    s
    • 2
    • 2
  • h

    Halil Ozercan

    01/16/2021, 9:39 PM
    Hi everyone. Did anyone experience a problem with AndroidView in alpha10. I'd been using MapView successfully within an AndroidView in alpha09. However, alpha10 introduced a strange behavior in which the
    viewBlock
    is called whenever the state changes, instead of
    updateBlock
    . I double checked every state parameter that I use in
    viewBlock
    and confirmed that even if none of them changes,
    viewBlock
    still gets executed.
    j
    a
    +2
    • 5
    • 8
  • s

    spierce7

    01/16/2021, 11:55 PM
    Jetpack compose isn’t compatible with Android TV right?
    j
    t
    h
    • 4
    • 6
  • a

    Adriano Celentano

    01/17/2021, 12:28 PM
    what would be the most simple infinite loop for an infinite animation ? is it possible to animate without reading a state ?
    n
    a
    d
    • 4
    • 14
  • s

    Shakil Karim

    01/17/2021, 12:48 PM
    I'm getting an exception when using Dagger Hilt 2.31-alpha with NavHost is it a known issue? @Ian Lake java.lang.Class<com.facr.fotbal.ui.onboarding.OnboardingViewModel> has no zero argument constructor at java.lang.Class.newInstance(Native Method)
    val navController = rememberNavController()
    NavHost(navController = navController, startDestination = FacrScreen.OnboardingAddFavoriteTeam.route) {
        composable(FacrScreen.OnboardingAddFavoriteTeam.route) {
            OnboardingAddFavoriteTeamScreen(facrViewModel = facrViewModel)
        }
    }
    @HiltViewModel
    class OnboardingViewModel @Inject constructor(
            clubsRepository: ClubsRepository
    ) : ViewModel() {
    
        val state = MutableStateFlow(OnboardingState())
    
        init {
            viewModelScope.launch {
                clubsRepository.fetchAllClubs(ClubsPagingKey())
                        .cachedIn(viewModelScope).map {
                            OnboardingState(clubs = flowOf(it))
                        }.collect { state.value = it }
            }
        }
    
    }
    @Composable
    fun OnboardingAddFavoriteTeamScreen() {
        val onboardingViewModel: OnboardingViewModel = viewModel()
    }
    i
    • 2
    • 1
  • r

    Rick Regan

    01/17/2021, 5:49 PM
    I would like to put a contiguous overline over a series of characters in a Text() composable, like you would notate a repeating decimal. The only options for
    TextDecoration
    appear to be
    LineThrough
    ,
    Underline
    , and
    None
    . I tried putting "combining overline" unicode characters in the text but it puts an overline over each character, not one contiguous overline across all the characters. Is there a way to do this in Compose?
    j
    s
    • 3
    • 9
  • a

    aherbel

    01/17/2021, 9:33 PM
    Hi, I want to make a carousel that swipes the images in this fashion… I have a scrollable row and I was able to set the correct width and spacing for each item, but I don’t know how to observe the scroll direction in order to calculate the Y translation… is there a way to observe such event/s?
    f
    o
    • 3
    • 4
  • c

    Colton Idle

    01/17/2021, 9:38 PM
    Should text size in sp be defined in "odd" numbers (not multiple of 4/8)? I know this isn't necessarily a compose thing, but I think in the past @nickbutcher has mentioned to stick to 8pt/dp rhythym. But I'm working on a compose app with a new designer and they really want to use 13sp as a font size and I think that's wrong because it doesn't multiply all that great. I know material has its own type scale that uses multiples of 4/8 but is it like "oh please don't set 13sp as a font size" or am I making this out to be worse than it really is and my designer can have a 13sp text size if they want?
    i
    s
    • 3
    • 8
  • c

    Colton Idle

    01/18/2021, 2:31 PM
    First time playing around with creating a composable that has a "slot". (took me way longer than I'd like to admit that I had to call
    content()
    and not just
    content
    🙃 Does this seem fairly idiomatic?
    @Composable
    fun MyCustomContainer(header: String = "", content: @Composable () -> Unit) {
        Column() {
            if (header.isNotBlank()) {
                Text(text = header)
            }
            content()
        }
    }
    a
    • 2
    • 13
  • j

    Jakub Ledwon

    01/18/2021, 2:55 PM
    Hi, what is the correct way for setting a ripple color on a button at this moment? I have a black button and in light mode it has no ripple - likewise for white button in dark mode.
    b
    l
    +2
    • 5
    • 15
  • s

    Skolson5903

    01/18/2021, 8:15 PM
    Trying to do a unit test using alpha10 of compose and can't figure out where to import createAndroidComposeRule if it is still good stuff 🙂. It doesn't seem to be in
    androidx.compose.ui:ui-test:1.0.0-alpha10
    Last I see it anywhere is in androidx.ui:ui-test:1.0.0-alpha07. Does anyone have a sample unit test using this and at least alpha08 or later so I can see what I'm missing? Thanks in advance...
    v
    • 2
    • 2
  • b

    birdsofparadise

    01/18/2021, 8:54 PM
    abstract class ComposeAbstractTest {
        @Composable
        abstract fun createView()
    }
    
    class ComposeTest: ComposeAbstractTest {
        @Composable
        fun createView() {
            Column { }
        }
    }
    Hi is such a thing possible? I'm getting a runtime error with my provided example and my understanding of Compose it seems like this shouldn't be possible.
    a
    a
    +2
    • 5
    • 20
  • m

    Mehmet Peker

    01/19/2021, 2:33 AM
    Hi everyone.Im coding simple snake game with jetpack compose.Im trying this code to detect swipe direction.But i cant detect Y axis everytime.What could be the problem?Anyone have any solutions or suggestions?Thank you
    s
    c
    r
    • 4
    • 10
  • s

    Skolson5903

    01/19/2021, 2:41 AM
    Anyone seen an example of a Compose custom layout that functions like GridLayout, where the children in any one column are all the same width, where the width of a column can be determined by the max measured (wrapped) size of individual row's child for that column, or by grid-level column weights, etc? If not I may try to come up with something as a training exercise, as I am a Compose newb. So barring any examples, tips on a high level strategy for building such a layout would be appreciated, before I start floundering on my own 🙂 Thanks in advance for any info/suggestions...
    z
    • 2
    • 1
  • e

    Elnur Jeksenov

    01/19/2021, 4:13 AM
    Hi guys! I want to make colored shadow to widgets. I tried this solution, but it is not working: https://gist.github.com/cedrickring/0497965b0658d6727aaec531f59e8c5c Have you got any idea?
    c
    • 2
    • 1
  • d

    Denis

    01/19/2021, 6:08 AM
    Why doesn't DropdownMenu react on back button press? It says in the docs it should:
    onDismissRequest will be called when the menu should close - for example when there is a tap outside the menu, or when the back key is pressed
    but even the sample from that page in an otherwise empty app doesn't work as expected—the dropdown menu stays expanded if you press the back button. Only a tap outside the menu closes it.
    m
    m
    • 3
    • 4
  • k

    Kshitij Patil

    01/19/2021, 6:40 AM
    Can we pass a boolean
    darkTheme
    to Compose Theme Adapter so that it read colors from respective theme xml?
    • 1
    • 1
  • k

    Kshitij Patil

    01/19/2021, 7:14 AM
    Can we maintain different variants of same Composable function for different flavors/build types?
    c
    j
    j
    • 4
    • 4
  • r

    rsktash

    01/19/2021, 7:38 AM
    Hi. Anybody tried to make a mpp app with dynamic features with compose? I have two dynamic feature modules. The main module will be available by default. The other two modules will be installed on demand. How can I access on demand module composable functions from main module?
    a
    z
    • 3
    • 10
  • k

    Kort

    01/19/2021, 8:50 AM
    Hi guys, I have a problem regarding RTL. I've googled, but I couln't find the similar issues. While dealing with Arabic, if I call
    Text("تزامن...")
    in
    AmbientLayoutDirection
    as
    Ltr
    , there will be an extra wrap line (see picture below). But it stays normal while as
    Rtl
    . Anyone have any solutions or suggestions? Thanks in advance!
    Providers(AmbientLayoutDirection provides LayoutDirection.Ltr) {  
     Text("LTR")  
     Text("تزامن...")  
     Text("مزيد من المعلومات.")  
    }  
    Providers(AmbientLayoutDirection provides LayoutDirection.Rtl) {  
     Text("RTL")  
     Text("تزامن...")  
     Text("مزيد من المعلومات.")  
    }
    j
    s
    • 3
    • 5
  • a

    Alan Yin

    01/19/2021, 10:31 AM
    Modifier in if not working, please see code below
    val modifier = Modifier
            .preferredWidth(292.dp)
            .preferredHeight(87.dp)
            .clickable(onClick = { selectedItem.value = item })
        if (item == selectedItem.value){
            Timber.i("on item selected ")
            modifier.background(brush = lightHighLightGradient)
        }
        Text(
            modifier = modifier,
            // .padding(start = 35.dp),
            text = stringResource(id = item),
            fontSize = 32.sp,
            textAlign = TextAlign.Center
        )
    ✅ 1
    🙌 1
    f
    • 2
    • 2
  • p

    Philip Blandford

    01/19/2021, 11:27 AM
    Is there a way to emulate the really useful autoSizeTextType*=*"uniform" behaviour, ie size the text according the size of the textview?
    👀 2
    👍 4
    z
    a
    v
    • 4
    • 4
  • s

    Shakil Karim

    01/19/2021, 1:44 PM
    How can i apply colored shadow around any composable?
    c
    • 2
    • 1
  • a

    alorma

    01/19/2021, 4:41 PM
    Hi! Is there anny way to make
    TextField
    clickable, so we can display a
    DropdownMenu
    below it to select an item and set as text?
    • 1
    • 1
  • d

    Daniel

    01/19/2021, 4:45 PM
    Is it just me or is android studio really slow with intellisense when working on a project with compose 😢
    ➕ 2
    c
    r
    +2
    • 5
    • 8
  • z

    Zach Klippenstein (he/him) [MOD]

    01/19/2021, 8:23 PM
    Question for Compose devs working on Material – why did yall make the decision to represent different button styles as different composables with different names, vs something like just passing a
    ButtonStyle
    enum as a parameter? Given that Material has a fixed set of button styles, it seems like the parameterized version would be less code (1 fun vs 3), less duplication in documentation, and more discoverable.
    j
    a
    +3
    • 6
    • 15
Powered by Linen
Title
z

Zach Klippenstein (he/him) [MOD]

01/19/2021, 8:23 PM
Question for Compose devs working on Material – why did yall make the decision to represent different button styles as different composables with different names, vs something like just passing a
ButtonStyle
enum as a parameter? Given that Material has a fixed set of button styles, it seems like the parameterized version would be less code (1 fun vs 3), less duplication in documentation, and more discoverable.
j

jim

01/19/2021, 8:28 PM
This was a topic of much passionate discussion, with many valid pros and cons. It's mostly a result of a fundamental shift in the way we want people to start thinking about widgets. You should not be afraid to build your own, and what you build should be no different from what we would do if we wanted to add our own variant. We do not want to take a privileged position in the ecosystem. Furthermore, while it seems like many things could be shared, that ends up leading to large monolithic composables with lots of complex and subtle mechanics in their internals. By breaking them out into separate composables, we ensure that we are adequately providing the necessary building blocks that allow implementations to be written without too much complexity, so when you go to build your own button, you can do it quickly and easily just like we did.
🙏 21
a

Adam Powell

01/19/2021, 8:28 PM
yeah basically that. It only takes one parameter that is only relevant for one of the button styles and then the whole API falls apart
👍 12
z

Zach Klippenstein (he/him) [MOD]

01/19/2021, 8:29 PM
Thanks for your responses! We’re trying to figure out the tradeoffs here for our own design system, so this is helpful.
c

Colton Idle

01/19/2021, 8:30 PM
Running into the same "question". Thanks for asking it @Zach Klippenstein (he/him) [MOD] We started seeing components with tons of if statements in them and ended up breaking them out anyway.
👍 8
a

Adam Powell

01/19/2021, 8:31 PM
it was a key insight that we picked up from the flutter folks in the separation of design libraries in general. Through Android's design revamps over the past decade and especially as the mdc-android library grew, for years we fought tooth and nail to keep
android.widget.Button
as the platonic ideal of a button, and it led to no end of complexity in implementation and API
👍 4
👆 2
there were a bunch of things that made us fight for that. In part it was because writing a custom view has such a high activation energy to make it worth it; for feature requests in isolation it seems easier to just add new APIs to an existing view but that scales poorly.
h

Halil Ozercan

01/19/2021, 8:34 PM
So, it begs the question "what's the cutout between function parameter and a whole different component?" The answer probably depends heavily on the specific UI component. In other words, if a simple cornerRadius + elevation makes the difference between two styles, would it make sense to separate them into different composables?
a

Adam Powell

01/19/2021, 8:34 PM
We spent a lot of time telling the Android design team, "no" on the grounds that we couldn't keep API compatibility in the presence of suggested designs, both in the Holo revamp and Material.
😮 1
Being able to make clean breaks at will is hugely valuable
👆 1
@Halil Ozercan it can; some of it relates to how people use and think about a component. Material makes distinctions around where things like ink buttons (not sure if that's still the accepted term?) or raised buttons should be used from a semantic perspective. Those make good separate components; when the "styling" carries semantic meaning and usage recommendations
👍 1
a

Alexjlockwood

01/20/2021, 3:36 AM
fwiw we chose the
enum
route here and it has been working well… the main reasoning being we tend to have more component styles than material, and it was overall less verbose to just have an
enum
parameter compared to creating a separate function for each component style. but that is just us 🙂 we also figured we could pretty easily migrate over to the non-enum approach if we ever needed to in the future, which i guess is probably not as easy of a migration for the material library (since we aren’t publishing any of our stuff publicly)
👍🏽 1
z

Zach Klippenstein (he/him) [MOD]

01/20/2021, 5:04 PM
We’re currently leaning towards the enum route too, I think for similar reasons. More component styles, and we don’t care as much about serving as an example for how to create custom components since we are more opinionated about wanting developers to only use the declared styles as much as possible. And also yes, this seems like a Type 2 decision - easy to back out of if necessary.
j

jim

01/20/2021, 5:11 PM
"we don’t care as much about serving as an example for how to create custom components"
Famous Last Words. Often these decisions end up building on each other in ways that isn't immediately obvious. If I were giving you advice, I'd suggest you follow a pattern more similar to what we are doing with material, rather than trying to use an enum. Having said that, one of the great things about Compose is that the technology is unopinionated and you are free to violate my recommendations and learn your lessons the hard way.
😂 6
It's more than just serving as an example, perhaps the wording in my initial response was somewhat incomplete. By breaking out your widget into composable parts (necessary for reuse across composables), you ensure you are not creating a monolithic mess. Your code will likely end up having more reusable constituent parts and often better data flow and modularization.
👍 1
z

Zach Klippenstein (he/him) [MOD]

01/20/2021, 5:25 PM
My bad, could have worded that better (a bit distracted watching the inauguration 😜). I probably did interpret your initial message a bit too narrowly. We’re aware of the monolithic risk, and we’re rolling this out very slowly so if things become untenable we should be able to correct course before it’s too late. Also, we do expect custom components to occasionally be needed, so we’ll also definitely be gathering feedback around that experience. We’re super early in this process so this discussion is super helpful, thanks again for all the responses!
View count: 3