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

    Colton Idle

    10/25/2021, 6:48 PM
    Using compose in prod (and coil for image loading) and started to see this stacktrace. Anyone know if this is a coil issue or a compose issue?
    Fatal Exception: java.lang.IllegalAccessError: Method 'void android.view.View.onAnimationEnd()' implementing interface method 'void coil.target.Target.onAnimationEnd()' is not public (declaration of 'androidx.compose.ui.platform.AndroidComposeView' appears in /data/app/~~D83UUWaeF7V8xBltnyPXpw==/base.apk)
    2 replies · 1 participant
  • n

    natario1

    10/25/2021, 7:57 PM
    Can anyone explain what
    SubcomposeLayoutState.maxSlotsToRetainForReuse
    is supposed to do? I have a LazyList-like component where only some children are subcomposed and I'm playing with this value, but I fail to see any effect. What's the metric I should be looking at?
    a
    7 replies · 2 participants
  • m

    Mikołaj Kąkol

    10/26/2021, 5:20 AM
    How in compose we should pass different states of UI (selected/checked/focued/enabled/etc)? In views we had all those state_xxx in xml. It’s bit cumbersome to pass all those states as params to function. I was wondering if few
    CompositionLocalPressed/Enabled
    would be a good idea? My main problem is how to change font color based on those states and I’m bit lazy to pass it to each function.
    m
    m
    11 replies · 3 participants
  • j

    Jason Roberts

    10/26/2021, 5:39 AM
    Hi, How can i get marker lat long by moving the map? i have a marker in the center of map
    l
    2 replies · 2 participants
  • k

    K Merle

    10/26/2021, 9:32 AM
    Is there a way to remove padding from the AlertDialog?
    c
    2 replies · 2 participants
  • i

    Ink

    10/26/2021, 11:53 AM
    Is it possible to set a shadow color?
    :no_red: 2
    f
    a
    2 replies · 3 participants
  • h

    Hatice Sarp

    10/26/2021, 12:12 PM
    Hello, I use compose throughout the app. I made 
    ripple
     transparent from material theme in Compose. When I make it transparent from this theme, ripple does not appear directly on compose. In some places I inflate composable into fragment with
    ComposeView
    .  The ripple of the items in the ComposeView is visible. What do you think I should do?
    c
    3 replies · 2 participants
  • m

    Mohammad Sianaki

    10/26/2021, 12:27 PM
    Hello, I have a
    Column
    with many
    TextField
    inside it, when I tap on the last
    TextField
    the Keyboard opens up and Covers the last
    TextField
    I have set
    android:windowSoftInputMode="adjustResize"
    in manifest but nothing changes.
    a
    2 replies · 2 participants
  • m

    mattinger

    10/26/2021, 3:15 PM
    So i’m toying with putting a LoggingContext in a composition local, and then using that inside my onClick events to do click logging. There’s two things here: 1. I have to get the loggingContext outside of the onClick, since it requires being in a composable environment, so i save it to a variable first and can reference it in onClick 2. I’m triggering a side effect by doing logging. I suppose this is kind of expected when clicking buttons. I’m just curious what the general consensus is on triggering side effects in an onClick (i can’t use SideEffect itself, but the function i’m calling is side effecting because it’s logging stuff)
    c
    4 replies · 2 participants
  • c

    clhols

    10/26/2021, 3:27 PM
    I have a Composable that is taller than the screen. I would like to animate it in using:
    AnimatedVisibility(enter = slideInVertically()) {}
    But the Composable get clipped by the screen height, so you only get to see the top part of it when it animates in. The Composable is scrollable, so my guess is that it is animating using the height of the scroll container and not the content. So I need the full content laid out when animating in but still scrollable afterwards. Any ideas on how to accomplish that?
    a
    2 replies · 2 participants
  • s

    Slackbot

    10/26/2021, 3:41 PM
    This message was deleted.
    c
    1 reply · 2 participants
  • c

    Chris Fillmore

    10/26/2021, 4:52 PM
    I have a
    LazyColumn
    with around ~75 items, including `stickyHeader`s, inside a bottom sheet, and the performance of
    LazyListState.animateScrollToItem()
    is noticeably bad. The animation is not smooth; it appears to just show a few frames before landing at the target index. Scrolling through the list manually otherwise works well enough. The items in the list have some state associated with them (they can be “favourited” (via a heart icon) or “toggled” (via a switch). They have other components which are visible (or interactive) conditionally. So they are perhaps relatively complex. Should I expect
    animateScrollToItem
    to be performant in this case? I’m wondering if others have encountered a similar situation. Thanks for the feedback.
    a
    f
    9 replies · 3 participants
  • a

    Ashu

    10/26/2021, 6:40 PM
    Coroutine launch is showing error when launched from a composable function. I am trying to show/hide ModalBottomSheetLayout by observing a state flow. How can I resolve this. Also, how do I implement multiple bottom sheets in same Layout?
    z
    m
    6 replies · 3 participants
  • n

    nglauber

    10/26/2021, 7:24 PM
    Is there a way to reassign the
    ViewModelStoreOwner
    of a
    hiltViewModel()
    ? 😛 Let’s say the user is in
    ScreenA
    and navigate to
    ScreenB
    . In
    ScreenB
    , I’m creating a viewmodel using
    hiltViewModel()
    . So, the scope of this viewmodel is
    ScreenB
    . Now, from
    ScreenB
    , I want to open
    ScreenC
    , pop
    ScreenB
    (therefore, the stack is
    ScreenA
    and
    ScreenC
    ), but reuse the viewmodel created in
    ScreenB
    . Is it possible? 🤔 (I wouldn’t create the viewmodel in
    ScreenA
    😞)
    i
    c
    6 replies · 3 participants
  • c

    Casey Brooks

    10/26/2021, 8:19 PM
    Is anyone aware of any libraries for displaying PDFs in Compose UI (specifically based on the built-in PdfRenderer)? A quick web search is flooded with paid libraries or View-based options, so it's not easy to find anything that's natively displayed in Compose if one even exists yet.
    i
    4 replies · 2 participants
  • y

    YASAN

    10/26/2021, 9:10 PM
    I am using Compose navigation for my app. I have 3 screens: A, B (dynamic) & C (dynamic). The user can navigate to a new C screen from all 3 screens but I want there to be only 1 C screen. so anytime a new version is navigated to, the old C should be removed from back stack. Can anyone help me how I can achieve that? I have tried a few things but none worked properly
    d
    i
    +1
    22 replies · 4 participants
  • v

    Vinay Gaba

    10/26/2021, 9:22 PM
    Has there been any conversation around when Compose will be able to target Kotlin 1.6?
    j
    2 replies · 2 participants
  • s

    Slackbot

    10/26/2021, 11:12 PM
    This message was deleted.
    ➕ 1
    a
    1 reply · 2 participants
  • c

    Chintan Soni

    10/27/2021, 5:12 AM
    Hey guys,, Just wanted to know about the inspiration of creating Jetpack Compose UI toolkit? Whether they were: • Haunted by android View class (~15k lines of code) • Missing the flavour of Declarative UI Programming. Though they were too late to the party, as if we look at Web UI frameworks, ReactJS already adopted this back in 2013. • something else?
    r
    2 replies · 2 participants
  • m

    Michael Marshall

    10/27/2021, 5:22 AM
    I’m using the Accompanist
    HorizontalPager
    and I’ve noticed that doing something like,
    val scope = rememberCoroutineScope()
    val pagerState = rememberPagerState()
    ...
    Tab (
        ...
        onClick = { scope.launch { pagerState.animateScrollToPage(index) } }
        ...
    )
    feels like a bit of an imperative programming anti-pattern compared to declaratively creating an
    AnimatedContent
    as described in the docs. I assume it’s doing something similar under the hood anyway, and this is just a convenience function, so it’s ok?
    c
    1 reply · 2 participants
  • k

    K Merle

    10/27/2021, 7:14 AM
    Adding Accompanist Navigation Animation to the project gives me
    java.lang.NoSuchMethodError: No static method fadeIn$default(FLandroidx/compose/animation/core/FiniteAnimationSpec;ILjava/lang/Object;)Landroidx/compose/animation/EnterTransition; in class Landroidx/compose/animation/EnterExitTransitionKt; or its super classes (declaration of 'androidx.compose.animation.EnterExitTransitionKt'
    ...
    Anyone know what could be the problem?
    f
    4 replies · 2 participants
  • t

    Tolriq

    10/27/2021, 8:35 AM
    Is there an idiomatic way to have derivedStateOf to return current content and do not update the calculation based on some flag? For example given
    val playlistItems by remember { derivedStateOf { playlistContent.toMutableList() } }
    I'd like to ignore playlistContent changes in some cases. I can use another variable to store a copy of the actual value and return it, but I wonder if there's something more integrated.
    a
    6 replies · 2 participants
  • a

    Ashu

    10/27/2021, 9:33 AM
    Any way to create layout of BottomSheetDialogFragment using compose? Any
    setContent
    equivalent for dialog fragments?
    c
    a
    4 replies · 3 participants
  • y

    YASAN

    10/27/2021, 10:25 AM
    I am having some confusion on how I should handle life cycles on Compose to achieve the behavior I want. I have a traditional
    View
    on my Composable which I need to
    init
    to show. The
    init
    is a heavy process so I really want to avoid doing it when its not needed.
    a
    9 replies · 2 participants
  • c

    colintheshots

    10/27/2021, 2:26 PM
    When I'm running integration tests made with
    createComposeRule()
    , I seem to be running into an issue where my font family is triggering the following error. This doesn't happen normally when using the app. Why is this only occurring in the test on the first TextStyle passed to the Typography constructor and how can I resolve it? Do I have to provide the font family differently for tests, since it appears that it thinks the FontFamily I defined is null?
    Caused by: java.lang.NullPointerException: Parameter specified as non-null is null: method kotlin.jvm.internal.Intrinsics.checkNotNullParameter, parameter h4
    1 reply · 1 participant
  • c

    Colton Idle

    10/27/2021, 4:02 PM
    I have a composable, that draws other composables from a list as seen here:
    val myListOfComposables = mutableStateListOf<@Composable () -> Unit>()
    This code triggers a lint warning/error that I should remember it. When I remember it, then I get duplication, seemingly every time it recomposes.
    val myListOfComposables = remember { mutableStateListOf<@Composable () -> Unit>() }
    Is the lint issue wrong? Or am I doing something wrong?
    a
    2 replies · 2 participants
  • a

    Anton Afanasev

    10/27/2021, 4:33 PM
    Hi. Does anyone know if Compose already support
    kotlin 1.6.0-RC
    version?
    j
    2 replies · 2 participants
  • l

    Lucien Guimaraes

    10/27/2021, 4:47 PM
    Following this official documentation on conditional navigation, I have a question regarding Compose navigation. In my home screen I have a Scaffold with a bottom bar. For one of the tab I display the account screen. And from the AccountViewModel I listen if the user is logged or not. If not I want to show the login screen incentive. And after user is successfully signIn/signUp, I popUp back to the account screen The login feature is in a separate module, so I have a dedicated NestedGraph for all login screens (login incentive, signIn, signUp....). My question is: where to add this nested graph ? Should it be inside a new NavHost in my AccountScreen ? Or should it be somewhere else, like inside my Home NavHost ? 🤔
    ➕ 2
    a
    1 reply · 2 participants
  • d

    Danish Ansari

    10/27/2021, 5:29 PM
    how can we retain scroll position of
    LazyColumn
    when navigating from screen A to screen B and coming back Screen A contains 20 items, user scrolled to 15th item, selected 15th item, Screen B opened, came back, list gets reset, scrolled to 1st item But I want the 15th item to be visible
    a
    t
    24 replies · 3 participants
  • m

    mattinger

    10/27/2021, 7:44 PM
    So i’m curious how you can create a view model backed by MutableState but still be able to have the data saved to the savedStateHandle. With livedata i could just back the entire property by the saved state handle, assuming the value was parcelable.
    data class UIState(val startTime: Long = System.currentTimeMillis())
    
    class UIStateVM(savedStateHandle: SavedStateHandle): ViewModel() {
        private val _uiState = mutableStateOf(UIState())
        val uiState: State<UIState> get() = _uiState
    }
    a
    i
    +1
    4 replies · 4 participants
Powered by Linen
Title
m

mattinger

10/27/2021, 7:44 PM
So i’m curious how you can create a view model backed by MutableState but still be able to have the data saved to the savedStateHandle. With livedata i could just back the entire property by the saved state handle, assuming the value was parcelable.
data class UIState(val startTime: Long = System.currentTimeMillis())

class UIStateVM(savedStateHandle: SavedStateHandle): ViewModel() {
    private val _uiState = mutableStateOf(UIState())
    val uiState: State<UIState> get() = _uiState
}
I could do this manually, but it seems like there should be a better way:
init {
        savedStateHandle.get<UIState>("uiState")?.let { state ->
            _uiState.value = state
        }
        viewModelScope.launch {
            snapshotFlow { uiState.value }.collect { state ->
                savedStateHandle.set("uiState", state)
            }
        }
    }
a

Alex Vanyo

10/27/2021, 9:41 PM
There currently isn’t a better built-in way, unfortunately. A complete solution would also likely take advantage of the
Saver
interface from Compose. You can follow https://issuetracker.google.com/issues/195689777 for any updates around this area.
i

Ian Lake

10/27/2021, 10:15 PM
Have you looked at SavedStateHandle's support for non-parcelable classes? That seems like exactly what you need: https://developer.android.com/topic/libraries/architecture/viewmodel-savedstate#non-parcelable
k

KamilH

10/28/2021, 6:50 AM
I’m not sure if it’s what you’re looking for, but this article presents an interesting solution to connect
SavedStateHandle
with
MutableState
View count: 2