https://kotlinlang.org logo
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
  • m

    myanmarking

    09/29/2021, 5:09 PM
    Does any1 know what is the color for this bubble ?
    s
    d
    • 3
    • 5
  • o

    Orhan Tozan

    09/29/2021, 7:14 PM
    Compose v1.0.3 supports Kotlin 1.5.30🎉
    🎉 16
    n
    a
    i
    • 4
    • 17
  • a

    adjpd

    09/29/2021, 7:28 PM
    Shouldn't
    textAlign = TextAlign.Justify
    mean the whitespace is stretched to fill the width? Or am I misunderstanding
    TextAlign.Justify
    ?
    Text(
      "heebie-jeebies ".repeat(4),
      Modifier.fillMaxWidth().background(Color.Yellow),
      textAlign = TextAlign.Justify
    )
    • 1
    • 1
  • a

    adjpd

    09/29/2021, 9:00 PM
    A transparent to white
    Brush.verticalGradient
    in a white
    Box
    renders gray with
    drawWithCache
    . A bug? Code in 🧵
    z
    • 2
    • 5
  • d

    Daniel Oliveira

    09/30/2021, 1:52 AM
    Hi everyone. Why I cannot use a ScrollableColumn/LazyColumn inside another ScrollableColumn/LazyColumn?
    a
    • 2
    • 2
  • v

    Vladas

    09/30/2021, 9:24 AM
    Is there any way for fillMaxSize to work with rotation. It works fine when view is a lot smaller than than device width and height but as it gets larger it starts to deform. I tried to do it with BoxWithConstraints and flip between width and height but it is still deforming when rotated.
    z
    • 2
    • 3
  • m

    myanmarking

    09/30/2021, 9:56 AM
    it it possible to disable the label animation for OutlinedTextField? I have label and placeholder. I don’t want the label to jump around
    👀 3
    🧵 1
    c
    z
    • 3
    • 6
  • c

    Chris Miller

    09/30/2021, 10:45 AM
    While I appreciate generating random numbers in a @Composable is a bad thing to do, I don't think the following should fail to @Preview? (See thread for exception)
    @Preview @Composable
    fun PreviewTest() { Random.nextBoolean(); Text("Hello World") }
    c
    • 2
    • 4
  • r

    Rafiul Islam

    09/30/2021, 10:50 AM
    I want to draw text on a canvas like the below picture. variable2 can be null but the text should always be in the center. How can I measure or draw this kind of multiline text perfectly in the center?
    c
    c
    • 3
    • 11
  • m

    myanmarking

    09/30/2021, 10:53 AM
    how can i change the LocalTextSelectionColors ? i used the same approach as the colors in jetsnack, but for some reason it keeps the original ones
    • 1
    • 1
  • h

    Heikki Rauhala

    09/30/2021, 11:42 AM
    Hi, what would be the best way to prevent unneeded AnimatedVisibility on new Configuration, for example when orientation changes?
    👀 1
    • 1
    • 1
  • m

    myanmarking

    09/30/2021, 12:08 PM
    Is there any recommended practice to expose some composable internal state, but keeping it updatable only internally? For instance, i have this inside the composable:
    val hasError by remember(textFieldValue.value) {
        derivedStateOf {
            textFieldValue.value.text.isNotEmpty() && isInputValid(textFieldValue.value.text).not()
        }
    }
    I want the caller code to access this value, but i don’t want to change it outside
    a
    • 2
    • 2
  • n

    nilTheDev

    09/30/2021, 12:26 PM
    How can I add a
    onLongClick
    event handler to a button? There is no parameter in the constructor. I tried with
    Modifier.combinedClickable
    with a
    onLongClick
    event listener. But it isn't working.
    Column(modifier = Modifier.padding(30.dp)) {
            Button(
                onClick = {
                    Toast.makeText(
                        applicationContext,
                        "hi",
                        Toast.LENGTH_SHORT
                    ).show()
                },
                modifier = Modifier.combinedClickable(
                    onLongClick = {
                        Toast.makeText(
                            applicationContext,
                            "hello",
                            Toast.LENGTH_SHORT
                        ).show()
                    },
                    onClick = {}
                )
            ) {
                Text(text = "Click Me")
            }
        }
    }
    🧵 1
    c
    r
    • 3
    • 3
  • m

    myanmarking

    09/30/2021, 12:40 PM
    given an already created MutableState, how can i update it when some other MutableState changes?
    j
    • 2
    • 1
  • z

    Zoltan Demant

    09/30/2021, 1:07 PM
    Card shadows are cut off when using
    Modifier.alpha
    , due to the underlying call to `graphicsLayer`; is there a way to work around this?
    c
    a
    • 3
    • 4
  • m

    Marko Gajić

    09/30/2021, 1:33 PM
    In a 100% Compose app, is it possible to get rid of the com.google.android.material:material dependency, since it has transitive appcompat dependencies..? It seems to be required only for the theme inside themes.xml, which itself is only required for the theme referenced from the AndroidManifest?
    :yes: 1
    👍 1
    z
    a
    +2
    • 5
    • 10
  • m

    myanmarking

    09/30/2021, 2:30 PM
    Whenever i have the keyboard opened on some field, and i click on a button that changes fragment, this error happens
    • 1
    • 4
  • s

    shahroz

    09/30/2021, 2:46 PM
    Working on RTL support for compose, and everywhere it is recommended to use
    CompositionLocalProvider(LocalLayoutDirection provides LayoutDirection.Rtl){
    }
    I only want this to happen when the locale is RTL, is there any efficient way to find out what layout direction should be used?
    c
    • 2
    • 2
  • t

    theapache64

    09/30/2021, 2:47 PM
    🧪 When testing screen orientation change, am getting
    java.lang.IllegalStateException: No compose views found in the app. Is your Activity resumed?
    ➡️ More details in the SO thread
    p
    • 2
    • 10
  • s

    Skolson5903

    09/30/2021, 5:28 PM
    I built a composable function with the intent of reusing it in places in my app that want to show a Grid similar to the legacy android GridLayout. But compiling it gets this error with a long callstack:
    org.jetbrains.kotlin.backend.common.BackendException: Backend Internal error: Exception during IR lowering
    File being compiled: <path>/GridDisplay.kt
    The root cause java.lang.IllegalStateException was thrown at: org.jetbrains.kotlin.backend.common.lower.loops.RangeLoopTransformer.gatherLoopVariableInfo(ForLoopsLowering.kt:375)
    Anyone else seen this? I started stripping stuff down and have a small function now that doesn't do much but builds fine, then a change to one line causes the build to fail with this error. I'll post the good code/failing code in a thread in case someone is interested. Weird. Searches show a similar error when trying to use kotlinx serialization and compose in the same module, but I don't have that scenario. My app does have three multi-platform modules using serialization, but the app module specific to android and using compose does not use serialization. Would this be a jetbrains defect or a Compose/google defect? Thanks in advance for any suggestions. FWIW this happens with kotlin 1.5.30 and compose 1.1.0-alpha04
    • 1
    • 2
  • b

    brabo-hi

    09/30/2021, 7:58 PM
    Hi, i am using accompanist permissions
    @Composable
    fun MyComposable() {
        val cameraPermissionState = rememberPermissionState(Manifest.permission.READ_CONTACTS)
    }
    I am getting the following error `
    java.lang.IllegalStateException: Permissions should be called in the context of an Activity
    `
    c
    • 2
    • 2
  • c

    Colton Idle

    09/30/2021, 8:02 PM
    If I have a full edge to edge app (so my status bar is transparent), and I open up a bottom sheet full screen... it goes all the way up behind the status bar. Where would I add my status bar insets so that the bottom sheet doesn't go all the way to the top?
    c
    t
    • 3
    • 7
  • s

    Scott Kruse

    09/30/2021, 9:45 PM
    Is anyone using dependency injection / oop for theming in compose? I see a lot of top level declaration in samples / material documentation
    c
    r
    +3
    • 6
    • 16
  • d

    darkmoon_uk

    10/01/2021, 12:15 AM
    📢 :compose: All Compose users, please consider voting for this issue in the :google: Issue tracker I know everyone wants their issue voted for - but really... this is a big one! If you have ever or will ever put a
    TextField
    inside a scrollable area then this affects you. Currently, Compose does not maintain visibility of focused elements inside a scrollable viewport, when it shrinks. This affects the very common case, where a user taps a Text Field and keyboard pops up. Often the field will become hidden behind the keyboard due to the viewport not scrolling (this is not an Activity
    adjustResize
    or Insets issue). Currently the only workaround is a hacky solution with a delay and
    RelocationRequester
    . This needs a proper solution!
    👍 13
    a
    a
    +3
    • 6
    • 7
  • m

    mcpiroman

    10/01/2021, 9:15 AM
    Compose will eventually arrive for ios, right? If so, will it run on native or jvm?
    c
    g
    +3
    • 6
    • 13
  • p

    Piotr Prus

    10/01/2021, 9:35 AM
    Hello community. I am trying to find a way to make stateful composable that knows new and previous state upon the change. I would like to make an action that takes old value as parameter when the new value comes. Is taht possible using some sideEffect? I tried, but with no luck so far. More in 🧵 👇
    c
    • 2
    • 6
  • f

    Florian

    10/01/2021, 9:40 AM
    What's the right way to dim the screen brightness in Compose? Do I need a reference to the activity?
    c
    • 2
    • 5
  • f

    Florian

    10/01/2021, 9:56 AM
    Can I put this
    (context as Activity).apply {}
    block directly into the composable function or do I have to wrap it into one of the side effects methods? I just can't wrap my head around it.
    @Composable
    fun TimerScreen(
        viewModel: TimerViewModel = hiltViewModel(),
    ) {
        val uiState by viewModel.uiState.collectAsState(null)
    
        val context = LocalContext.current
    
        [...]
    
        val screenBrightness = if (uiState?.timerRunning == true) 0.15f else -1f // default
    
        (context as Activity).apply {
            val attributes = window.attributes
            attributes.screenBrightness = screenBrightness
            window.attributes = attributes
        }
    
        ScreenContent(
            uiState = uiState,
            actions = viewModel,
            scaffoldState = scaffoldState,
            bodyScrollState = bodyScrollState,
        )
    }
    r
    m
    c
    • 4
    • 13
  • m

    Mikołaj Kąkol

    10/01/2021, 10:27 AM
    Quick question. Why back (◀️ ) button first drops focus from `BasicTextField`❓ So in order to go back from a screen with input I need to click back button twice ❗
    👀 1
    m
    a
    • 3
    • 3
  • y

    yschimke

    10/01/2021, 11:37 AM
    If I'm using multiple MutableStateFlow instance fields for individual settable options of a composable, then using collectAsState inside the composable. Is there any guidance as to whether to use 6 individual fields, vs a single combined field with a data class. Do 6 State instances (of primitives, like Int / String) perform worse than a single State instance with that data class.
    c
    m
    +3
    • 6
    • 12
