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

    YASAN

    04/25/2021, 4:05 PM
    Is there a function or something to change the alpha variable of a
    Color
    ? It is val so cannot be modified. To change it I had to create my custom extension function:
    fun Color.updateAlpha(newAlpha: Float) =
        Color(red = red, blue = blue, green = green, colorSpace = colorSpace, alpha = newAlpha)
    r
    a
    4 replies · 3 participants
  • o

    Olivier Patry

    04/25/2021, 4:10 PM
    I struggle to achieve "complex" transition of my entities. I have a list of items, each of them having an "update cause". Depending on it, I have different transition to apply to the item's composable. So, I need to animate several values of different nature at the same time, the animation "spec" depending on "update cause". Both beginning and ending state depends on such state. I have a quick & dirty "working" impl (not smooth anim, not very nice code…) which I try to clean using
    updateTransition
    (doc) without a lot of success so far…
    r
    d
    +2
    78 replies · 5 participants
  • n

    Nat Strangerweather

    04/25/2021, 4:49 PM
    I have a box with a
    .fillMaxWidth
    modifier. In that box, I have another box and I want it to be the width of the parent box divided by 7. How can I get the width of the parent Box, or that .
    fillMaxWidth
    value?
    n
    m
    21 replies · 3 participants
  • a

    Ahmed Mourad

    04/25/2021, 5:05 PM
    Hey everyone! So I'm having this problem and I'm not sure what the "conventions" are in this situation, I was trying to create a range bar, a simplified version of which is this:
    @Composable
    fun SomeRangeBar(
        lower: Float,
        upper: Float,
        onLowerChanged: (Float) -> Unit,
        onUpperChanged: (Float) -> Unit,
        range: ClosedRange<Float>,
        modifier: Modifier = Modifier
    ) {
        Canvas(modifier = modifier.pointerInput(Unit) {
            detectHorizontalDragGestures {
                if (headToMove == Head.LOWER) {
                    onLowerChanged(
                        newValue.coerceIn(range.start, upper)
                    )
                } else {
                    onUpperChanged(
                        newValue.coerceIn(lower, range.endInclusive)
                    )
                }
            }
        }) {
        // drawing...
        }
    }
    
    @Composable
    fun UseSomeRangeBar() {
        val lower by remember { mutableStateOf(25f) }
        val upper by remember { mutableStateOf(100f) }
        SomeRangeBar(
            lower = lower,
            upper = upper,
            onLowerChanged = { lower = it },
            onUpperChanged = { upper = it },
        )
    }
    The problem would be that, since the
    pointerInput
    closure survives recomposition and since it also captures the values of
    lower
    and
    upper
    then the values of
    lower
    and
    upper
    passed to
    coerceIn
    are always the initial lower and upper values, all subsequent values of
    lower
    and
    upper
    never make it to the lambda. A simple solution to this is to pass
    MutableState<Float>
    instead of
    Float
    as
    lower
    and
    upper
    and since
    MutableState
    is mutable lol, then updates to
    lower
    and
    upper
    make it to the closure:
    @Composable
    fun SomeRangeBar(
        lower: State<Float>,
        upper: State<Float>,
        //...
    ) {
    //...
    }
    
    @Composable
    fun UseSomeRangeBar() {
        val lower = remember { mutableStateOf(25f) }
        val upper = remember { mutableStateOf(100f) }
        SomeRangeBar(
            lower = lower,
            upper = upper,
            onLowerChanged = { lower.value = it },
            onUpperChanged = { upper.value = it },
        )
    }
    But I haven't seen anything like this in the available composables, what's the convention in such a situation?
    d
    8 replies · 2 participants
  • l

    loloof64

    04/25/2021, 5:15 PM
    Hi ! I'm writing a custom layout based on
    ConstraintLayout
    . More on thread
    1 reply · 1 participant
  • l

    loloof64

    04/25/2021, 5:58 PM
    I am trying to set up two diffent layouts based on
    ConstraintLayout
    for portrait and landscape, but it does not apply any layout at all. More on thread
    2 replies · 1 participant
  • o

    orangy

    04/25/2021, 6:41 PM
    Is it possible to make a component that would receive a simple
    content: @Composable () -> Unit
    but then will wrap each child into another component?
    j
    z
    +2
    9 replies · 5 participants
  • s

    Slackbot

    04/25/2021, 6:53 PM
    This message was deleted.
    a
    y
    3 replies · 3 participants
  • a

    Alexander Karkossa

    04/25/2021, 10:05 PM
    Hey i tried to use the new SwipeRefresh. My LazyColumn uses SwipeToDismisswithin the rows. To show the dismiss animation, my viewModel hold a list of deleted items. Within the LazyColum i check, if my item is within the deletedItems list, than i will skip it in the LazyColumn. If i remove the item directly from the list or delete it in the db, the ui will be triggered from collectAsState on the itemsFlow. The deleted item is not in the list anymore... as a result, the item will instantly be invisible, no fadeOut, shrinkHorizontally... My current problem is, that SwipeRefresh won't let me "swipe" down anymore, if the first item is "deleted". Any ideas?
    🤔 1
    2 replies · 1 participant
  • r

    robnik

    04/26/2021, 12:56 AM
    I have a Scaffold with a TopAppBar. How do you make the bar's background color go all the way to top edge of screen?
    b
    j
    11 replies · 3 participants
  • x

    xxfast

    04/26/2021, 7:00 AM
    Has anyone able to use jetpack compose in
    androidMain
    source sets of a kotlin multi-platform project?
    s
    2 replies · 2 participants
  • s

    Samir Basnet

    04/26/2021, 7:12 AM
    @cb I noticed that while using Coil in lazy list to load images if i use drawable instead of url then the performance is quite laggy . Is it loading image from url in background thread and from drawable resource in main thread???
    s
    c
    +1
    10 replies · 4 participants
  • c

    Chachako

    04/26/2021, 8:24 AM
    When the
    Text
    beginning is
    .
    and
    maxLines
    is
    2
    , it is inconsistent with the display effect of Android. Is this intentional? As you can see, Annex 1 is the effect displayed by Android (expected), and Annex 2 is Compose.
    👀 1
    j
    s
    4 replies · 3 participants
  • a

    allan.conda

    04/26/2021, 9:47 AM
    How did the compose Material icons get compiled into
    ImageVector
    ? Currently our design system are all
    Painter
    loaded from the vector drawables.
    a
    c
    +2
    8 replies · 5 participants
  • s

    Shivam Sethi

    04/26/2021, 10:49 AM
    Is it just me or is Android Studio Canary 14 (latest) not suggesting any modifier methods to anyone else also ? I am having a hard time styling composables , I know just few of them on top of my head.
    😒ame: 2
    ➕ 2
    s
    s
    +3
    8 replies · 6 participants
  • p

    Paul Woitaschek

    04/26/2021, 12:28 PM
    Is there any way to make compose not clip it's contents? I have this compsable inside a recycler view and yet clipChildren is set to false it clips the shadows. The layout bounds are the bounds of a whole composable and it seems to even clip them within a composable
    c
    a
    +2
    30 replies · 5 participants
  • j

    julioromano

    04/26/2021, 1:17 PM
    Is there a way to draw multi-level menus with
    DropdownMenu
    (i.e. have `DropdownMenuItem`s open a sub-
    DropdownMenu
    ) ?
    c
    z
    8 replies · 3 participants
  • p

    Paul Woitaschek

    04/26/2021, 1:37 PM
    I'd love to see this published 😍 https://android.googlesource.com/platform/frameworks/support/+/androidx-main/compose/material/material/icons/generator/src/main/kotlin/androidx/compose/material/icons/generator/ImageVectorGenerator.kt
    ☝️ 3
    l
    a
    2 replies · 3 participants
  • l

    loloof64

    04/26/2021, 1:48 PM
    Hi ! I'm have a strange issue with Android Studio (Arctic Fox). Yesterday I left my code without error, but when loading my project this afternoon, A.S reported plenty of errors (my code is unchanged). Did someone had this error and had a solution ? Also I can run my project on the device. Just an IDE error
    s
    c
    +1
    7 replies · 4 participants
  • l

    loloof64

    04/26/2021, 3:22 PM
    It seems I am linking leaking memory in my
    @Composable
    , I know which part of code is responsible, but don't know exactly how to fix the issue. More on thread
    d
    c
    +2
    34 replies · 5 participants
  • d

    Denis Ismailaj

    04/26/2021, 3:32 PM
    Here’s a gist for an animated page indicator that may come in handy: https://gist.github.com/denis-ismailaj/521417c3e519032c6b4e5f49e8f3d5c8
    Screen Recording 2021-04-26 at 5.27.09 PM.mov
    👍 2
    o
    m
    20 replies · 3 participants
  • n

    Nat Strangerweather

    04/26/2021, 5:59 PM
    I have a small Box in a big Box. The large Box has a width of
    Modifier.fillMaxWidth
    . The small Box has a width of
    Modifier.fillMaxWidth(1 / 7f)
    . Elsewhere in my code outside my Composable I am defining an animation. There, I need the offset of my small Box to be the same as its width. Is there any way to use
    Modifier.fillMaxWidth
    as a variable? If not, how can I get the right width for my offset?
    z
    5 replies · 2 participants
  • a

    Arkadii Ivanov

    04/26/2021, 6:01 PM
    Trying to update Compose from beta03 to beta05 and hitting the following Lint crash (inside the thread). Is it a known issue? What could be a problem?
    l
    5 replies · 2 participants
  • d

    Denis Ismailaj

    04/26/2021, 6:12 PM
    Encountered a bug in beta05 where `Image`s don't recompose properly.
    YouCut_20210426_200823981.mp4
    t
    4 replies · 2 participants
  • d

    Doris Liu

    04/26/2021, 7:10 PM
    Call for mocks and use cases for screen level transition. 🙂 As we are building low level animation support for transition from screen to screen, we would love to support the use cases that you wish to build.😄 If you could add to the thread your use cases (preferably in video format, but static mocks + descriptions would do), we'll surely take them into consideration. 🙇
    🤩 2
    👍 10
    ❤️ 11
    👍🏽 1
    c
    a
    +9
    24 replies · 12 participants
  • r

    robnik

    04/26/2021, 8:32 PM
    If I draw some dots on a Canvas with drawCircle, is there a way to put some shadows behind each dot? (I'm porting some iOS/CoreGraphics code, a scatter plot with shadows behind the points.)
    1 reply · 1 participant
  • c

    Colton Idle

    04/26/2021, 8:34 PM
    Does anyone have a working solution to get around the compose kotlin version check that works in a .kts build file?
    j
    2 replies · 2 participants
  • j

    Justin Tullgren

    04/26/2021, 8:53 PM
    Does anyone know if the compose kotlin compiler plugin will remove code added by other plugins? Ex. In a irBlockBody a statement is added but then the compose compiler comes along and it don't see it after
    a
    l
    +1
    26 replies · 4 participants
  • c

    Colton Idle

    04/26/2021, 9:22 PM
    Is there such thing as an absolute layout in Compose? Details in thread.
    a
    k
    11 replies · 3 participants
  • r

    raenardev

    04/26/2021, 10:09 PM
    Hey. Is there any updates about this kind of API? https://kotlinlang.slack.com/archives/CJLTWPH7S/p1596215337162600 I needed to do something like TextInputLayouts
    prefix
    - to create phone prefix for input field. Since i needed only visual part, and didn’t need to modify resulting string -> i ended up making it work with
    VisualTransformation
    But what if i need to filter out some characters or modify resulting string in some way?
    phone_input.mov
    s
    15 replies · 2 participants
Powered by Linen
Title
r

raenardev

04/26/2021, 10:09 PM
Hey. Is there any updates about this kind of API? https://kotlinlang.slack.com/archives/CJLTWPH7S/p1596215337162600 I needed to do something like TextInputLayouts
prefix
- to create phone prefix for input field. Since i needed only visual part, and didn’t need to modify resulting string -> i ended up making it work with
VisualTransformation
But what if i need to filter out some characters or modify resulting string in some way?
phone_input.mov
s

Siyamed

04/26/2021, 10:11 PM
You already have to modify string, so i guess it is that you change the string that is passed in.
Compose will inform the rejection or change to ime (afaik by restarting the input)
I ak also not sure what is 'modifying string'
r

raenardev

04/26/2021, 10:27 PM
Say i want to filter out some characters:
val fixedPhone = phone.filterNot { it in 'a'..'z' }
I guess i can do that higher up, while forming a state for input, since we don’t store state in it anymore. But what happens with that - is cursor jumps to next character everytime i input a letter instead of number. IIRC with InputFilter i didn’t move cursor in such case - pressing invalid character just did nothing.
s

Siyamed

04/26/2021, 10:31 PM
I didnt check input code but: • ime says this is new string, this is where cursor is • If app want to change state, moves to state to something it would like (i.e. reject a char and put the cursor back) • Compose informs ime to restart the input with the given cursor and input
Not sure what exactly Input Filter was doing but there is not much to do other than the flow above. It is possible that inoutfilter was trying to be clever, but now cursor can be set at the same callback/input flow
If there is a bug in that flow please feel free to create a ticket. But at the end of the day there is one state on ime side and 'almost' none on compose
So that case, putting the cursor back where it should be, becomes an app concern. It is possible to write some utilities once we know better about use cases or an api. InputFilter api didnt look applicable to TextField because of the state hoisting
I will try to implement an example like that to see what happens.
r

raenardev

04/26/2021, 10:40 PM
InputFilter api didnt look applicable to TextField because of the state hoisting
Yeah, i agree
putting the cursor back where it should be, becomes an app concern
Is there an API for that available now? Say i have made changes to phone string. I would pass modified string to PhoneInput to render. But what about cursor position?
@Composable
fun PhoneInput(phone: String, onPhoneChanged: (String) -> Unit) {
    BasicTextField(value = phone, onValueChange = onPhoneChanged)
}
s

Siyamed

04/26/2021, 10:41 PM
There is a TextFieldValue overload of the same function
TextFieldValue.selection is the cursor when the TextRange in it has the same start/end
🔥 1
r

raenardev

04/26/2021, 10:50 PM
Awesome! And the same is true for
onValueChange
Seems like i have everything i need for now, will try it out tomorrow. Thank you 🙂
👍 1
Also - it would be really helpful to have this info (about filtering some input and working with
TextFieldValue.selection
) somewhere in the docs: https://developer.android.com/jetpack/compose/text#enter-modify-text I searched for this for a while, before coming to slack. Again, tnx for your quick response 🙂
s

Siyamed

04/26/2021, 10:53 PM
Cc @yrezgui
View count: 2