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

    SrSouza

    05/03/2022, 8:40 PM
    Hi folks, there is any similar API to ComposeView but for Dialog? I want to start a Dialog in a "legacy xml ui" and in this Dialog I want to use Compose. The source for AlertDialog or Dialog depends on a Composable function scope.
    a
    • 2
    • 2
  • x

    xxfast

    05/04/2022, 2:18 AM
    is there a neater way to conditionally apply modifiers than
    modifier = modifier
      .let { if(canBeExpanded) it.clickable { expanded = !expanded } else it }
    f
    a
    +2
    • 5
    • 14
  • s

    saket

    05/04/2022, 3:19 AM
    Is anyone using dropdown menus in their android app? I've just added support for compose to
    cascade
    and would like people to try out its beta: https://github.com/saket/cascade/releases/tag/2.0.0-beta1
    cascade.mp4
    👏 19
    👏🏽 1
    👌 2
    👏🏻 1
    👏🏼 1
    🎉 11
    a
    c
    a
    • 4
    • 3
  • j

    Jason Ankers

    05/04/2022, 7:29 AM
    Still some (probably) undesired behaviour with
    rememberSaveable
    inside
    movableContentOf
    : Calling
    recomposeScope.invalidate()
    inside
    movableContentOf
    changes the
    currentCompositeKeyHash
    which breaks
    rememberSaveable
    a
    • 2
    • 3
  • d

    Daniele Segato

    05/04/2022, 9:25 AM
    I've found a couple of issues with
    LazyRow
    and
    stickyHeader
    . 1. If the header is vertically higher than the content the
    LazyRow
    change height when the sticky header item would scroll out of view. 2. if the
    LazyRow
    has
    contentPadding
    this is ignored for the
    stickyHeader
    , I would expect the sticky header to snap in a position that respect content paddding. are these 2 issues know? should I open 2 but reports? I assume these 2 issues translates equally with
    LazyColumn
    s
    c
    a
    • 4
    • 8
  • n

    nitrog42

    05/04/2022, 12:51 PM
    What is the preferred way to use Saver with “complex” object ?
    data class Container(val name: String, val items: List<Item>)
    data class Item(val id: Int)
    I know how to create a Saver for each (an object, or a list), but I’m not sure how to handle object that contains a list
    • 1
    • 2
  • w

    William Reed

    05/04/2022, 1:30 PM
    does anyone know of a good resource demonstrating compose for web (example sites to browse)?
    f
    • 2
    • 2
  • j

    jasu

    05/04/2022, 1:41 PM
    what’s the way to limit no. of characters in
    Text()
    composable?
    d
    a
    n
    • 4
    • 5
  • n

    nitrog42

    05/04/2022, 1:57 PM
    Another question about the new
    SavedStateHandle.saveable
    API, is there an equivalent to
    val argArticleId = savedStateHandle.getStateFlow(ArticleArgKey, -1)
    that return a State ? I tried with
    .saveable(ArticleArgKey)
    but it seems the return value is a Bundle instead of a Long... (in my case)
    i
    • 2
    • 9
  • r

    Rafael Costa

    05/04/2022, 7:05 PM
    Sometimes
    remember
    saved state is lost after screen is turned off and on. 🧵
    i
    m
    • 3
    • 13
  • c

    Colton Idle

    05/04/2022, 8:27 PM
    I had a question in regards to topAppBar not playing nicely with insets, and so we've been relegated to using accompanist insets-ui. I could have sworn someone posted the gerrit link or something to topAppBar getting this functionality out of the box, but now my search skills are failing me. Does anyone remember that by chance?
    a
    • 2
    • 2
  • z

    Zoltan Demant

    05/05/2022, 4:33 AM
    I wrote a small composable that makes handling "is this dialog visible?" pretty much seamlessly, without adding any extra overhead. Its very minimal, but I thought Id share it anyway; it has helped me tremendously! Code in thread 🧵
    👍🏽 1
    👍🏻 1
    👍 2
    m
    u
    c
    • 4
    • 7
  • w

    Wishnuprathikantam

    05/05/2022, 10:41 AM
    LazyPagingItems<Episodes>
    How to use group by with LazyPagingItems? I want to implement a sticky header list here so i would need to convert this to Map<String,List<Episodes>> here. One way i can think of is using the itemSnapshot list, but not sure if it's a good practice. Any help is appreciated. Thanks.
    j
    • 2
    • 2
  • b

    Big Chungus

    05/05/2022, 11:18 AM
    Is there a way to implicity pass some data to parent composable without hoisting the state? I basically need to let the parent know if it contains a specific kind of optional child composable.
    a
    c
    z
    • 4
    • 7
  • s

    Satyam G

    05/05/2022, 11:57 AM
    How can we display a custom small view like this over any composable without adding it to Root Composable and controlling it's visibility. The use case is like on any screen if any error occurs this should be displayed and this view (composable) should not be included in every composable. How to achieve this ?? Any help will e appreciated
    f
    c
    • 3
    • 3
  • l

    Landry Norris

    05/05/2022, 3:26 PM
    For my work, I need to show a row of thumbnails from different parts of a video in the bottom of the screen instead of a Slider, similar to when you view a video in iOS’s photos app. Is there a Composable or Android view that will do this for me?
    m
    c
    • 3
    • 3
  • m

    Matthew Laser

    05/05/2022, 3:28 PM
    hey all - has anyone been having issues with the
    androidx.startup
    package in association with compose?
    f
    • 2
    • 2
  • r

    Roberto Leinardi

    05/05/2022, 4:43 PM
    Hello, I'm trying to write an integration test for an Android application entirely written in Compose that has a single Activity and uses the Compose Navigation to change the screen content. I managed to properly interact and test the first screen that is shown by the navigation graph but, as soon as I navigate to a new destination, the test fails because it does not wait for the NavHost to load the new content. This is my current code for the test:
    @RunWith(AndroidJUnit4::class)
    class MainActivityTest {
        @get:Rule
        val composeTestRule = createAndroidComposeRule<MainActivity>()
    
        @Test
        fun appStartsWithoutCrashing() {
            composeTestRule.apply {
                // Check Switch
                onNodeWithTag(FirstScreen.CONSENT_SWITCH)
                    .assertIsDisplayed()
                    .assertIsOff()
                    .performClick()
                    .assertIsOn()
    
                // Click accept button
                onNodeWithTag(FirstScreen.ACCEPT_BUTTON)
                    .assertIsDisplayed()
                    .performClick()
    
                // Thread.sleep(500)
    
                // Check we are inside the second screen
                onNodeWithTag(SecondScreen.USERNAME_TEXT_FIELD)
                    .assertIsDisplayed()
            }
        }
    }
    I'm sure that is a timing issue because if I add a
    Thread.sleep(500)
    before the
    onNodeWithTag(SecondScreen.USERNAME_TEXT_FIELD).assertIsDisplayed()
    , the test is successful. But I would like to avoid `Thread.sleep()`s in my code. Is there a better way to tell the
    composeTestRule
    to wait for the NavHost to load the new content before executing proceeding with the next assertion? PS I know that would be better to test the Composables in isolation, but I really need to simulate the user input on the App using Espresso and not only test the Composable behavior.
    🧵 1
    a
    i
    • 3
    • 8
  • d

    dazza5000

    05/05/2022, 7:54 PM
    is it more idiomatic/preferred to expose a
    mutableStateOf
    or a
    StateFlow
    /
    LiveData
    property from a ViewModel?
    l
    c
    • 3
    • 5
  • s

    Slackbot

    05/06/2022, 12:24 AM
    This message was deleted.
  • l

    Liangjun Sha

    05/06/2022, 2:58 AM
    Hi, I’m trying to write a list with
    LazyColumn
    , there is a
    ConstraintLayout
    in the top of it and other items list below the
    ConstraintLayout
    . It works well until I changed the compose version from
    1.1.1
    to
    1.2.0-alpha08
    , and now it crashed every single time when I scroll the
    LazyColumn
    .
    a
    • 2
    • 3
  • g

    gpaligot

    05/06/2022, 8:29 AM
    Hello here! I have a question about the
    text
    property we can call inside the
    semantics
    callback. What is the difference between
    text
    and
    contentDescription
    and why we should use an
    AnnotatedString
    as value? 🤔 Thanks in advance!
    a
    • 2
    • 1
  • s

    ste

    05/06/2022, 9:43 AM
    🤔 Would you try this snippet and see what it prints? I think there's an unwanted behavior under the hood... 🐛🧵
    • 1
    • 1
  • v

    Vaios Tsitsonis

    05/06/2022, 10:17 AM
    hello! is there a way to render markdown in a compose's Text? Do we need a library?
    c
    z
    • 3
    • 4
  • r

    rsktash

    05/06/2022, 10:29 AM
    2 weeks passed. Where is the next release which have to be fix for the last issue? https://issuetracker.google.com/issues/229752147
    c
    • 2
    • 1
  • m

    Michael Paus

    05/06/2022, 11:49 AM
    I am just trying to get an older Compose project built again but after some tool and library updates the build fails with
    2 files found with path 'META-INF/kotlinx_coroutines_core.version'.
    Adding a packagingOptions block may help, please refer to
    <https://google.github.io/android-gradle-dsl/current/com.android.build.gradle.internal.dsl.PackagingOptions.html>
    for more information
    Besides the fact that the given link is wrong I am wondering what I shall do to get that working again. kotlinx_coroutines_core is used in a thousand places. How can I find the conflicting ones?
    s
    • 2
    • 4
  • a

    andrew

    05/06/2022, 2:00 PM
    If this becomes mature enough, I'd love to see this work upstreamed 🤤🤩
    c
    a
    +7
    • 10
    • 195
  • m

    mattinger

    05/06/2022, 4:03 PM
    var startBluetoothFlow by remember { mutableStateOf(false) }
        LaunchedEffect(key1 = true) {
            if (!host.bleManager.isReadyForScanning) {
                startBluetoothFlow = true
            }
        }
    
        if (startBluetoothFlow) {
            BluetoothController(
                permissionState = permissionState,
                bluetooth = host.bleManager,
                navHostController = navController,
            )
        }
    The problem is that BluetoothController is getting evaluated multiple times
    f
    • 2
    • 3
  • s

    spierce7

    05/06/2022, 4:44 PM
    If I have an
    Image
    , without knowing it’s size, how could I center something on top of the image? I want the the
    Image
    size to dictate the size of the parent
    Box
    . How could I do this in compose?
    o
    • 2
    • 4
  • j

    Jorge Domínguez

    05/06/2022, 5:08 PM
    Checking the Jetnews sample app there's this code snippet that allows state collection from a composable:
    private val viewModelState = MutableStateFlow(HomeViewModelState(isLoading = true))
    
    val uiState = viewModelState
        .map { it.toUiState() }
        .stateIn(
            viewModelScope,
            SharingStarted.Eagerly,
            viewModelState.value.toUiState()
        )
    My question is, what's the advantage of using
    stateIn()
    here? I would normally do something like:
    private val _viewModelState = MutableStateFlow(HomeViewModelState(isLoading = true))
    val viewModelState get() = _viewModelState
    But looking into the
    stateIn()
    docs there's a mention to increased performance for multiple observers since the upstream flow is instantiataed only once, but what if the flow is collected from a single composable? is there really an advantage there? I was thinking that each recomposition can be considered as a new observer, in which case I can see how the use of
    stateIn()
    helps, but I'd like to fully understand the implications of its usage and how it's better, so if anyone can shed some light I'd be grateful.
    a
    • 2
    • 8