Powered by Linen
Title
y

yschimke

10/01/2021, 11:37 AM
If I'm using multiple MutableStateFlow instance fields for individual settable options of a composable, then using collectAsState inside the composable. Is there any guidance as to whether to use 6 individual fields, vs a single combined field with a data class. Do 6 State instances (of primitives, like Int / String) perform worse than a single State instance with that data class.
I guess second question is if it's new code but stored as a instance field, can I swap between MutableStateFlow and mutableStateOf()? Is there much difference?
c

Csaba Kozák

10/01/2021, 1:45 PM
Personally i would not use
mutableStateOf()
in a ViewModel. Compose specific code should not leak into VMs.
StateFlow
is a better fit there.
👎🏼 1
👍 2
👍🏻 1
👎 4
UIState object vs. multiple fields is an old debate, i do not think there is a consensus. 🙂 Performance wise, there should not be any difference, since you already read these 6 different streams, combining them into an object is not expensive.
👍🏻 1
m

myanmarking

10/01/2021, 2:21 PM
I think he was asking about performance in like which ones minimize recompositions, rather than what is costly in creation of the flow.
c

Csaba Kozák

10/01/2021, 2:23 PM
Sorry, i missed that. The combined class could be suboptimal in that case, since if any of its 6 field change, the whole object will change, and compose has to recompose everything which reads the state object.
👍 1
👍🏻 1
a

