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

    Reondz

    09/06/2020, 11:25 AM
    Why we must pass a param of "label" into TextField?Could it has a default value(null)?
    c
    • 2
    • 2
  • f

    flosch

    09/06/2020, 2:35 PM
    What is the easiest way to convert a
    androidx.compose.ui.graphics.Color
    to a
    ColorInt
    ?
    j
    • 2
    • 2
  • f

    flosch

    09/06/2020, 3:08 PM
    I just tried to use
    rememberCoroutineScope { Dispatchers.Default }
    . When trying to build it leads to
    e: org.jetbrains.kotlin.codegen.CompilationException: Back-end (JVM) Internal error: Couldn't transform method node:...
    (full stack trace in thread). When using
    rememberCoroutineScope()
    without a custom context, everything works fine. Is this a known issue? Running
    AS 4.2 Canary 9
    and
    1.0.0-alpha02
    .
    z
    • 2
    • 2
  • a

    amar_1995

    09/06/2020, 3:10 PM
    I need to provide in-app dark and light theme feature. Currently, I am changing theme using
    isSystemInDarkTheme
    but how to change theme using user input ?
    f
    • 2
    • 4
  • a

    Archie

    09/06/2020, 4:41 PM
    is there a way to animate/create transition for
    Composable
    s getting "disposed". When changing state in compose it is usually done this way:
    Surface(color = selectorExpandedColor, elevation = 3.dp) {
            when (currentSelector) {
                InputSelector.EMOJI -> EmojiSelector(onTextAdded, focusRequester)
                <http://InputSelector.DM|InputSelector.DM> -> NotAvailablePopup(onCloseRequested)
                InputSelector.PICTURE -> FunctionalityNotAvailablePanel()
                InputSelector.MAP -> FunctionalityNotAvailablePanel()
                InputSelector.PHONE -> FunctionalityNotAvailablePanel()
                else -> { throw NotImplementedError() }
            }
        }
    (Note: Code above is taken from
    JetChat
    ) But doing so, creates a jarring experience where contents just pops-out and pops-in in an instant. Is it possible to trigger/create transition or animation when changing states (animate composable out and then animate composable coming in)? Is there any guide for this out there?
    j
    a
    s
    • 4
    • 10
  • m

    manueldidonna

    09/06/2020, 5:09 PM
    LazyColumn
    doesn't consider the contentPadding to show items https://issuetracker.google.com/issues/167913500 I've reported this bug almost a month ago but I mistakenly believed it was due to the translucent
    TopAppBar
    a
    • 2
    • 1
  • m

    Mehdi Haghgoo

    09/07/2020, 4:37 AM
    Hey. What is a RecomposeScope mentioned in the following paragraph (Sorry it sounds like a TOEFL question! lol)?
    MutableState: A mutable value holder where reads to the value property during the execution of a Composable function, the current RecomposeScope will be subscribed to changes of that value. When the value property is written to and changed, a recomposition of any subscribed RecomposeScopes will be scheduled. If value is written to with the same value, no recompositions will be scheduled.
    s
    • 2
    • 3
  • n

    Namig Tahmazli

    09/07/2020, 7:35 AM
    Hi I have been investigating Jetpack Compose couple of days. In Flutter and SwiftUI it is possible to have a shadow with different colors. But I could not find how I can achieve it in Jetpack Compose.
    👍 1
    a
    • 2
    • 1
  • a

    ahulyk

    09/07/2020, 8:44 AM
    Will Compose support multiplatform? Any info on that?
    m
    m
    +5
    • 8
    • 11
  • y

    Yann Badoual

    09/07/2020, 9:49 AM
    What's the easiest way to create the equivalent of a grid layout recycler view currently? (not staggered) Thought of having a lazy list of column, where each line would be a row having n elements, but feels hacky
    a
    n
    • 3
    • 3
  • z

    Zhelyazko Atanasov

    09/07/2020, 12:12 PM
    Is this a common known issue or I'm the only one having it - Interactive Preview is not working in AS 4.2 Canary 9 / Jetpack Compose
    1.0.0-alpha02
    / Android Tools
    4.2.0-alpha09
    . AS goes into "Interactive mode", but when I start interacting, nothing happens (I have the simple demo with a button that shows the number of times it has been clicked. It was working in AS Canary 8 / Compose Alpha 1
    m
    m
    l
    • 4
    • 5
  • a

    Ali Zargar Shabestari

    09/07/2020, 2:05 PM
    Adding
    clickable
    modifier inside
    LazyColumnFor
    makes the scrolling jaggy. My first thought was that ripple effect has something to do with the lag, but, as I changed the indicator to
    null
    the problem is still there. here is link to my code in a thread related to this issue: https://kotlinlang.slack.com/archives/CJLTWPH7S/p1599482698133100?thread_ts=1597241706.045300&amp;cid=CJLTWPH7S
    a
    • 2
    • 2
  • j

    jaqxues

    09/07/2020, 2:10 PM
    Alright I think I have a more complex bug today. I have an expandable Card (representing Articles). When collapsed, the Card contains the author and sources. When expanded, it also contains a longer description. The user can save the article by long pressing on the article (Obviously there will be a button for it, just to simplify the following sample code). A state representing the saving result will be displayed in the extended layout. So the user extends the article (by clicking on the card), the user long presses (on the card), and state might show up (uses
    Random.nextInt(0, 3)
    for testing purposes) As you can see in the screenshots below (1 -> 2), when having the content in the "extendedContent" changed, the card doesnt expand more to fit the contents. Now, when the Card is collapsed and expanded again (3), it resizes and looks how it should. However, if now the message disappears, it is again not resizing, meaning we have a lot of empty space (4)
    • 1
    • 3
  • j

    JulianK

    09/07/2020, 3:16 PM
    Is there a solution for remembering UI State through app navigation? For example, i have a Tab Navigation/Pager with dynamic number of pages. Each page is a scrollable list containing items. When i navigate to a "sub-view" (would have been a fragment before), i'd like to remember scroll state, so when the user goes back, the list maintains it's scroll position. Remember does not work here because the component is removed from tree. Also i can't pull remember up the tree, because its not a static number of pages/lists.
    j
    t
    • 3
    • 4
  • j

    Jan Skrasek

    09/07/2020, 3:56 PM
    Is there any issue/"initiative" to decompose TextField? Such simple thing as setting a background color seems quite impossible. (outline api doesn't provide bg color property, filled text field applies 0.12% transparency on the passed value...) All building blocks are internal/private 😞
    a
    i
    +5
    • 8
    • 10
  • m

    Mehdi Haghgoo

    09/07/2020, 5:48 PM
    When a composable function is invoked, the invocation might occur on a different thread from the caller. That means code that modifies variables in a composable lambda should be avoided–both because such code is not thread-safe, and because it is an impermissible side-effect of the composable lambda. -link
    Parallel execution in Compose is very new to me. Could someone tell me please how I can modify variables if I am not allowed to do it in a Composable lamda? Also, what does thread-safety mean in the above paragraph?
    m
    s
    • 3
    • 2
  • v

    Victor Yakovlev

    09/07/2020, 6:47 PM
    How to set height to
    fillMaxHeight
    inside component where height is
    wrapContentHeight
    ?
    a
    v
    • 3
    • 16
  • a

    Ali Zargar Shabestari

    09/07/2020, 7:39 PM
    I’m facing a problem with
    LazyColumnFor
    . The problem is kind of hard to explain, so I included a video. depensing on the scroll position of Column recomposing with a subset list of items leads to empty list.
    untitled.webm
    m
    a
    • 3
    • 4
  • a

    Ali Zargar Shabestari

    09/07/2020, 8:08 PM
    I’m not sure is I’m doing something wrong, but in my app the content in
    scaffold
    is drawn behind the
    bottomBar
    . is this the expected behaviour? The content:
    Text(modifier = Modifier.verticalScroll(rememberScrollState()),text = <a Long content>)
    m
    z
    s
    • 4
    • 5
  • m

    manueldidonna

    09/07/2020, 9:35 PM
    BottomNavivation
    composable (green accent) has a different ripple than
    BottomNavigationView
    (red accent) from Material Components for Android (which is the same effect showed in the material guidelines)
    l
    • 2
    • 5
  • m

    Mehdi Haghgoo

    09/08/2020, 3:38 AM
    Hi. @romainguy said in a recent

    video▾

    that Jetpack Compose has to catch up with 15 years of development. Does that mean that Android's classic way of using xml layouts has been in use since 2005? I ask because Android's public first public release seems to be 2008.
    ➕ 1
    r
    • 2
    • 3
  • v

    Vincent tiensi

    09/08/2020, 4:32 AM
    Hiya! Thank you for the codelabs/compose tutorials, they have been super helpful. I was wondering if there’s any tutorials/deeper dive on building custom Modifiers. Modifiers seem pretty core to compose components but besides digging into the source code there doesn’t seem to be much else on it (There was a custom text Modifier.layout in the layout tutorial).
    :yes: 2
    a
    • 2
    • 1
  • s

    Sumit Sharma

    09/08/2020, 5:49 AM
    Hi all, hope you all good, I have a question regarding @Model Annotation in Jetpack library. What does it mean and how can I use it in my JetPack Compose project. Which dependency contains it. Sorry for my bad English. Thanks
    r
    g
    • 3
    • 7
  • n

    Namig Tahmazli

    09/08/2020, 6:41 AM
    Hi all. I have a question related to nested scrolling inside draggable and swappable components. I have been investigating Crane App. The BottomUp Slider view contains list. Which causes the list to consume all scroll until it reaches to bottom. Then finally the slider scrolls. I was able to overcome this issue by disabling and enabling LazyColumnFor, but it is not smooth at all. I wonder if there is a better way to handle it?
    m
    • 2
    • 3
  • e

    efemoney

    09/08/2020, 7:42 AM
    Is there a modifier to scale a composable? kinda like how scalex and scaley work? I need something temporary (for animations)
    n
    a
    • 3
    • 8
  • m

    Mehdi Haghgoo

    09/08/2020, 7:54 AM
    How can I support RTL text in Compose e.g. inside a Text Composable?
    z
    • 2
    • 2
  • b

    Brett Best

    09/08/2020, 8:23 AM
    I’m trying to use ViewModel + LiveData, as seen https://developer.android.com/jetpack/compose/interop#viewmodel however the code sample (in thread reply) always shows null
    s
    • 2
    • 13
  • m

    Mehdi Haghgoo

    09/08/2020, 9:44 AM
    All children of the a compose app's material theme must follow the typography defined in that theme, mustn't they?
    class MainActivity : AppCompatActivity() {
        override fun onCreate(savedInstanceState: Bundle?) {
            super.onCreate(savedInstanceState)
            setContent {
                DraftNotebookTheme {
                    Surface(color = MaterialTheme.colors.background) {
                        MyButton("Android")
                    }
                }
            }
        }
    }
    
    @Composable
    fun MyButton(label: String) {
        Button(onClick = {}) {
            Text(label)
        }
    }
    
    @Preview(showBackground = true)
    @Composable
    fun DefaultPreview() {
        DraftNotebookTheme {
            MyButton("سلام دنیا")
        }
    }
    When doing preview, the text shown on the button does not follow the font family I have set in the theme. Is this a bug?
    e
    • 2
    • 6
  • c

    casablancais

    09/08/2020, 11:10 AM
    Hi, based on codelabe on Modifiers ⬇️
    Note : By convention, the modifier is specified as the first optional parameter of a function. This enables you to specify a modifier on a composable without having to name all parameters.
    Is there a reason why the AppTopBar Modifier was not put as the first parameter in the compose material TopAppBar implementation ?
    @Composable
    fun TopAppBar(
        title: @Composable () -> Unit,
        modifier: Modifier = Modifier,
        navigationIcon: @Composable (() -> Unit)? = null,
        actions: @Composable RowScope.() -> Unit = {},
        backgroundColor: Color = MaterialTheme.colors.primarySurface,
        contentColor: Color = contentColorFor(backgroundColor),
        elevation: Dp = TopAppBarElevation
    ) {...}
    m
    • 2
    • 2
  • y

    Yann Badoual

    09/08/2020, 12:07 PM
    Is this bad practice?
    val (currentSize, setCurrentSize) = remember { mutableStateOf(Size.Zero) }
    val matrix = remember(currentSize) {
        Matrix().apply {
            setRectToRect(
                box,
                RectF(0f, 0f, currentSize.width, currentSize.height),
                Matrix.ScaleToFit.CENTER
            )
        }
    }
    
    remember(matrix) { // heavy work }
    
    Canvas(modifier = Modifier.fillMaxSize()) {
        setCurrentSize(size)
    	
    	// Do some drawing ...
    }
    I didn't find any alternative to retrieve the size and be able to
    remember
    some result with it as a key 🤔
    s
    n
    • 3
    • 5
Powered by Linen
Title
y

Yann Badoual

09/08/2020, 12:07 PM
Is this bad practice?
val (currentSize, setCurrentSize) = remember { mutableStateOf(Size.Zero) }
val matrix = remember(currentSize) {
    Matrix().apply {
        setRectToRect(
            box,
            RectF(0f, 0f, currentSize.width, currentSize.height),
            Matrix.ScaleToFit.CENTER
        )
    }
}

remember(matrix) { // heavy work }

Canvas(modifier = Modifier.fillMaxSize()) {
    setCurrentSize(size)
	
	// Do some drawing ...
}
I didn't find any alternative to retrieve the size and be able to
remember
some result with it as a key 🤔
s

satyan

09/08/2020, 12:46 PM
In the codelabs about layout Modifier.layout is explained to get children size.
n

Nader Jawad

09/08/2020, 4:42 PM
In this case you would want to remember the matrix and conditionally update the computation within the DrawScope receiver scope within the Canvas composable only when the size changes
y

Yann Badoual

09/08/2020, 4:54 PM
How would you check that the size changed? You'd need to remember the size right? So the only difference would be that the computation would be inside the DrawScope instead of in the matrix creation lambda 🤔
n

Nader Jawad

09/08/2020, 4:55 PM
You can create a wrapper object that keeps track of both the size and the matrix and remember that. Then within the DrawScope callback you can compare/update the size parameter and matrix computations
y

Yann Badoual

09/08/2020, 5:15 PM
Indeed, thanks for the help
View count: 2