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

    chansek

    03/17/2022, 11:06 AM
    @Composable
    fun Payment(
        price: Double,
        onResult: (Int, PaymentResponse) -> Unit
    ) {
        val launcher = rememberLauncherForActivityResult(ActivityResultContracts.StartActivityForResult()) {
                onResult(RC_PAY, appNotFoundError ?: handlePaymentResult(it.data))
        }
        launcher.launch(preparePaymentIntent(price))
    }
    How do I handle the exception caused by
    launcher.launch
    when there is not Acitivity found to handle the
    Intent
    passed to
    launch
    ?
    f
    • 2
    • 3
  • k

    Kata

    03/17/2022, 1:18 PM
    When using
    Paging
    with custom unique keys(UUID) and
    LazyColumn
    I found the following issue: When I scroll through a bigger list(with 150 elements, paging 30) too fast then the app crashes with:
    "Key $slotId was already used. If you are using LazyColumn/Row please make sure you provide a unique key for each item."
    Issue is coming from SubcomposeLayout.kt line
    353
    . Now if I scroll though the list really slowly then everything works fine. Once everything is loaded and I scroll through it fast then there is no issue. Anybody has an idea what could be the issue? Is this maybe a bug inside compose? What I found is by adjusting the paging size to something smaller the crash happens earlier and when modifying the paging to something bigger than the list itself then the crash is not happening. I tried is with compose version
    1.1.0
    and also with
    1.2.0-alpha05
    👀 1
    • 1
    • 1
  • s

    Slackbot

    03/17/2022, 1:19 PM
    This message was deleted.
    f
    • 2
    • 1
  • s

    skwalking

    03/17/2022, 2:33 PM
    Any way to use Google Play In-App Review API in jetpack compose based app ?
    c
    • 2
    • 1
  • m

    Mohan

    03/17/2022, 5:09 PM
    22-03-17-22-38-15.mp4
    z
    • 2
    • 3
  • m

    Mohan

    03/17/2022, 5:10 PM
    Text field at the bottom of the list doesn't get focus, keyboard closes as soon as clicked on the textfield., If anyone has faced this issue please help.
    d
    • 2
    • 1
  • r

    Robert Menke

    03/17/2022, 7:49 PM
    Is there a way with coil-compose to specify that you want the placeholder image to render at a different size than the real image?
    p
    • 2
    • 3
  • j

    jonc

    03/17/2022, 11:26 PM
    Is it possible to access the size of a drawing environment? In my specific use case I'm applying the
    graphicsLayer
    modifier to an
    Image
    . I need the size of the image respective to content scale in order to implement some customized gestures. I've tried
    onSizeChanged
    and
    onGloballyPositioned
    but those seem to be used for the layouts rather than graphics so it isn't called when transformations are made through
    graphicsLayer
    i
    z
    • 3
    • 8
  • l

    Lance Gao

    03/18/2022, 2:07 AM
    Hi there, how can I show a
    Box{}
    and start with a fade-in animation?
    i
    c
    • 3
    • 6
  • z

    Zoltan Demant

    03/18/2022, 5:11 AM
    Back in the day, enums followed the
    VERY_BOLD
    naming pattern, since compose they (and a lot of other variables) follow a
    MuchSofterPattern
    . Im curious about how you manage any type of consistency between the two in your projects? Personally, I prefer the latter - but refactoring isnt very simple when the old style enums are part of external datasets, json structures, etc. I feel liek Im stuck with
    UPPER_CASE
    and
    BeautifulCase
    (sorry, I couldnt find the actual appropiate names for them) and I rarely know when to use which as a result.
    k
    d
    • 3
    • 2
  • a

    Abhilash

    03/18/2022, 9:31 AM
    I know there are a few of naming conventions for functions in compose. But is there any naming conventions I should follow for naming packages in compose?
    z
    • 2
    • 1
  • t

    thelumiereguy

    03/18/2022, 10:32 AM
    Are there any differences between place() and placeRelative() other than RTL support?
    🇳🇴 2
    z
    • 2
    • 2
  • f

    Fabio

    03/18/2022, 1:39 PM
    I started adopting Compose 1.1.1 in an existing Android app but I'm facing very weird behavior when trying to limit input in a
    TextField
    to decimal numbers. I just posted a question on StackOverflow with the full details, but I could also post them here if you prefer. The TL;DR is that even if I do not update my state in response to the
    onValueChange
    callback (or if I just set the previous value and ignore the new one), the text I get in the next
    onValueChange
    still includes the changes I rejected.
    r
    b
    • 3
    • 11
  • b

    Bradleycorn

    03/18/2022, 3:22 PM
    We’re converting a Fragment based app over to Compose. It’s got quite a few Fragments. During this transition period, I know I can use the
    AndroidViewBinding
    Composable to inflate a
    FragmentContainerView
    with a Fragment and show it within composable “screen”. So far though, it seems like I have to create a wrapper xml layout resource with a
    FragmentContainerView
    for every fragment. I was hoping to find a way to just define a single xml layout resource (compose_fragment_container.xml) and write a composable that uses it with
    AndroidViewBinding
    to load an arbitrary Fragment. But so far no luck. Anyone know a way to do this? My current (not working) code in the 🧵
    l
    m
    • 3
    • 6
  • m

    Marko Novakovic

    03/18/2022, 4:07 PM
    I have interactive preview enabled but clicks are not working at all. button click shows ripple effect and effect is stuck in the middle of animation and just stays like that. multiple clicks and ripples just stack
    c
    • 2
    • 16
  • c

    colintheshots

    03/18/2022, 7:47 PM
    I need to keep some buttons onscreen underneath a textfield while my IME keyboard is visible. I know all the tricks with Accompanist Insets (and the new insets in Compose 1.2.0-alpha), but none of them seem to be working for me. When I use
    Modifier.imePadding
    or
    Modifier.navigationBarsWithImePadding
    , the UI elements are scrolled completely offscreen and I’m left with a blank space where they were. I was able to workaround the issue by giving my textfield a weight of 1f and this keeps the buttons onscreen above the keyboard and below the textfield, but I can’t use this on screens with more than one textfield. Are there any alternatives to Modifier.weight(1f) that will work better here?
    b
    z
    • 3
    • 14
  • r

    Robert Menke

    03/18/2022, 9:56 PM
    I can’t seem to find an explanation of the
    contentType
    parameter for
    items
    that I can understand. Let’s say I have a
    LazyColumn
    where each item is a
    FooItem
    . What am I supposed to be supplying to
    contentType
    ?
    fun items(
            count: Int,
            key: ((index: Int) -> Any)? = null,
            contentType: (index: Int) -> Any? = { null },
            itemContent: @Composable LazyItemScope.(index: Int) -> Unit
        ) {
            error("The method is not implemented")
        }
    d
    p
    +2
    • 5
    • 8
  • m

    Mjahangiry75

    03/19/2022, 8:39 AM
    Is there a way to have multi
    BottomSheet
    dialog in a screen? just like
    Dialog
    c
    • 2
    • 1
  • n

    nuhkoca

    03/19/2022, 3:33 PM
    Hello I have a setup below for different views based on different states. Views for
    Success
    and
    Error
    states already work as expected because they aren’t centered on the screen but
    LoadingView
    should be centered instead but it is always placed on top. How do I fix this? Thank you.
    ...
    Scaffold(topBar = topBar) {
        Box(
            modifier = Modifier
                .padding(it)
                .verticalScroll(rememberScrollState())
        ) {
            when (collectionState) {
                CollectionState.Loading -> LoadingView()
                is CollectionState.Success -> {
                    ScreenView(
                        collection = collectionState.collection,
                        onWatchlistItemClick = onWatchlistItemClick,
                        onDisclaimerTextClicked = onDisclaimerTextClicked
                    )
                }
                CollectionState.Error -> ErrorView(onTryAgainClicked = onTryAgainClicked)
            }
        }
    }
    ...
    @Composable
    private fun LoadingView() {
        Box(
            modifier = Modifier.fillMaxSize(),
            contentAlignment = Alignment.Center
        ) {
            CircularProgressIndicator()
        }
    }
    t
    a
    • 3
    • 7
  • h

    harry.singh

    03/19/2022, 10:23 PM
    Hey all! I'm collecting a
    Channel(Channel.BUFFERED)
    as a flow in a Composable function but I'm only ever seeing the latest element and missing all of the elements before the latest one. I've added all of the code here. I debugged
    collectAsState
    and I'm seeing all of the elements in the
    produceState
    composable function but not in my composable function. Any ideas why this might be happening?
    a
    l
    +3
    • 6
    • 23
  • a

    andrew

    03/20/2022, 12:32 AM
    Had some help from @romainguy, wrangling filament for this, still very rough but I wrote composable wrappers for some imperative APIs for Filament's model viewer. Also these are real IoT devices I'm triggering in the office around 1k miles away in Philadelphia. I'm in Florida, and I hope no one wonders why a light is going on/off 😂
    screen-20220319-202637.mp4
    r
    • 2
    • 12
  • a

    Android75

    03/20/2022, 4:39 AM
    n
    • 2
    • 1
  • a

    Android75

    03/20/2022, 6:05 AM
    Hi I’m changing my app to compose vesion. I have to develop a classinc wizard such as this..
    c
    • 2
    • 2
  • a

    Android75

    03/20/2022, 6:05 AM
    to swipe 2-3 “pages” what can i use ?
    c
    • 2
    • 1
  • z

    Zach Klippenstein (he/him) [MOD]

    03/20/2022, 4:52 PM
    Does passing null to
    leadingIcon
    work?
    r
    • 2
    • 1
  • z

    zt

    03/20/2022, 10:55 PM
    I'm using this library https://github.com/raamcosta/compose-destinations, is it possible to get a screen that can be collapsed down but displayed on top of another screen? Like the collapsible player in the Youtube app
    i
    i
    r
    • 4
    • 4
  • f

    FunkyMuse

    03/20/2022, 11:05 PM
    Hey guys, is there equivalent of splitMotionEvents from RecyclerView for LazyColumn/Row?
    a
    k
    • 3
    • 6
  • m

    mcpiroman

    03/21/2022, 8:54 AM
    Are there any plans to move Compose project outside of androidx repository / generally decouple it from android(x) / merge with Jetbrains' fork? I think as a whole Compose is inherently more multiplatform than android, although I'm not sure how complicated would it be to setup android dependencies/workflow in that case. Is https://issuetracker.google.com/issues/187071114 relevant to above, or is it only about final binaries, no matter how produced? I'm mainly asking because it's currently hard to play with and contribute given the setup of AOSP, especially for non-android parts.
    z
    • 2
    • 1
  • a

    althaf

    03/21/2022, 10:21 AM
    hi, when using this pattern
    class LoginViewModel : ViewModel() {
    
        val registeredUsers = mutableStateListOf<UIRegisteredUser>()
    in the view model 1. Is there way to protect this registeredUsers list from updating the object values from other than view model ? I'm tryting to avoid accidental modification these values from out side view model, trying to keep vm as single source of truth.
    a
    a
    • 3
    • 3
  • a

    althaf

    03/21/2022, 10:23 AM
    here any one access to view model will be able to modify this directly. Which live data i use this pattern
    private val _quickLinks = MutableLiveData<List<UIQuickLink>>()
    val quickLink: LiveData<List<UIQuickLink>> = _quickLinks
    So that, quickLink access are only observed than posted with new values from UI, here update to quickLink happens from only view model
    f
    a
    • 3
    • 26
Powered by Linen
Title
a

althaf

03/21/2022, 10:23 AM
here any one access to view model will be able to modify this directly. Which live data i use this pattern
private val _quickLinks = MutableLiveData<List<UIQuickLink>>()
val quickLink: LiveData<List<UIQuickLink>> = _quickLinks
So that, quickLink access are only observed than posted with new values from UI, here update to quickLink happens from only view model
f

f.babic

03/21/2022, 10:24 AM
You can do the same for state, just expose a
State
instead of a
MutableState
using a second property. You could also do it with a function instead of a property
a

althaf

03/21/2022, 10:32 AM
@f.babic, is this how we do it ? I understood your point, however some thing is missing, this isn't working
val _registeredUsers = mutableStateListOf<UIRegisteredUser>()
val registeredUser: State<UIRegisteredUser> = _registeredUsers
I think this is how we have to do is in case of mutableStateList
val _registeredUsers = mutableStateListOf<UIRegisteredUser>()
val registeredUser: SnapshotStateList<UIRegisteredUser> = _registeredUsers
SnapshotStateList
Is mutable 😕
f

f.babic

03/21/2022, 10:36 AM
Is there a reason why you use
mutableStateListOf
instead of
mutableStateOf
? We're using the latter in our code and seems to work fine, haven't had issues per se.
a

althaf

03/21/2022, 10:50 AM
private val _registeredUsers = mutableStateOf<List<UIRegisteredUser>>(value = listOf())
val registeredUser: State<List<UIRegisteredUser>> = _registeredUsers
This above appears to work , however following use case we are not able to accomplish with above approach, where as with mutableStateListOf() these worked fine, however, object became insecure
init {
    _registeredUsers.value.toMutableStateList().addAll(mockRegisteredUsers)
    
}
fun onUserSelected(user: UIRegisteredUser) {
    viewModelScope.coroutineContext.run {
        _registeredUsers.value.toMutableStateList().let { userList ->
            userList.find { it.isSelected }?.let {
                userList.indexOf(it).also { index ->
                    userList.remove(it)
                    userList.add(index, it.copy(isSelected = false))
                }
            }

            userList.find { it == user }?.let {
                userList.indexOf(it).also { index ->
                    userList.remove(it)
                    userList.add(index, it.copy(isSelected = true))
                }
            }
        }
    }
}
f

f.babic

03/21/2022, 10:55 AM
Oh okay that makes sense - in that case you'd come back to the same thing if you went that way. I mean, instead of:
_registeredUsers.value.toMutableStateList().addAll(mockRegisteredUsers)
You could have:
_registeredUsers.value = _registeredUsers.value + mockRegisteredUsers
Basically, instead of havign a mutable list that can be changed anywhere, you use immutable lists but make sure to add/remove items from the given list and producing a new list instead. That gives you control in the ViewModel of whatever you want to do, but the rest of the world won't be able to mutate incorrectly
a

althaf

03/21/2022, 10:57 AM
@f.babic i got it working with your approach, so these are the changes,
private val _registeredUsers = mutableStateOf<ArrayList<UIRegisteredUser>>(value = arrayListOf())
val registeredUsers: State<List<UIRegisteredUser>> = _registeredUsers
I'm using ArrayList now
fun onUserSelected(user: UIRegisteredUser) {
    viewModelScope.coroutineContext.run {
        _registeredUsers.value.let { userList ->
            userList.find { it.isSelected }?.let {
                userList.indexOf(it).also { index ->
                    userList.remove(it)
                    userList.add(index, it.copy(isSelected = false))
                }
            }

            userList.find { it == user }?.let {
                userList.indexOf(it).also { index ->
                    userList.remove(it)
                    userList.add(index, it.copy(isSelected = true))
                }
            }
        }
    }
}
this also work fine
however @f.babic there is a catch , when the onUserSelected is called, recomposition is not happening
any input on this ?
f

f.babic

03/21/2022, 11:00 AM
This is because you're taking the list of items form the State, copying it and updating it in that instance. You should always push the new state/list to the property like:
_registeredUsers.value = newValue
when you mutate the list within those
find
calls, you need to make sure to push the new state to the UI
a

althaf

03/21/2022, 11:09 AM
@f.babic sorry to bother you this way 😢 that didn't work either UI is observing from composable for registeredUser
SelectLoginUsersScreenContent(registeredUsers = loginViewModel.registeredUsers.value, onUserSelected = onUserSelected)
fun onUserSelected(user: UIRegisteredUser) {
    viewModelScope.coroutineContext.run {
        _registeredUsers.value.let { userList ->
            userList.find { it.isSelected }?.let {
                userList.indexOf(it).also { index ->
                    userList.remove(it)
                    userList.add(index, it.copy(isSelected = false))
                }
            }

            userList.find { it == user }?.let {
                userList.indexOf(it).also { index ->
                    userList.remove(it)
                    userList.add(index, it.copy(isSelected = true))
                }
            }
            _registeredUsers.value = userList
        }
    }
}
See that last line i 'm even manually setting _registeredUser.value
f

f.babic

03/21/2022, 11:19 AM
Could you try doing something like:
val registeredUsers by loginViewModel.registeredUsers

SelectLoginUsersScreenContent(registeredUsers = registeredUsers, onUserSelected = onUserSelected)
Basically the way we expose state in our VMs is the following:
private var threadMessagesState: MessagesState by mutableStateOf(MessagesState())
And then we just fetch it using an exposed property or something
a

althaf

03/21/2022, 11:31 AM
val registeredUsers by loginViewModel.registeredUsers

SelectLoginUsersScreenContent(
    registeredUsers = registeredUsers,
    onUserSelected = onUserSelected
)
😭 didnt work @f.babic
a

Albert Chang

03/21/2022, 11:42 AM
Why can’t you just do this?
private val _registeredUsers = mutableStateListOf<UIRegisteredUser>()
val registeredUsers: List<UIRegisteredUser> = _registeredUsers
☝️ 2
a

althaf

03/21/2022, 11:44 AM
i need registeredUsers to trigger recomposing when value changes
will it be possible if we use registeredUsers: List<UIRegisteredUser>?
a

Albert Chang

03/21/2022, 11:45 AM
Yep. As long as a snapshot state is read, even if not directly, it will trigger recomposition when it changes.
a

althaf

03/21/2022, 11:48 AM
💥🥳
@Albert Chang @f.babic thank you , it worked
private val _registeredUsers = mutableStateListOf<UIRegisteredUser>()
val registeredUsers: List<UIRegisteredUser> = _registeredUsers
❤️ 1
View count: 4