Adam Powell

10/02/2021, 4:02 PM
Prefer snapshot state, that is,
mutableStateOf
. Yes, in ViewModels too. Snapshots are not a UI or Compose-specific technology, it's a generic observable MVCC system.
😮 1
Multiple MutableStateFlows mean you can't ensure consistency across them in a thread-safe way. Single UiState objects in MutableStateFlows mean you're doing very broad recompositions from the root whenever things change instead of granular recompositions of only the things that change, and repeated .equals comparisons made by compose on stable objects can traverse large sections of that object tree multiple times as recomposition proceeds downward if you don't hit all the right optimization cases. Copying deep immutable object trees to make a change is cumbersome and usually means you're introducing something like arrow lenses to make it less obnoxious. Snapshots were literally created to solve these problems. Stop worrying what maven artifact they're delivered in and use them. 🙂
😮 1
👍 2
➕ 1
👍🏻 1
😐 1
c

Csaba Szugyiczki

10/04/2021, 11:00 AM
@Adam Powell How about decoupling the VM from the UI lifecycle. In this article we can see a way how to collect Flows from a VM in compose that respects the view lifecycle. If the Snapshot states are created in the VM how is it possible to handle lifecycle correctly without the VM knowing about it explicitly?
a

Adam Powell

10/04/2021, 1:50 PM
If you are truly using cold data sources then that matters, but if you have hot data sources (if you're using
MutableStateFlow
those are hot data sources) then doing any sort of lifecycle-bound collect isn't buying you much, if anything. Whatever process is changing the MutableStateFlow in response to other external stimuli is still running in the background unless you have some different means of limiting it.
c

Csaba Szugyiczki

10/04/2021, 2:08 PM
I am not sure I can follow the reasoning perfectly. Can you show any code as reference, where snapshot state is created in the ViewModels. Did I miss a Compose sample app that does this?
a

Adam Powell

10/04/2021, 2:10 PM
It's the same as any of the hoisted state samples, just in a class that extends ViewModel.
class MyViewModel : ViewModel() {
  var myValue by mutableStateOf(initial)
    private set // optional
}
a

Archie

10/19/2021, 3:44 PM
@Adam Powell I am not sure if I understood it correctly. In the original question of whether to use UIState object vs. multiple fields, is it correct to assume that having multiple fields with snapshot state is better? I’ve been working on Kotlin Multiplatform Projects where we share ViewModel across platform and so we do not use
mutableStateOf
inside the ViewModel. Is this assumption correct?
View count: 7