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

    julioromano

    01/26/2022, 8:04 PM
    After upgrading to
    lifecycle-viewmodel:2.5.0-alpha01
    I’m getting compile errors on classes that inherit from `ViewModelProvider.Factory`:
    Inheritance from an interface with ‘@JvmDefault’ members is only allowed with -Xjvm-default option
    I’ve tried fiddling all
    -Xjvm-default=xxxxx
    options but the error does not go away. Anyone had the same trouble?
    c
    • 2
    • 6
  • s

    Slackbot

    01/26/2022, 9:08 PM
    This message was deleted.
    c
    • 2
    • 1
  • o

    Olivier Patry

    01/26/2022, 10:21 PM
    Hi all 👋 I'm trying to adjust the style of my buttons. I'd like all my `Button`s to have the same style, same is for `OutlinedButton`s. I was able to tweak some parts like shape & surface given the
    MaterialTheme
    open properties but if I want to customize more, I'm stuck. For instance, I'd like to tweak the width of the `OutlinedButton`'s border and potentially its color. The only thing I can think of so far is to redefine my own
    MyAppButton
    tweaking what's needed (by calling built-in button composable or not, impl detail here). Can't we have ways to override
    ButtonDefaults
    ? (using opened
    var
    instead of
    val
    or
    LocalButtonDefaults
    or something like that). I have the feeling that redefining custom buttons make composable less reusable and tightly coupled to custom composable rather than provided theming.
    s
    k
    +2
    • 5
    • 10
  • l

    Lilly

    01/27/2022, 1:28 AM
    Any ideas how I can align the text centered? I tried everything I'm aware of but the text doesn't move vertically except padding.
    s
    c
    • 3
    • 3
  • a

    Abhishek Dewan

    01/27/2022, 6:58 AM
    I’m running 1.1.0-rc02 compiler with 1.1.0-rc01 dependencies (both tooling and tooling-preview). Using AS bumblebee and compose previews aren’t rendering. Does anyone know if this is a known issue. Couldn’t find anything relevant on issue tracker
    c
    a
    • 3
    • 10
  • m

    Mikael Alfredsson

    01/27/2022, 8:26 AM
    I hope this is the place for Coil questions. How do I point to my own instance of OkHttp with Coil and rememberImagePainter?
    t
    c
    m
    • 4
    • 4
  • l

    Lokik Soni

    01/27/2022, 8:42 AM
    I have designed a custom switch in Jetpack compose and not able to use it properly it is not respecting its parent and getting out of the view.
    f
    s
    • 3
    • 5
  • a

    Ashu

    01/27/2022, 10:17 AM
    Hii, I wanted to know if it is better to keep State<UiModels> in view models or keeping StateFlow<UiModels> in view models and then in compose layout collect their value to a state? What would be preferable here?
    f
    s
    • 3
    • 11
  • f

    Fanilog

    01/27/2022, 12:13 PM
    Hello, I was wondering if people encounter the same issue while using https://github.com/google/accompanist/tree/main/navigation-material with ModalBottomSheet with Compose? If i swipe down the modal the lifecycle of the NavBackStackEntry goes to the
    ON_DESTROY
    state however if I’m doing the classic back the lifecycle stop at
    ON_STOP
    and never reach the
    ON_DESTROY
    • 1
    • 1
  • n

    natario1

    01/27/2022, 12:27 PM
    Is there a way to know whether
    LazyListState.isScrollInProgress
    was triggered by user or not? Documentation says "Whether this ScrollableState is currently scrolling by gesture, fling or programmatically". I think I can use
    InteractionSource
    to catch drags, but it would not cover flinging and maybe some other user-initiated scrolls.
    m
    • 2
    • 5
  • g

    Gerardo Ernesto Rodriguez Navar

    01/27/2022, 1:05 PM
    I have a CoordinatorLayout which contains (FragmentContainer + BottomNavigation)
    m
    f
    • 3
    • 10
  • c

    Casey Brooks

    01/27/2022, 4:56 PM
    For setting clickable links within text, we need to use AnnotatedString with ClickableText. However, I've noticed that the ClickableText consumes the pointer events even if the tap doesn't correspond to a clickable region of text, and thus a tap anywhere on the text doesn't fall-through to its parent. Is there any way to make only the clickable regions of text consume the pointer events?
    t
    • 2
    • 3
  • n

    Nick

    01/27/2022, 5:06 PM
    What’s the best way to accomplish this layout? I was thinking about using a
    FlowRow
    that contains the `Chip`s for each user, with a
    TextField
    that will fill remaining width? How would I get the
    TextField
    to fill the remaining width in the row while also having a minWidth?
    c
    • 2
    • 3
  • s

    Simon Stahl

    01/27/2022, 7:35 PM
    Has support for marquee text been added lately? I know it wasn't supported as of about 6 month ago
    a
    z
    • 3
    • 16
  • b

    brabo-hi

    01/27/2022, 11:27 PM
    Hi all, from the doc
    <https://developer.android.com/guide/navigation/navigation-pass-data#supported_argument_types>
    navigation can accept a nullable string as parameter. Should we ignore the null argument ?
    i
    • 2
    • 4
  • a

    Andrew Hughes

    01/28/2022, 12:45 AM
    Does anyone know if it's possible to programmatically determine what the current color is beneath/behind a composable? The scenario I'm trying to solve is that I want to composite a transparent overlay color on top of the background color and use the resulting composite color in order to create a cut-out appearance. For example, see the area around the check mark in the attached image. I, of course, can pass the background color to composite over into the composable, but that would require passing this down through several composables (which other than to pass it on, shouldn't need to know the background color).
    a
    m
    +2
    • 5
    • 23
  • t

    Tash

    01/28/2022, 2:11 AM
    Seeing a
    has no zero argument constructor
    runtime error when using
    androidx.lifecycle.viewmodel.compose.viewModel()
    🧵
    y
    • 2
    • 7
  • o

    Oleksandr Balan

    01/28/2022, 9:49 AM
    I am facing an issue with displaying a copy-paste popup inside a Popup composable. My use-case is to display a text field inside our component, which uses Popup underneath. Text field works correctly, but when I try to copy-paste something application crashes. Is it even possible to “nest” popups? Tested with latest Compose 1.2.0-alpha02 & Kotlin 1.6.10, also reproduced in older versions. See video, code example and crash log in the 🧵. Thx for advice.
    :plus-one: 3
    c
    a
    • 3
    • 18
  • a

    alorma

    01/28/2022, 11:45 AM
    Hi! I know this may be a ... dummy question about texts, but I'm running out if ideas here. We have a chip, created by
    Surface
    and
    Text
    inside it, text is in a
    Row
    , centered both horizontal and vertical. We see a small pixel.. difference, as it should be on the center, and we see here that text is a bit under the center.. Any idea?
    j
    f
    • 3
    • 12
  • r

    rudolf.hladik

    01/28/2022, 1:08 PM
    Is there a way to stick a
    stickyHeader
    not to top of
    LazyColumn
    but to top with some offset?
    d
    f
    • 3
    • 6
  • n

    ninadmg

    01/28/2022, 1:29 PM
    How to show only the fitting items in a row? do we have any modifiers for this. or should i write a custom layout for this.
    👀 1
    a
    c
    t
    • 4
    • 9
  • i

    iamthevoid

    01/28/2022, 2:26 PM
    is it possible to make view pager looped infinite?
    j
    z
    • 3
    • 3
  • c

    Colton Idle

    01/28/2022, 2:26 PM
    Looks like Version 1.2.0-alpha02 of compose was release a few days ago A few interesting things I found: • Text selection magnifier behavior has been polished to match the platform magnifier. •
    LazyColumn
    , 
    LazyRow
    , 
    Modifier.verticalScroll
     and other containers that use 
    Modifier.scrollable
     now support mouse wheel scrolling. • Added 
    excludeFromSystemGesture
     Modifiers for easy access to Android's 
    setSystemGestureExclusionRects
      • Fix continuous backspace on CJK keyboards (I think this is the fix for continuous backspace not working in password fields 🤞) • Preserve scroll when items are added in lazy grid • Fix TextFieldKeyInput onValueChange (this seems to fix an issue of typing with your keyboard on an emulator) • Compose Material - Add support for action chip (not sure if this is a new chip component, but I want to check it out) • Added Material 3 divider • Added support for Material 3 progress indicators • Add experimental View.createLifecycleAwareRecomposer extension (idk what this is but it sounds interesting...) • Wear OS - Add support for Rotary Events modifiers
    👍 5
    👍🏽 1
    f
    • 2
    • 1
  • j

    Justin Breitfeller

    01/28/2022, 2:39 PM
    Is there a Modifier that lets me wrap the content that is about to be created in a CompositionLocalProvider. I.E. If i apply a modifier to a composable, I’d like the child content to be able to access that set CompositionLocal.
    a
    • 2
    • 4
  • a

    alorma

    01/28/2022, 3:07 PM
    Hi. Anyone having problems rendering previews on BumbleBee? stacktrace on 🧵
    c
    • 2
    • 2
  • g

    GeorgeS-Litesoft

    01/28/2022, 3:17 PM
    New to Compose, but have done AWT, Swing, GWT, Web (of course), and interested in Fyne (GoLang), JavaFX. In the ones I've actually used, each "component" could access the "parent component" (walk the directed graph, e.g. DOM), is that possible with compose?
    n
    a
    • 3
    • 4
  • g

    gpaligot

    01/28/2022, 4:02 PM
    Hi all! I'm would like to create an AlertDialog with a scrollable content but I have a strange behavior with a padding in top of the dialog and the content that goes under my buttons in bottom of the dialog. There is already an issue created on the bugtracker somewhere about that?
    alert.mp4
    c
    a
    m
    • 4
    • 7
  • p

    PHondogo

    01/28/2022, 5:19 PM
    Hi! How can I make all rows in collumn has the same width = longest row in column?
    s
    • 2
    • 1
  • l

    Laura Kelly

    01/28/2022, 6:51 PM
    I'm using Compose in two repos -- one that is a small design system library and one very large monorepo that is organized into smaller modules. We've noticed that Compose previews are very slow in the monorepo. Has anyone dealt with this? Any tips for making previews faster in a large repo or know what specifically about a large repo causes this? We're currently using Bumblebee.
    m
    v
    • 3
    • 5
  • r

    Robert Menke

    01/28/2022, 9:41 PM
    Hey, I have an architecture question. I have a standard compose app with navigation-compose and an
    AuthenticationViewModel
    which is a
    @HiltViewModel
    that keeps track of the authenticated
    User
    entity as follows:
    private var authenticatedUser: LiveData<User?> = userRepository.observeAuthenticatedUser().asLiveData()
    After I’ve verified that a user is authenticated I want to be able to observe
    authenticatedUser
    and ideally receive the latest`User` instance without having to retrieve it from the database again. I have a component called
    ProfileScreen
    that tries to access that data as follows:
    val authViewModel: AuthenticationViewModel = hiltViewModel()
    val user by authViewModel.getAuthenticatedUser().observeAsState()
    val firstName by viewModel.firstName.observeAsState(user?.firstName ?: "")
    When I set a breakpoint on
    firstName
    the variable
    user
    is always
    null
    initially. What is the right way to keep my
    User
    instance in memory without having to re-fetch from the DB whenever I ask for it?
    i
    • 2
    • 5
Powered by Linen
Title
r

Robert Menke

01/28/2022, 9:41 PM
Hey, I have an architecture question. I have a standard compose app with navigation-compose and an
AuthenticationViewModel
which is a
@HiltViewModel
that keeps track of the authenticated
User
entity as follows:
private var authenticatedUser: LiveData<User?> = userRepository.observeAuthenticatedUser().asLiveData()
After I’ve verified that a user is authenticated I want to be able to observe
authenticatedUser
and ideally receive the latest`User` instance without having to retrieve it from the database again. I have a component called
ProfileScreen
that tries to access that data as follows:
val authViewModel: AuthenticationViewModel = hiltViewModel()
val user by authViewModel.getAuthenticatedUser().observeAsState()
val firstName by viewModel.firstName.observeAsState(user?.firstName ?: "")
When I set a breakpoint on
firstName
the variable
user
is always
null
initially. What is the right way to keep my
User
instance in memory without having to re-fetch from the DB whenever I ask for it?
i

Ian Lake

01/28/2022, 11:29 PM
If you look at the source code for `asLiveData()`, you'll see that it calls
collect
on the
Flow
, which is inherently an async operation. Now if your
UserRepository
was driven by Room and returned a
LiveData
itself, then you'd gain the natural caching that
LiveData
has where it always remembers any previously returned value just like how
StateFlow
works
Personally, I'd probably skip using LiveData at all here and use something like:
private var authenticatedUser: StateFlow<User?> = userRepository.observeAuthenticatedUser().stateIn(viewModelScope, SharingStarted.WhileSubscribed(), null)
Which would give you a
StateFlow
(which also always remembers its current value), that is Lifecycle aware (the
WhileSubscribed
prevents it from doing any work while your UI isn't collecting the StateFlow), and that still lets your Composable code call
collectAsState()
to easily gather the latest value
r

Robert Menke

01/28/2022, 11:58 PM
Thank you @Ian Lake I’ll give that a try tonight. This is a follow up from the same question I asked you on twitter and once again I want to express gratitude for your time and expertise. I’ll reply in thread with my solution if/when I get there.
👍 1
Alright I think I finally understand my main issue after setting some breakpoints within
@Composable
@PublishedApi
internal fun createHiltViewModelFactory(
    viewModelStoreOwner: ViewModelStoreOwner
): ViewModelProvider.Factory? = if (viewModelStoreOwner is NavBackStackEntry) {
    HiltViewModelFactory(
        context = LocalContext.current,
        navBackStackEntry = viewModelStoreOwner
    )
} else {
    // Use the default factory provided by the ViewModelStoreOwner
    // and assume it is an @AndroidEntryPoint annotated fragment or activity
    null
}
I had a
NavBackStackEntry
for my
SplashScreen
and a separate one for my
ProfileScreen
and yet another that didn’t have any associated
NavBackStackEntry
, so of course I was re-fetching user state after the initial authentication check. Seems like the right solution for something like authenticated user state is to create 1 instance of the view model outside of the navigation graph and then pass that instance into each
Composable
that needs it since being scoped to
@AndroidEntryPoint
I believe makes more sense here. I think I’ll move forward with that for now.
Yep, that did the trick 👍
View count: 1