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

    Mitchell Syer

    01/11/2022, 4:12 PM
    Hi, for navigation I am using the library called Voyager, because its simple and fits my requirements very well. But I am not sure at how I would go about setting a new root screen with it. My application starts with a login screen, and then that should be replaced with a different screen once the user finishes logging in. I have a found a few functions like Navigator.popAll() but that only pops until the current root composable, so I am not sure how to go about this.
    😍 1
    ✅ 1
    • 1
    • 1
  • a

    Arun Joseph

    01/11/2022, 4:30 PM
    Is accompanyst permission lib is a goto choice if the permission request to be done in presentation layer?
    m
    • 2
    • 3
  • v

    Vsevolod Kaganovych

    01/11/2022, 4:39 PM
    Does anyone know how to use
    TextFieldValue
    in
    TextField
    with
    AnnotatedString
    ? Example: I have a
    ViewModel
    from where I observe state. When text changes, I update my state and create a new
    AnnotatedString
    like this
    val nokString = getNokString(amount = state.nokAmount)
    the
    getNokString()
    looks like this
    @Composable
    private fun getNokString(amount: String): AnnotatedString {
        return buildAnnotatedString {
            withStyle(
                style = SpanStyle(
                    fontFamily = MaterialTheme.typography.subtitle1.fontFamily,
                    fontSize = 40.sp
                )
            ) {
                append(amount.ifEmpty { "0" })
            }
            append(" ")
            withStyle(
                style = SpanStyle(
                    fontFamily = MaterialTheme.typography.subtitle1.fontFamily,
                    fontSize = 14.sp
                )
            ) {
                append("NOK")
            }
        }
    }
    But when I assign a new value to
    TextField
    TextField(value = TextFieldValue(nokString),
              onValueChange = {
                     actioner.invoke(SendAction.OnNokChanged(it.text))
              })
    The behaviour is unexpected: it appends the new result to the previous one. And I'm not sure how to handle this situation. Any ideas? Thanks in advance.
    m
    z
    r
    • 4
    • 6
  • a

    alorma

    01/11/2022, 4:47 PM
    Hi all! Is there a (out of the box) way to obtain the Hex value (as #aaxxyyzz) from a given
    Color
    ?
    k
    e
    +2
    • 5
    • 16
  • c

    Colton Idle

    01/11/2022, 6:28 PM
    If I have a Container composable that takes a list of other composables to display, and can display that list in a Row, is there any way to add a modifier to each composable, even though I don't know what each composable is?
    fun SomeContainer(
        content: List<@Composable () -> Unit>)
      Row(
             Modifier.horizontalScroll(rememberScrollState()).height(IntrinsicSize.Min),
            ) {
                content.forEach {
                    it(Modifier.fillMaxHeight()) <----- Anyway to get something like this
                }
            }
    Wrapping it in a box for example doesn't help me, because although the box will get the modifier, the composable inside the box will not draw to fill max height.
    c
    z
    c
    • 4
    • 12
  • m

    mattinger

    01/11/2022, 7:03 PM
    So we have a MainActivity that’s mainly xml. But we’re starting to use compose for certain parts of it, and some of the things in there need to popup things like bottom sheet dialog. I was trying to write a declarative bridge that would do this, but i’m having trouble with the Preview annotation. I’m assuming we’re using FragmentActivity (because we always extend that in some indirect way). However Preview uses PreviewActivity which directly extends ComponentActivity. As a result, i can’t get access to the supportFragmentManager in order to show the dialog. Any suggestions? (code in thread)
    i
    c
    • 3
    • 4
  • a

    Andy Himberger

    01/12/2022, 3:28 AM
    I am seeing some problems if a LiveData is updated in quick succession from a coroutine with postValue, that the compose observers are not always updated with the final value. If I insert a delay everything does work, its also odd because I am using the same Composable twice in my tree and one of them updates and the other doesn't, all of this seems more likely to happen (keeping old state) when the children are more expensive to update. It feels like if you have 2 updates, and the 2nd update comes in before the first one has completed recomposition, that first one when it ends is saving its state as if it did consume the update. (More in reply)
    🤔 1
    c
    a
    • 3
    • 8
  • d

    Deepak Gahlot

    01/12/2022, 6:46 AM
    Hi All,
    c
    • 2
    • 4
  • y

    yschimke

    01/12/2022, 10:00 AM
    Is there an easy way to disable events for the top layer of Box. I essentially want a debug only overlay, that doesn't stop the events being handled in the normal UI below.
    Box {
      Content()
      Overlay(modifier = Modifier.ignoreTouchEvents())
    }
    a
    v
    z
    • 4
    • 17
  • m

    Marco Righini

    01/12/2022, 11:31 AM
    Hi everyone, we are using a remote build machine. At the end of the remote compilation we are syncing back the apk from the remote build machine to the local machine. Compose previews are not working when building remotely (previews are empty) but working when building locally. The suspect is that we need to sync back not only the apk but other generated build files related to previews too. What are the build files that are compiled for showing the previews in Android Studio?
    z
    c
    • 3
    • 4
  • j

    Jaime

    01/12/2022, 3:18 PM
    hi everyone, do you know any way or best practice to make the compose views responsive for all devices, I am doing with constraintlayout as in xml but it doesn’t work very well on small devices
    z
    • 2
    • 5
  • m

    Marcin Wisniowski

    01/12/2022, 3:25 PM
    How can I put a bigger composable in a smaller parent (both with fixed sizes), so that it's clipped? (like would happen by default with Views) My child composable just resizes itself to fit into the parent, which I don't want. I tried using
    requiredWidth()
    but that centers it inside the parent (it overflows to both sides), where I want it left-aligned and clipped on the right.
    ✅ 1
    a
    z
    • 3
    • 4
  • s

    Stylianos Gakis

    01/12/2022, 5:02 PM
    A question about
    derivedStateOf
    for when we want to calculate some result using composable’s parameters vs using local mutableState objects. More in thread 🧵
    c
    z
    l
    • 4
    • 7
  • m

    myanmarking

    01/12/2022, 5:46 PM
    Having something like this:
    fun someComposable(enabled: Boolean){
    var valueField by remember{
    mutableStateOf(..)
    }
    val errorInternal: Boolean = remember(enabled, valueField) {
    derivedStateOf(valueField && enabled)
    }
    }
    I need a state that depends on another state and a variable. derivedStateOf is for state only. This works but is this the correct approach?
    c
    a
    +2
    • 5
    • 10
  • c

    Colton Idle

    01/12/2022, 7:17 PM
    Compose Version 1.2.0-alpha01 out today 🎉 Notable changes (in my opinion): • kotlin 1.6.10 (even though we technically had this last release) • New parameter 
    userScrollEnabled
     was added to 
    LazyColumn
    , 
    LazyRow
    , and 
    LazyVerticalGrid
     in order to allow users to temporarily or permanently disable the user initiated scroll via touch gestures or accessibility actions. Scrolling programmatically via the methods on the state will still be allowed. (I7eae9, b/201150093) • Added Wear OS device ids to Preview devices list (I93232) • Fixes 
    TextField
     cursor handle not hiding when scrolled out of view. (I14552, b/208883748) •
    ModalBottomSheetState
     now has a 
    isSkipHalfExpanded
     flag. It can be either set through the constructor or updated later on by setting `ModalBottomSheetState`'s 
    isSkipHalfExpanded
     property to 
    true
    . Updating `isSkipHalfExpanded`'s value causes a recomposition of the sheet. (I18b86, b/186669820) Edit: Can we get a slackbot that posts releases and release notes? lol
    🎉 8
    🙌 3
    👀 8
    r
    a
    t
    • 4
    • 9
  • b

    Bojie Jiang

    01/12/2022, 8:01 PM
    I found app background mix up when turning to dark theme as below, we can see Text background layers overlapping. Is there an easy to debug this issue? Thanks!
    c
    k
    c
    • 4
    • 8
  • b

    brabo-hi

    01/12/2022, 8:05 PM
    Hi all, when inside a compose component, how could we listen to the activity event
    override fun onNewIntent(intent: Intent?) {}
    c
    i
    • 3
    • 4
  • c

    Colton Idle

    01/12/2022, 8:43 PM
    Out of curiosity. if I just wanted to "watch" what updates are going into compose, would I just broswe this list for the most recent changes to get excited about? https://android-review.googlesource.com/q/project:platform%252Fframeworks%252Fsupport+branch:androidx-main or is there a better set of params to view what CLs are created?
    s
    • 2
    • 8
  • s

    Simon Stahl

    01/13/2022, 12:29 AM
    Hi everyone. I was wondering what a good solution for the
    Flow operator functions should not be invoked within composition
    warning is Say I have following method in my VM:
    @Composable
    fun getValue() =
        flowOf(1, 2, 3)
            .map { it.toString() } // warning here
            .collectAsState(initial = "")
    The naive solution is to just split the method up
    fun getValueFlow() =
        flowOf(1, 2, 3)
            .map { it.toString() }
    
    @Composable
    fun getValue() =
        getValueFlow()
            .collectAsState(initial = "")
    But that is not really a functional change and if there is an issue with flow operations, then we would still have it. What would be a real fix for this warning?
    i
    c
    • 3
    • 18
  • c

    Cristian Rosa

    01/13/2022, 3:21 AM
    Does anybody know if there is any issue with
    androidx.compose.material3
    v1.0.0-alpha02
    and setting (according material 3 specification) right color on TextButton
    TextButton(
        onClick = onConfirm,
        enabled = onConfirmEnable,
        colors = ButtonDefaults.textButtonColors(
            contentColor = MaterialTheme.colorScheme.primary,
            disabledContentColor = Color.Red,
            containerColor = Color.Transparent,
            disabledContainerColor = Color.Transparent,
        )
    Doing by this che color always have primary color even when it’s disable…..I know those “transparent” look ugly, they were just for test it quicker! 😄
    m
    • 2
    • 2
  • f

    FunkyMuse

    01/13/2022, 8:35 AM
    hey guys, is there something like
    afterTextChanged
    for TextInputField in compose?
    a
    s
    c
    • 4
    • 7
  • m

    Michael Bichlmeier

    01/13/2022, 9:25 AM
    Hey guys. Does anyone of you knows a compose image zoom library like this https://github.com/igreenwood/loupe ? Overall requirements for our view: • Show image in fullscreen • Image zoom in/out with pinch gesture • double tap for zoom in/out (by percent) • Pager for multiple images • Image description overlay • Swipe to dismiss I know we can implement things like the last two points quite simply by our own, but maybe there is already a library with all these features 😉
    a
    • 2
    • 7
  • a

    Ankit Shah

    01/13/2022, 10:14 AM
    Hello Everyone, I need to add a lazyVerticalGrid inside a scrollable column. How can I achieve it? for example:
    Column(modifier = Modifier
        .padding(it)
        .fillMaxSize()
        .verticalScroll(scrollState)
    ){
    Box(){
        Text("Sample Widget")
    }
    Box(){
        LazyVerticalGrid(cells = GridCells.Fixed(3)) {
                    items(3) { index ->
                        val item = index
                        Text(text = "Item $item")
                    }
                }
        }
    }
    c
    r
    c
    • 4
    • 3
  • x

    xxfast

    01/13/2022, 11:00 AM
    Hi all, trying to use
    androidx.compose.material3:material3:1.0.0-alpha03
    , and i’m running into this when building the app
    e: java.lang.IllegalArgumentException: Failed requirement.
    	at androidx.compose.compiler.plugins.kotlin.lower.ComposableFunctionBodyTransformer.visitNormalComposableCall(ComposableFunctionBodyTransformer.kt:2660)
    Full trace in the thread. I’m using kotlin-1.6.10
    c
    c
    • 3
    • 5
  • e

    elye

    01/13/2022, 12:43 PM
    Is it possible to make a passed in variable (i.e. MutableState) still a delegate, so I can assign to the value directly (instead of using the
    .value
    )? More info on my question on https://stackoverflow.com/questions/70696585/can-we-still-use-the-variable-delegate-for-variable-pass-through-parameter
    d
    z
    • 3
    • 2
  • a

    Ankit Shah

    01/13/2022, 1:04 PM
    https://kotlinlang.slack.com/archives/CJLTWPH7S/p1588253042070100 This is a 2 years old issue. I am stuck in the same. Does anyone have solution to this?
    l
    y
    +2
    • 5
    • 10
  • s

    ste

    01/13/2022, 1:30 PM
    I'm getting a
    ClassCastException
    with the following minimal snippet:
    var something by rememberSaveable { mutableStateOf(0) }
    val value by rememberSaveable(something) { mutableStateOf("Hello") }
    val somethingElse by rememberSaveable { mutableStateOf(false) } // !!!
    
    println("value: $value") // !!!
    
    Box(
        modifier = Modifier
            .fillMaxSize()
            .clickable { something += 1 }
    )
    However, after
    something
    is changed, it throws
    java.lang.ClassCastException: java.lang.Boolean cannot be cast to java.lang.String
    on configuration change. I know the example doesn't make sense, but is this a bug or whatsoever?
    👀 1
    a
    z
    • 3
    • 11
  • k

    K Merle

    01/13/2022, 2:01 PM
    How to prevent autoscroll on LazyColumn update if item index 0 is not visible?
    f
    d
    +2
    • 5
    • 13
  • s

    Stylianos Gakis

    01/13/2022, 3:07 PM
    Question about Android Studio tooling for compose animations. More in thread 🧵
    d
    c
    • 3
    • 8
  • e

    efemoney

    01/13/2022, 4:31 PM
    How can I require only a specific set of composable functions be called inside the scope of one of my slots. My use case is I have an “action bar” slot that can contain any number of
    ActionItem(...)
    composables up until a maximum number (eg based on available space, only 3
    ActionItem(...)
    s allowed). Is this enforceable at compile time? (eg something like coroutines’
    @RestrictedSuspension
    ) 🤔 or can it only be implemented as a custom
    Layout
    (that maybe checks, at runtime, for a particular
    parentData
    type)?
    c
    • 2
    • 2
Powered by Linen
Title
e

efemoney

01/13/2022, 4:31 PM
How can I require only a specific set of composable functions be called inside the scope of one of my slots. My use case is I have an “action bar” slot that can contain any number of
ActionItem(...)
composables up until a maximum number (eg based on available space, only 3
ActionItem(...)
s allowed). Is this enforceable at compile time? (eg something like coroutines’
@RestrictedSuspension
) 🤔 or can it only be implemented as a custom
Layout
(that maybe checks, at runtime, for a particular
parentData
type)?
c

Casey Brooks

01/13/2022, 5:34 PM
Requiring specific methods is kind-of against the philosophy of compose. A better solution is to use a "scope object" as the slot lambda's receiver to expose and encourage the correct APIs for that scope, while giving users the flexibility to do something different if they need to. This is done commonly throughout the Compose/Material stdlibs for reference (for example,
Column()
->
ColumnScope
,
Box()
->
BoxScope
, etc)
➕ 3
Alternatively, if it does truly need to be restricted, don't use a slot. Pass configuration parameters or a builder object to the function instead
➕ 1
View count: 1