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

    Adrian Tappe

    11/01/2021, 5:03 PM
    I have an issue with
    SwipeToDismiss
    state when navigating back and forth between screens. I would like to
    reset
    (suspend function) the
    dismissState
    as part of a cleanup. (Or “forget” that state when navigating back to this screen) Idea: When the user swipes out a Card in a LazyList the card stays in the swiped out state while a SnackBar appears. If the snackbar gets dismissed, the element is deleted via the viewModel. If the snackbar action (Undo) gets pressed, the dismissState gets reset. Problem: If I navigate to another screen, the coroutineScope the snackbar is opened gets cancelled. The dismissState will never be reset. When I navigate back to this screen, the swiped card will stay swiped. I tried but failed: A) Have a
    finally
    block in the coroutine to do the cleanup. B) Having a
    DisposableEffect
    seems to not work as I cannot access the compose state and have no coroutine scope. Sourcecode:
    edit: in thread
    t
    • 2
    • 24
  • m

    Mjahangiry75

    11/01/2021, 6:42 PM
    Does anybody know how can I design a layout like this?
    :not-kotlin: 4
    c
    k
    • 3
    • 7
  • a

    Afzal Najam

    11/01/2021, 9:15 PM
    What's the right way to have a LazyColumn inside a Column with
    verticalScroll
    modifier? For example in the Bloom AndroidDevChallenge app home screen.
    c
    n
    • 3
    • 5
  • a

    Andy Himberger

    11/02/2021, 12:29 AM
    This might be a dumb quesiton, but in the compose sample for produceState, there is an initial value of Result.Loading, what Result type is being used in the samples that include the .Loading member? I haven't been able to find a Result type to import with that support and want to avoid making a new one if it already exists somewhere produceState: convert non-Compose state into Compose state
    @Composable
    fun loadNetworkImage(
        url: String,
        imageRepository: ImageRepository
    ): State<Result<Image>> {
    
        // Creates a State<T> with Result.Loading as initial value
        // If either `url` or `imageRepository` changes, the running producer
        // will cancel and will be re-launched with the new keys.
        return produceState(initialValue = Result.Loading, url, imageRepository) {
    k
    • 2
    • 2
  • i

    itnoles

    11/02/2021, 2:58 AM
    How to find GlanceID for GlanceAppWidget?
    j
    • 2
    • 2
  • a

    Alexander Suraphel

    11/02/2021, 2:04 PM
    I haven’t fully understood why we wrap mutableStateOf with remember. Can someone please explain? Does a mutable state reset to initial value if it’s not wrapped in remember?
    a
    z
    • 3
    • 3
  • s

    Scott Kruse

    11/02/2021, 2:51 PM
    Seeing a crash related to compose not finding viewTreeLifecycleOwner, full stack trace in thread
    z
    • 2
    • 6
  • s

    Steffen Funke

    11/02/2021, 4:04 PM
    Would
    derivedStateOf
    be the State-equivalent of
    combine
    in Flow / Rx-World? Meaning, if one of the inputs change, the resulting state should be recalculated? And can this also safely be used inside a ViewModel? Background: I have e.g. a list and a search bar, and using
    MutableStateFlows
    inside my ViewModel for data streams. Whenever the search term changes, I
    combine
    the search term with the list, to filter it. Works well and solid, but I think about going full Compose also in my ViewModels, therefore replacing my
    MutableStateFlow
    s with Compose States. Is this the correct approach, using
    derivedStateOf
    ?
    :yes: 2
    a
    a
    • 3
    • 13
  • j

    James Harman

    11/02/2021, 4:08 PM
    Is it possible to change the animation when showing a Dialog? Currently when shown it kind of slides in from the left and expands (video and code in thread).
    • 1
    • 2
  • n

    nglauber

    11/02/2021, 5:27 PM
    Hello… Is there any workaround to make
    BringIntoViewRequester
    works in the following situation: 1.
    TextField
    is at the bottom of the screen and the user tap on it and it gain focus. 2. System keyboard is displayed and the
    TextField
    becoming visible because of the following:
    Modifier.bringIntoViewRequester(bringIntoViewRequester)
    .onFocusChanged {
        if (it.isFocused) {
            coroutineScope.launch {
                delay(300)
                bringIntoViewRequester.bringIntoView()
            }
        }
    }
    3. The user now press the system back key and the keyboard is closed, but the
    TextField
    still has focus. 4. Finally, if the user tap on the
    TextField
    again. The keyboard is opened on top of the
    TextField
    and the
    BringIntoViewRequester
    is not triggered again because the focus haven’t changed. I know there’s a ticket kinda related to this… https://issuetracker.google.com/u/0/issues/192043120 Any suggestion?
    r
    • 2
    • 4
  • c

    Colton Idle

    11/02/2021, 11:19 PM
    Is there any way to have a degree adjust for a linearGradient?
    Brush.linearGradient(listOf()))
    My designer keeps giving me stuff like this 😅
    background: linear-gradient(180deg, rgba(5, 64, 87, 0.5)
    and
    background: linear-gradient(215.31deg, rgba(255, 255, 255, 0.1)
    e
    c
    • 3
    • 11
  • m

    miqbaldc

    11/03/2021, 1:50 AM
    Unable to have interaction in Compose Preview Does it not possible to use list ADT e.g:
    HashSet
    as
    remember { mutableStateOf(hashSetOf()) }
    See video & snippet code in 🧵
    n
    z
    • 3
    • 12
  • c

    Colton Idle

    11/03/2021, 1:51 AM
    Might sound stupid, but does anyone have any tricks to remembering arrangement vs alignment? I find it to be like plugging in a USB cable... takes at least 2 or 3 tries to guess the one that I want. 😅
    j
    n
    s
    • 4
    • 3
  • j

    John Aoussou

    11/03/2021, 2:42 AM
    Hello, does anyone understand when you should use viewmodel + mutablestateOf() vs. using remember?
    n
    n
    +2
    • 5
    • 10
  • g

    Gumiku

    11/03/2021, 5:51 AM
    Hi , does anyone know why println("hello") will not be called if there is a composable inside the ?.let{}
    val name: String? = null
    name?.let {
          Box() {
    
          }
    } ?: println("hello")
    t
    j
    • 3
    • 3
  • c

    Colton Idle

    11/03/2021, 6:03 AM
    Is there a way to render the vector icons are in the IDE so I don't have to run my code to check the icon choice?
    s
    y
    +2
    • 5
    • 5
  • a

    Adib Faramarzi

    11/03/2021, 6:35 AM
    compose's
    setContent
    seems to be drawing too much CPU time. Is it natural?
    w
    a
    • 3
    • 20
  • b

    Bagadeshkumar R

    11/03/2021, 6:40 AM
    Hello guys, I been trying on compose to have a list view and if an item is selected then I need to make the selected item to move slightly to the right thereby making item drawing outside the lazy Column. How to achieve this? Any idea is welcome. Thanks in advance.
    s
    a
    a
    • 4
    • 11
  • s

    Steffen Funke

    11/03/2021, 7:23 AM
    Probably off topic: Does anyone know a dedicated Slack community like this for iOS / SwiftUI related stuff?
    f
    • 2
    • 2
  • y

    YASAN

    11/03/2021, 8:20 AM
    I am trying to write some tests for my Compose app but I am getting
    Default FirebaseApp is not initialized in this process com.livingmaples.videoplayer.test. Make sure to call FirebaseApp.initializeApp(Context) first.
    c
    • 2
    • 9
  • s

    Steffen Funke

    11/03/2021, 10:15 AM
    Does it make sense to cache values of frequently used calculations or extensions, like
    .dp
    ,
    RoundedCornerShape
    ,, etc. in some global space?
    // some global .kt file
    val cornerShape = RoundedCornerShape(3.dp)
    val imageSizeLarge = 120.dp
    ...
    Or does the Compose compiler take care of it, and we are free to reuse those same values all over the place? Or are they so cheap to create that it is even encouraged to write them out each time?
    z
    • 2
    • 2
  • s

    Sololo

    11/03/2021, 12:52 PM
    private class PreviewUserInfoProvider : PreviewParameterProvider<UserInfoBean> {
        override val values: Sequence<UserInfoBean>
            get() = sequenceOf(UserInfoBean("111", "111", ""))
    }
    
    @Preview(
        name = "user info layout",
        group = "node",
        showBackground = true,
        backgroundColor = 0xffffff
    )
    @Composable
    fun PreviewUserInfo(@PreviewParameter(PreviewUserInfoProvider::class) info: UserInfoBean) {
    //    UserInfoView(
    //        modifier = Modifier.size(120.dp, 30.dp),
    //        userInfoBean = info,
    //        onUserClick = {})
        
        Text(text = info.nickName)
    }
    why it cannot be preview shown?
    d
    p
    • 3
    • 9
  • n

    natario1

    11/03/2021, 1:29 PM
    Compiler behavior question - this crashes:
    class Obj(val id: Int) {
        @Composable fun id() = remember { id }
    }
    
    // later ...
    var obj by remember { mutableStateOf(Obj(0)) }
    LaunchedEffect(obj) {
        delay(1000)
        obj = Obj(obj.id + 1)
    }
    require(obj.id == obj.id())
    I understand what's happening and I know how to solve it (use
    remember(this)
    in Obj, or
    key
    ) but I wonder if this is how it should be. Wouldn't it be desirable that the compiler recognizes
    obj
    as part of the remember call stack? Since
    id()
    is a member function, it's pretty clear that if the object changes, the old remember should be invalidated.
    z
    • 2
    • 7
  • a

    AmrJyniat

    11/03/2021, 2:26 PM
    How to push FAB when keyboard pop up without setting
    windowSoftInputMode="adjustResize"
    in manifest because this push all the content not just the FAB?
    t
    • 2
    • 2
  • m

    Mehdi Haghgoo

    11/03/2021, 2:42 PM
    Why do most animation APIs work pixel-based? and given the fact that units in Android are often given in d.p, what is the best practice for creating accurate animations?
    b
    f
    d
    • 4
    • 7
  • a

    Adam Powell

    11/03/2021, 3:10 PM
    It's safe.
    ⛑️ 4
    👍 1
    m
    • 2
    • 1
  • r

    Rick Regan

    11/03/2021, 3:47 PM
    I'd like to get the maximum dimension of a device at app startup, but since that depends on the device's orientation,
    BoxWithConstraints
    does not look like the right tool for that. For example, on a Pixel 4A,
    BoxWithConstraints
    (at the top level, not within a
    Scaffold
    ) will give
    maxWidth
    392.dp and
    maxHeight
    785.dp in portrait, and
    maxWidth
    801.dp and
    maxHeight
    348.dp in landscape. I'd like to know that 801.dp is the max, even if the app starts in portrait. Is there a way to do that? | Edit: Rationale in thread.
    j
    t
    z
    • 4
    • 7
  • r

    rudolf.hladik

    11/03/2021, 7:57 PM
    Is there a way to have multiple
    stickyHeaders
    in
    LazyColumn
    ? I mean, I need a behaviour that e.g. 3 stickyHeaders all stick to top, not overlapping and not exchanging one-another
    f
    • 2
    • 4
  • j

    John O'Reilly

    11/03/2021, 9:06 PM
    Does anyone know whether you can use
    Image
    composable when using new
    Glance
    API to create app wdiget?
    c
    • 2
    • 6
  • a

    Alex C

    11/04/2021, 12:03 AM
    I'm trying to write test for a compose component which has a LazyColumn inside I expect I can assert the count of the items in the LazyColumn, but it seems the children of onChildren() includes some of the sub-hierarchies. For example,
    val testData = listOf("item1", "item2", "item3")
    composeTestRule.setContent {
                LazyColumn(Modifier.testTag(TEST_TAG)) {
                    itemsIndexed(testData) { index, item ->
                        Row {
                            Text("index $index: ")
                            Spacer(modifier = Modifier.height(10.dp))
                            Text(item)
                        }
                    }
                }
            }
    composeTestRule.onNodeWithTag(TEST_TAG).onChildren().assertCountEquals(3)
    It turns out the actual count of the children is 6 rather than 3, which counts the
    Text("index $index: ")
    and
    Text(item)
    inside the Row but not the
    Spacer()
    But what I actually want is to count how many rows in the LazyColumn. So how can I do it?
    j
    • 2
    • 4
Powered by Linen
Title
a

Alex C

11/04/2021, 12:03 AM
I'm trying to write test for a compose component which has a LazyColumn inside I expect I can assert the count of the items in the LazyColumn, but it seems the children of onChildren() includes some of the sub-hierarchies. For example,
val testData = listOf("item1", "item2", "item3")
composeTestRule.setContent {
            LazyColumn(Modifier.testTag(TEST_TAG)) {
                itemsIndexed(testData) { index, item ->
                    Row {
                        Text("index $index: ")
                        Spacer(modifier = Modifier.height(10.dp))
                        Text(item)
                    }
                }
            }
        }
composeTestRule.onNodeWithTag(TEST_TAG).onChildren().assertCountEquals(3)
It turns out the actual count of the children is 6 rather than 3, which counts the
Text("index $index: ")
and
Text(item)
inside the Row but not the
Spacer()
But what I actually want is to count how many rows in the LazyColumn. So how can I do it?
I end up adding a testTag in the composable I want to count and filter the tag
But I'm keen to understand how the nodes being count. like what is considered a 'node' what is not? If I write a Composable fun can I make it counted as a note?
Found the answer here 🙂https://developer.android.com/jetpack/compose/testing#semantics
j

John Nichol

11/05/2021, 3:23 PM
I see you got to the answer Alex - I find testing the LazyXXXX components by observing the LazyListLayoutInfo is also a useful tool to have in your bag. E.g. https://cs.android.com/androidx/platform/frameworks/support/+/androidx-main:wear/com[…]ayoutInfoTest.kt?q=f:test%20f:layoutinfo%20f:wear&amp;ss=androidx
👍 1
View count: 9