Powered by Linen
Title
j

Jorge Domínguez

05/06/2022, 5:08 PM
Checking the Jetnews sample app there's this code snippet that allows state collection from a composable:
private val viewModelState = MutableStateFlow(HomeViewModelState(isLoading = true))

val uiState = viewModelState
    .map { it.toUiState() }
    .stateIn(
        viewModelScope,
        SharingStarted.Eagerly,
        viewModelState.value.toUiState()
    )
My question is, what's the advantage of using
stateIn()
here? I would normally do something like:
private val _viewModelState = MutableStateFlow(HomeViewModelState(isLoading = true))
val viewModelState get() = _viewModelState
But looking into the
stateIn()
docs there's a mention to increased performance for multiple observers since the upstream flow is instantiataed only once, but what if the flow is collected from a single composable? is there really an advantage there? I was thinking that each recomposition can be considered as a new observer, in which case I can see how the use of
stateIn()
helps, but I'd like to fully understand the implications of its usage and how it's better, so if anyone can shed some light I'd be grateful.
If anyone thinks this is more of a #coroutines question let me know.
a

Adam Powell

05/06/2022, 6:15 PM
kind of an #android or #android-architecture question, really. 🙂 either way though, it's trying to satisfy conflicting requirements: the source of truth isn't a
UiState
, it's something that gets mapped to one, and if you don't have a
StateFlow
then you don't have an initial value available, you have to subscribe and wait for it to emit, and in the case of consuming from compose that means you get a frame of empty data before the first item is known.
the whole thing could instead be written as:
private var viewModelState by mutableStateOf(HomeViewModelState(isLoading = true))
val uiState: UiState
  get() = viewModelState.toUiState()
to leverage snapshots instead and skip all of the subscription complexity, since the upstream source of truth is a
MutableStateFlow
anyway - a hot data source that doesn't care about subscription awareness in the first place.
j

Jorge Domínguez

05/06/2022, 6:36 PM
Thanks! Would you then recommend mutating the state within the ViewModel and exposing it directly instead of using
collectAsState()
?
Also, out of curiosity, do you think the statement "...each recomposition can be considered as a new observer" is true?
a

Adam Powell

05/06/2022, 7:43 PM
the call to
.collectAsState
is an observer for as long as it remains in composition with the same receiver flow instance
the same underlying observer (call to
Flow.collect
persists undisturbed across recompositions for as long as the call to
.collectAsState
is present in the composition for the same
Flow
instance
j

Jorge Domínguez

05/06/2022, 7:51 PM
I see now, thanks again, appreciate your help
View count: 1