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

    daivid

    05/28/2021, 7:40 PM
    Hey o/ I was trying to implement a slowly moving background for a project using compose. I started using the canvas, paths and bezier curves for that. With that approach I’m having trouble making the waves, well… wavy… Then a colleague suggested using animated vector resources. It works more or less… I can use it and animate between paths to achieve the waves… but… using the
    animatedVectorResource
    and the
    AnimatedImageVector
    ’s
    painterFor
    , it seems that all I can control is the direction of the animation with
    atEnd
    . Is there a way to get more control over the animated vector animation? I’d like to be able to loop the animated vector’s animation infinitely. Ideally with multiple steps to the animation (to improve the waviness of my background)
    m
    • 2
    • 2
  • t

    Tiago Nunes

    05/28/2021, 8:37 PM
    Hey everyone, I'm getting a weird bug with LazyRow... for some reason, when I scroll through 4 cards, the next cards are EMPTY! When I scroll back, the old cards are also empty... What am I doing wrong?
    @Composable
    fun HeaderCards(users: List<User>) {
        LazyRow(
            contentPadding = PaddingValues(horizontal = 10.dp),
            modifier = Modifier
                .fillMaxWidth(),
        ) {
            items(users) { user ->
                HeaderCard(user)
            }
        }
    }
    z
    c
    • 3
    • 4
  • d

    Daniel

    05/28/2021, 10:08 PM
    I'm struggling to draw a Painter to a Bitmap. The confusing thing is that the docs for painter say
    In addition to providing the ability to draw into a specified bounded area,
    Painter
    provides a few high level mechanisms that consumers can use to configure how the content is drawn.
    However, the entire public api is just the property
    intrinsicSize
    and the extension function
    DrawScope.draw
    . Confusingly
    draw
    doesn't take the painter as an argument, so I'm not sure how it could work. This is as far as I got:
    val painter = painterResource(R.drawable.marker)
        val size = painter.intrinsicSize
        val image = ImageBitmap(size.width.roundToInt(), size.height.roundToInt())
        val canvas = Canvas(image)
        CanvasDrawScope().draw(LocalDensity.current, LocalLayoutDirection.current, canvas, size) {
        }
    n
    • 2
    • 3
  • t

    tad

    05/28/2021, 11:21 PM
    Any Compose folks want a method sample trace to see a pathological case of scroll delay in LazyColumn?
    👀 1
    👍 1
    • 1
    • 4
  • d

    Daniel

    05/29/2021, 12:07 AM
    I need to have a composable and an android view collaboratively detect pointer events in a view. I want the composable to get access to the events first, and decide if it wants to exclusively handle them or if it wants the view to see them as well. Because I need to switch which composable renders above the android view without recreating the android view, (I think) I need them to be siblings.
    Box(Modifier.fillMaxSize()) {
            AndroidView(/* ... */)
            
            when (foo) {
               is Bar -> Box(Modifier.fillMaxSize().pointerInput(key) { /* ... */ }
               is Buzz -> Box(Modifier.fillMaxSize().pointerInput(key) { /* ... */ }
               / * ... */
            }
    }
    The problem is both
    Modifier.pointerInteropFilter
    (even returning false) and
    Modifier.pointerInput
    (even with an empty block) prevent the view from seeing any pointer events.
    f
    • 2
    • 1
  • m

    Michael Paus

    05/29/2021, 5:14 AM
    Does Compose have a concept to explicitly ask for a recomposition? I am currently using some dummy state for that but that looks awkward.
    z
    a
    • 3
    • 7
  • a

    Abdalla Hassanin

    05/29/2021, 9:58 AM
    how to Localization my app in compose without string XML file
    z
    t
    +2
    • 5
    • 12
  • a

    Akram Bensalem

    05/29/2021, 9:58 AM
    How to modify padding inside TextField ?! The default text padding is very tiny I want to modify it without give more height to the whole TextField Is any one have an idea how to do it ?!
    m
    • 2
    • 1
  • a

    André Thiele

    05/29/2021, 12:28 PM
    Does the automatic saved state population of navigation arguments only work with HiltViewModel or is it also populated when using Koin for instance? Or do I need to use hiltNavGraphViewModel? (as shown here:

    https://youtu.be/0z_dwBGQQWQ?t=968▾

    )
    v
    s
    i
    • 4
    • 16
  • m

    Michal Klimczak

    05/29/2021, 1:26 PM
    I had a piece of code that behaved in a way that I cannot understand:
    //causes infinite recomposition
        val playerUiStateWrong by player.observeState()
            .map { PlayerUIState(it, sound) }
            .collectAsState(PlayerUIState(null, null))
    
        //works fine
        val playerState by player.observeState().collectAsState(PlayerState.Stopped)
        val playerUiState = PlayerUIState(playerState, sound)
    I thought they would both do the same thing, but the first one, whenever I use
    playerUiStateWrong
    as a parameter in a modifier, causes infinite recompositions, whereas the second one works fine.
    a
    z
    • 3
    • 15
  • s

    Sunny

    05/29/2021, 2:26 PM
    Can somebody help, need help in gesture part of jetpack compose https://stackoverflow.com/questions/67752131/long-press-gesture-in-jetpack-compose
    z
    d
    • 3
    • 4
  • c

    codeslubber

    05/29/2021, 2:30 PM
    Went into the beta and tried to make a new project with an empty Compose view. That didn’t work. So I did upgrade to beta 3 from Canary and cannot make a new one here either.
    a
    • 2
    • 5
  • t

    theapache64

    05/29/2021, 4:34 PM
    ✅ [RESOLVED] What does it means? 🤔
    a
    k
    c
    • 4
    • 7
  • z

    Zun

    05/29/2021, 7:03 PM
    I'd like to use the Palette API to generate the dominant color from a remote Image inside a ViewModel. I am a bit confused as to how to retrieve the Bitmap when using an image loading library such as Coil that's included into Accompanist. Anyone got ideas? FWIW, this is what my image loader code looks like right now
    c
    • 2
    • 4
  • d

    Daniel

    05/29/2021, 11:26 PM
    Since there's not a compose exposed dropdown menu yet I built one myself (there's a WIP patch somewhere, but it uses a lot of compose internals so it's hard to copy). I'm happy with how it looks, but not with the complexity of the code. Is there a way to avoid needing subcomposeLayout but get the same result? Thanks! https://gist.github.com/danielzfranklin/a54260971aa51b2e2c4140c741f7650b
    c
    z
    • 3
    • 5
  • a

    André Thiele

    05/30/2021, 9:00 AM
    ✅ [RESOLVED] Anybody who can help me with Koin and Navigation Compose? Android Team said in a video that its possible to extract the passed in navigation arguments from the saved state handle. They used Hilt in their video, but i want to use Koin. This is how I am currently trying to achieve it, but the ID that I am passing to screen is null regardless.
    c
    • 2
    • 2
  • s

    Shakil Karim

    05/30/2021, 10:59 AM
    Hi, is there any example of how can i use Navigation Compose 2.4.0-alpha01 new method currentBackStackEntryAsFlow(), I noticed @cb Tivi project is using this approach do we still need OnDestinationChangedListener or we can achieve the same with currentBackStackEntryAsFlow()?
    i
    • 2
    • 3
  • y

    Yuri Drigin

    05/30/2021, 11:13 AM
    Hi folks. Please help. I have crash
    java.lang.IllegalStateException: pending composition has not been applied
    in this code. Where I’m wrong?
    Untitled.kt
    s
    a
    • 3
    • 8
  • t

    Tiago Nunes

    05/30/2021, 11:46 AM
    Hey everyone, is there a way to assign a weight sum to a Row, like there is with LinearLayouts? For example, I have this:
    Row {
        columns.forEach {
            Card(Modifier.weight(1f))
        }
    }
    In my case the number of columns is dynamic, and the max number of columns is 3 And I get a row looking like this, when I have 3 columns: (each card has weight 1) [ ] [ ] [ ] And when there is only 1 column, I get this: (each card has weight 1) [ ] I wanted to get this: (each card has weight 1, weight sum is 3) [ ]
    a
    v
    z
    • 4
    • 6
  • v

    Vitaliy Zarubin

    05/30/2021, 12:30 PM
    Please tell me how to add the addOnDestinationChangedListener correctly
    s
    j
    i
    • 4
    • 3
  • k

    Kirill Grouchnikov

    05/30/2021, 12:49 PM
    How are people tracking selection state in
    LazyColumn
    ? Something like this multi-column layout (which might be for tablets on Android, or for larger screens on desktop) where the middle column is a lazily loaded list of articles / emails / etc, and the right column is the full detail of the selected element.
    e
    • 2
    • 1
  • h

    Hachemi Hamadi

    05/30/2021, 12:54 PM
    How can we make a Box zoomable, I did try it images and it works fine. But i want to make a box zoomable (like it can grow and shrink depending on user gesture)
    val scale = remember { mutableStateOf(1f) }
    
    Box(modifier = Modifier
        .height(250.dp)
        .fillMaxWidth()
        .background(color = Color.White)
        .graphicsLayer(
            scaleX = maxOf(.5f, minOf(3f, scale.value)),
            scaleY = maxOf(.5f, minOf(3f, scale.value)),
        )
        .pointerInput(Unit) {
            detectTransformGestures { centroid, pan, zoom, rotation ->
                scale.value *= zoom
            }
        }
    )
    z
    • 2
    • 2
  • a

    Aditya Thakar

    05/30/2021, 1:31 PM
    Hi, I am playing with Dialog and vertical scroll, when I click a button inside Dialog, it scrolls to top. How can I keep the scroll position intact on button click?
    • 1
    • 3
  • n

    Nikhil

    05/30/2021, 5:54 PM
    Hi everyone! 😄 I tried creating Neumorphism UI with Jetpack Compose. You can take a look at the lib/code here - https://github.com/CuriousNikhil/neumorphic-compose I’m learning this and probability of the code being correct/holding best practices may be less. 😅 I’ve a couple of questions. The idea is simple, I’ve created a custom modifier by extending the
    DrawModifier
    and I’m drawing the shadows using
    contentDrawScope
    provided by
    DrawModifier
    . 1. First of all, Is this a correct to extend the modifiers? 2. To render the shadows(GradientDrawable) smoothly, I’m using RenderScript (I know it’s going to be deprecated in the Android12. I’ll migrate.). I need
    context
    param to invoke renderscript api. Is it okay to pass
    context
    param in the Modifier?
    :jetpack-compose: 6
    💣 4
    d
    c
    • 3
    • 6
  • z

    Zhelyazko Atanasov

    05/30/2021, 6:07 PM
    I have a very peculiar use case for a
    TextField
    / text input. I'm building an app for mobile phones that have hardware barcode scanners. When the user scans a barcode, the actual barcode is transmitted as a sequence of key events. In a
    View
    world I have an
    EditText
    that is focused, so when a user scans a barcode, its value is entered into the
    EditText
    and I can just do
    editText.text.toString()
    to get the value of the scanned barcode + the user sees what was scanned. As the user is expected to use the barcode scanner for input, the on-screen software keyboard must not be shown. This was easy to do with
    EditText
    . Now I wanted to replicate the same functionality in Compose using a
    TextField
    . Unfortunately, I can't find a way how to do that. If you specify
    readOnly = true
    , then the
    CoreTextField
    doesn't use the
    TextInputService
    and the TextField is not listening for any input key events. It seems that
    readOnly
    is suited for cases where we'll just display data, like a Calculator app. Then I went deeper into `CoreTextField`'s implementation and decided to try another approach. I created a composable that didn't use any
    TextField
    . Instead, I got a reference to the
    LocalTextInputService.current
    , created an
    EditProcessor
    instance and called
    startInput()
    like so:
    @Composable
    fun ScannerInput() {    
        val textInputService = LocalTextInputService.current
        var textFieldValue = remember { mutableStateOf(TextFieldValue()) }
        val editProcessor = EditProcessor()
    
        textInputService?.startInput(
            value = textFieldValue.value,
            imeOptions = ImeOptions.Default.copy(singleLine = true),
            onEditCommand = {
                val newValue = editProcessor.apply(it)
                Log.d("Scanner", "onEditCommand: $newValue")
            },
            onImeActionPerformed = {
                Log.e("Scanner", "onImeActionPerformed: $it")
            }
        )
    }
    The thing is that down into the implementation of
    TextInputService
    , it's making a call to
    showSoftwareKeyboard()
    and the keyboard is shown 😞 Any idea what else I could try, as this is a core part of my app and the requirement is strictly never to show the on-screen software keyboard 🤔
    a
    • 2
    • 3
  • a

    Alexander Karkossa

    05/30/2021, 8:37 PM
    Hey. Maybe someone can help me. After the change to
    compose 1.0.0-beta07
    various items disappear when scrolling in
    LazyColumn
    . I could reproduce the problem in a minimal example by inserting a
    Box
    inside a
    LazyColumn
    between
    AnimatedVisibility
    and the actual
    Card
    (the same happens with e.g.
    Column
    ). Example in my answer
    k
    • 2
    • 6
  • t

    Tlaster

    05/31/2021, 3:29 AM
    Can we expect to have kotlin 1.5 support in beta08?
    a
    • 2
    • 1
  • c

    Colton Idle

    05/31/2021, 4:35 AM
    Anyone know how to use accompnist/coil +
    Crossfade()
    ? The docs state that you CAN crossfade, but not exactly how? I also looked at Owl sample app but didn't see usage of crossfade either.
    a
    c
    • 3
    • 8
  • s

    Sunny

    05/31/2021, 6:30 AM
    How to determine in which direction lazy list is being scrolled?
    a
    • 2
    • 1
  • i

    iamthevoid

    05/31/2021, 6:59 AM
    Is it possible to animate AppBar navigationIcon appearance? I mean not only of navigationIcon anim in-out, but navigation title slide. I mean exactly smooth swithing between next AppBar states
    a
    • 2
    • 9
Powered by Linen
Title
i

iamthevoid

05/31/2021, 6:59 AM
Is it possible to animate AppBar navigationIcon appearance? I mean not only of navigationIcon anim in-out, but navigation title slide. I mean exactly smooth swithing between next AppBar states
a

Arkadii Ivanov

05/31/2021, 9:21 AM
I would put separate AppBars on each screen, so they would animate together with the content.
i

iamthevoid

05/31/2021, 9:38 AM
Do you mean transition animation for full screen?
a

Arkadii Ivanov

05/31/2021, 9:39 AM
Yeah, this is how I am doing it usually.
But if you really need separate animations for AppBars elements, the you need another solution.
i

iamthevoid

05/31/2021, 9:43 AM
I think that the best solution for what i am trying to do is to create custom app bar )
a

Arkadii Ivanov

05/31/2021, 9:46 AM
It depends on the UI design and architecture requirements. In all apps I worked on - the AppBar was always screens' implementation details. But if you have such a design requirement, to animate items of the AppBar individually, then you need a custom solution indeed.
If you need to animate items individually, then maybe
AnimatedVisibity
will help?
i

iamthevoid

05/31/2021, 10:12 AM
I am afraid that it doesn’t ) Maybe it could works for nav icon (I am new in compose and don’t sure), but as i understood from code below row with fixed size just appears if set and title move to right with no anim
a

Arkadii Ivanov

05/31/2021, 10:14 AM
Yeah, I meant if you will ever implement a custom app bar 😀
View count: 1