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

    Utkarsh Tiwari

    10/29/2021, 9:48 AM
    Is there any way to achieve this kind of ordered list of text? Please notice the varied spacing between the numbers and the text.
    f
    d
    z
    • 4
    • 5
  • o

    olonho

    10/29/2021, 11:07 AM
    https://blog.jetbrains.com/kotlin/2021/10/compose-multiplatform-goes-beta/
    :compose-desktop: 12
    ❤️ 12
    :jetpack-compose: 19
    :kotlin-intensifies: 31
    d
    b
    • 3
    • 2
  • a

    Arpit Shukla

    10/29/2021, 1:44 PM
    I have a text field where I want a numerical input. I set keyboardType to KeyboardType.Number. But what I see is that I can type multiple decimals as well as commas in the TextField. Will I have to do all this validation myself? Also, I saw that when I press and hold the delete button it only deletes one digits and doesn't start deleting the remaining digits? Is this intentional or a bug?
    z
    • 2
    • 1
  • p

    Piotr Krzemiński

    10/29/2021, 2:09 PM
    Hi! Does Compose support iOS? From what I see, it's just Android, desktop and web
    🤞 2
    🇳🇴 7
    f
    j
    +5
    • 8
    • 30
  • d

    Diego

    10/29/2021, 3:14 PM
    Why do we need
    LazyColumn
    if we can do the same thing with a vertical scrollable
    Column
    ? Is it because performance-wise the LazyColumn is better? 🤔
    f
    c
    • 3
    • 2
  • s

    Sergey Y.

    10/29/2021, 3:32 PM
    Hi. I have a question. How do I wait for the
    AnimatedContent
    transition to complete? Is there a callback for this? Well, I found that the
    AnimatedVisibilityScope
    has the
    transition
    attribute with the
    isRunning
    property. Is this the correct way to use it? I want to fire my action after the animation ends. Thanks.
    d
    • 2
    • 1
  • b

    Brian G

    10/29/2021, 5:19 PM
    When a box is too big for its parent, it gets center aligned, ignoring the "content alignment" field. Is there any way to make it align top? E.g.
    Box(Modifier.fillMaxSize(), contentAlignment = Alignment.TopStart) {
        Box(Modifier.fillMaxWidth().background(Color.Black).requiredHeight(1200.dp), contentAlignment = Alignment.TopStart) {
            Text("top", Modifier.requiredHeight(300.dp).background(Color.Red).align(Alignment.TopCenter))
            Text("middle", Modifier.requiredHeight(300.dp).background(Color.Green).align(Alignment.Center))
            Text("bottom", Modifier.requiredHeight(300.dp).background(Color.Blue).align(Alignment.BottomCenter))
        }
    }
    z
    b
    • 3
    • 4
  • m

    Marcello Galhardo

    10/29/2021, 5:40 PM
    Hi! Does anyone know if there are downsides of using a
    MutableState
    and
    State
    inside a
    ViewModel
    ? For example, why would someone choose a
    MutableStateFlow
    in a
    ViewModel
    and do a
    collectAsState
    instead of simple using a
    MutableState
    at first place? 🤔
    b
    e
    • 3
    • 12
  • a

    Alexander Suraphel

    10/29/2021, 6:10 PM
    my project doesn’t seem to find
    Modifier.fillParentMaxWidth()
    what am I missing?
    k
    • 2
    • 4
  • c

    Chris Johnson

    10/29/2021, 8:15 PM
    Is there a reason the nullable operator +
    let
    is broken going from version 1.0.1 of compose to alpha01? Code in thread.
    ➕ 1
    j
    c
    • 3
    • 21
  • m

    Mehdi Haghgoo

    10/29/2021, 8:44 PM
    Does Compose UI get translated to Android Views under the hood to create native UIs and interact with the Android framework?
    j
    o
    r
    • 4
    • 15
  • f

    Felix Schütz

    10/30/2021, 12:44 AM
    Is it possible to reopen https://github.com/google/accompanist/issues/729? I think this should be adressed.
    i
    • 2
    • 6
  • m

    Miguel Vargas

    10/30/2021, 1:46 AM
    I use Compose’s
    fun StateFlow<T>.collectAsState()
    without initial value so I don’t have to come up with some empty object while the ui waits for the ViewModel to figure out what should be drawn. But when I want to log each emission it breaks because
    Flow<T>.collectAsState
    does require an initial.
    class ViewModel {
      val myStateFlow = _myStateFLow
          .onEach { logger.i("check $it out!") } 
       // onEach casts it to Flow, not a StateFlow any more :(
    }
    Any ideas for a workaround?
    s
    k
    s
    • 4
    • 4
  • l

    lhwdev

    10/30/2021, 2:22 AM
    While tracing some button layout problems, I found
    .minimumTouchTargetSize()
    was added to Surface. Button should extend to minimum touch target size, but it seems only the Surface (in the
    Button.kt
    ) extended, Row didn't extended. Is this expected behavior?
    • 1
    • 4
  • f

    Florian

    10/30/2021, 11:01 AM
    How do I call a ViewModel method in MainActivity's
    onStart
    when using compose? Do I create a property and initialize it in
    setContent
    ? In the past I would've used by
    viewModels()
    . Or should I use something like this?
    y
    m
    • 3
    • 4
  • a

    Arsen

    10/30/2021, 10:56 PM
    Have question about "Snapshot system" in multithreaded environment: Is there a way to read global snapshot's state value to make decission of "apply() or dispose() previously taken mutable snapshot" in a sync manner (i.e. lock on mutex to avoid "advanceGlobalSnapshot" between "check statement" and mySnapshot.apply call). For simple cases, there is a SnapshotMutationPolicy to make decission that depends on "previous" value, but let's assume that for some reason we need to check value of another "State object". Consider following example:
    val catsState = mutableStateListOf<Cat>()
    val sortState = mutableStateOf("ASC") // [ASC, DESC]
    
    // ------ Worker Thread ---------
    val snapshot = Snapshot.takeMutableSnapshot()
    
    val sort = sortState.value
    val cats = fetchCoolCatsFromNetwork(sort)
    
    snapshot.enter {            
        catsState.clear() 
        catsState.addAll(cats) 
        
        Snapshot.lockOnGlobalSnapshot { // Does it possible?
            val sortOfActualGlobalSnapshot = sortState.value
            if(sortOfActualGlobalSnapshot == sort) {
                snapshot.apply()
            } else {
                snapshot.dispose()
            }
        }
    }
    P.S. State hoisted to ViewModel
    :thread-please: 2
    z
    c
    • 3
    • 6
  • e

    enighma

    10/31/2021, 1:59 AM
    Is the Glance widget API available to use yet? or is it coming in a later androidx release? Context:

    https://www.youtube.com/watch?v=15Q7xqxBGG0&amp;t=1s▾

    ➕ 2
    i
    s
    p
    • 4
    • 6
  • a

    Arpit Shukla

    10/31/2021, 9:32 AM
    Can someone please help me which this issue? https://stackoverflow.com/questions/69785477/compose-textfield-shows-wierd-behavior
    r
    • 2
    • 4
  • a

    Adib Faramarzi

    10/31/2021, 1:37 PM
    Is there any way to animate a
    LazyColumn
    ’s items to appear with an animation?
    n
    r
    • 3
    • 4
  • c

    Cicero

    10/31/2021, 4:13 PM
    Hey, I saw a lot of "Reasons not to use GlobalScope" but what are the alternatives when you can't reach a scope? Do I always need to pass down an activity reference? I have a singleton watching network state and pushing this state as it changes into a singleton flow. The way I need to handle some of this processing will always require a thread but it's not guaranteed I will have short access to a scope. What is your solution? What is our community default solution?
    b
    • 2
    • 21
  • m

    mertceyhan

    10/31/2021, 5:12 PM
    Hi all! I want to write a unit test for this code block and I’m sending multiple values to the State class, is it possible to collect values of the state? Like; values[0] == Loading values[1] == Success
    r
    a
    m
    • 4
    • 11
  • v

    Vivek Sharma

    10/31/2021, 7:16 PM
    I am drawing a line in
    Canvas
    and then
    rotating
    it by
    angle 45f
    , is there a way to get that
    end Offset
    till the line is rotated How can I get/access this Offset
    (?,?)
    ?
    a
    t
    m
    • 4
    • 4
  • a

    Alex C

    11/01/2021, 4:18 AM
    Hey all Does anyone know how to make the animated vector animates infinitely?
    val image = animatedVectorResource(id = R.drawable.animated_vector)
    val atEnd by remember { mutableStateOf(false) }
    Icon(
        painter = image.painterFor(atEnd = atEnd),
        contentDescription = null // decorative element
    )
    e
    d
    n
    • 4
    • 9
  • c

    Ch8n

    11/01/2021, 8:19 AM
    Hi is there a way to control to disable dismiss of
    ModalBottomSheetLayout
    when the unfocused/background region is pressed?
    r
    • 2
    • 2
  • c

    Colton Idle

    11/01/2021, 9:47 AM
    If I set
    backgroundColor
    of
    BottomNavigation
    to Color.Red, it turns Red. If I set
    backgroundColor
    of
    BottomNavigation
    to Color.Black, it turns Grey. Why and how do I make it black?
    k
    a
    • 3
    • 2
  • t

    Tolriq

    11/01/2021, 9:57 AM
    Elevation to 0 if you are in dark mode
    c
    • 2
    • 1
  • n

    nlindberg

    11/01/2021, 10:20 AM
    Anyone else had an issue with AnimatedVisibility using fadeIn / fadeOut where the content has a complex shaped background & shadow. In the fadeIn part of the animation it’s treating the background and shadow as if it was not defined with the Shape and then in the end it’s adding the shadow and complex background shape in an instant. If I just use e.g. slideInVertically alone it works fine. This is the code (I also tried only with the fade animation and clip = true):
    AnimatedVisibility(
        visible = viewModel.show,
        enter = slideInVertically() + fadeIn(initialAlpha = 0f),
        exit = slideOutVertically() + fadeOut()
    ) {
    Box(
        modifier = Modifier
            .shadow(elevation = 5.dp, shape = TooltipShape(0.7f), clip = false)
            .background(color = Color.White, shape = TooltipShape())
            .padding(horizontal = 12.dp, vertical = 14.dp)
    ) {
        content()
    }
    d
    • 2
    • 1
  • a

    Arpit Shukla

    11/01/2021, 11:06 AM
    How can I access stringResource inside LaunchedEffect block?
    z
    • 2
    • 1
  • l

    lesincs

    11/01/2021, 12:05 PM
    Weird bug when `Scaffold`’s
    bottomBar
    using a
    wrapContentHeight
    Modifier.
    a
    • 2
    • 5
  • m

    Michal Klimczak

    11/01/2021, 3:31 PM
    Crossfade animation with custom diff lambda 🧵
    d
    t
    • 3
    • 10
Powered by Linen
Title
m

Michal Klimczak

11/01/2021, 3:31 PM
Crossfade animation with custom diff lambda 🧵
I have some sealed class for state and it can be different data classes, e.g.
data class SearchSuggestions(
        override val searchPhrase: String,
        val suggestions: List<String>
    ) : ShopScreenState(), HasSearchPhrase

    data class SearchRecents(
        override val searchPhrase: String,
        val recentSearches: List<String>
    ) : ShopScreenState(), HasSearchPhrase
Now I want a nice crossfade when
SearchSuggestions
changes into
SearchRecents
and vice versa. But don't want the crossfade to "blink" every time e.g.
SearchRecents
changes to a different
SearchRecents
I don't want to get rid of data class magic, too, it's useful in other places. Its equals should not change. What I want is to compare different states myself and only then crossfade one state to another, but still be able to use the whole state internally, e.g. like this
Crossfade(state, diff = { previousState, newState -> previousState::class != newState::class }){ 
   when(it)... //`it` should still be ShopScreenState, so that it's smartcasted and preserved across animation
}
am I missing something obvious?
(CC: @Doris Liu, hope you don't mind)
I guess I can do my own Crossfade, but if what I wrote makes sense, I wonder if I should also file a feature request
d

Doris Liu

11/01/2021, 5:37 PM
Thanks for the request. We have recently added the support for
contentKey
in AnimatedContent, where the
contentKey
can be defined for each target, and is being used for diffing. You can use that for your use cases. The support in crossfade is coming, tracked here: https://issuetracker.google.com/197907070 In the meantime, I'd encourage you to try out
contentKey
and let us know if you have any other feature requests. See https://developer.android.com/reference/kotlin/androidx/compose/animation/package-summary#(androidx.compose.animation[…].Function1,kotlin.Function2)
❤️ 2
m

Michal Klimczak

11/01/2021, 5:55 PM
Awesome, thank you Doris!
(I starred the issue, I assume it concerns the crossfade as well and another issue is not required)
d

Doris Liu

11/01/2021, 5:57 PM
Yup. No need to file another issue. 🙂
t

Thomas

11/02/2021, 8:10 PM
@Doris Liu I just took a look at
contentKey
and it should do exactly what I want. Thanks for adding it! However, it looks like you missed a function. Is there a reason
contentKey
was not added here? https://cs.android.com/androidx/platform/frameworks/support/+/androidx-main:compose/[…]ent.kt;l=119-129;drc=4b91a7fe67a0a791829b42dbccb4e80f7beaaf74
d

Doris Liu

11/02/2021, 8:13 PM
Thanks for the follow-up @Thomas . We didn't add contentKey to
AnimatedContent
(i.e. non-extension fun version) intentionally to keep that version simple and therefore easy to learn.
👍 1
View count: 3