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

    Rak

    01/19/2022, 4:20 PM
    Hi, how would I use compose for a
    DialogFragment
    ?
    t
    c
    • 3
    • 6
  • b

    Brian Donovan

    01/19/2022, 4:25 PM
    Hey all, how can I add space between inside of the topAppBar? Should look like the figma
    s
    c
    c
    • 4
    • 17
  • t

    Tolriq

    01/19/2022, 5:34 PM
    What would be the idiomatic way to autoscroll a scrollable when it's parent container padding change?
    d
    • 2
    • 5
  • c

    Colton Idle

    01/19/2022, 6:03 PM
    Can you
    remember {}
    a when statement? I'm trying something like this
    remember{
       when (someValue) {
           optionA -> {
               doSomething()
    but I get an error of "remember calls must not return Unit"
    d
    j
    • 3
    • 9
  • r

    rsktash

    01/19/2022, 6:22 PM
    I think compose icons package must be separate from material package. It’s strange to import material package when using material 3 components
    c
    l
    • 3
    • 4
  • h

    Huan

    01/19/2022, 6:41 PM
    Hi I have a strange behavior using
    Sealed class
    ,
    when
    and
    flow
    with
    LazyColumn
    🧵
    f
    • 2
    • 3
  • b

    brabo-hi

    01/19/2022, 7:47 PM
    Hi all, what is the best way to host a composable child that has a navbar? should we have two
    NavHost
    ?
    • 1
    • 4
  • s

    Simon Stahl

    01/19/2022, 8:01 PM
    Hey everyone. I am looking for recommendations for animations between separate Composables - animate something from one Composable to another (details in comments)
    • 1
    • 5
  • m

    Manojna Chintapalli

    01/19/2022, 8:07 PM
    Hi! I have a Side Nav drawer that I'm implementing using
    drawerContent
    in the
    Scaffold
    of
    BottomSheetScaffold
    and the bottomsheet is always displayed at the bottom partially(acc. to the designs). My issue is that when I open Side Nav drawer the bottomsheet is covering some contents of the Nav drawer at the bottom. I am able to collapse the bottomsheet all the way to the bottom when Side Nav is opened by using
    DisposableEffect
    but is there any other way to achieve this without the brute force method?
    if (drawerScaffoldState.drawerState.currentValue != DrawerValue.Closed) {
         DisposableEffect(Unit) {
             onDispose {
           // do soemthing
            }
          }
     }
    c
    • 2
    • 2
  • e

    elye

    01/19/2022, 8:16 PM
    Is Compose Function can’t take in Reified inline function? The below example compiles well but fail at runtime
    This function has a reified type parameter and thus can only be inlined at compilation time, not called directly
    @Composable
    fun Launcher() {
        val context = LocalContext.current
        LazyColumn(modifier = Modifier.fillMaxWidth(),
            horizontalAlignment = Alignment.CenterHorizontally) {
            item {
                context.StartActivityButton<LaunchedEffectActivity>()
            }
        }
    }
    
    @Composable
    private inline fun <reified T : Activity>Context.StartActivityButton() {
        Button(onClick = {
            startActivity(Intent(this, T::class.java))
        }) {
            Text(T::class.toString())
        }
    }
    More info here https://stackoverflow.com/q/70768211/3286489
    m
    z
    • 3
    • 9
  • n

    natario1

    01/19/2022, 8:34 PM
    Is it expected that a text field (BasicTextField) stops working (no keyboard, no focus) if the parent has
    clickable(enabled=false, onClick=...)
    ? This used to work.
    c
    z
    • 3
    • 6
  • e

    elye

    01/19/2022, 8:48 PM
    Is the SideEffect
    deriveStateOf
    not able to work together with
    snapshotFlow
    in aiding recomposition? Separate them out seems working, but not together. The code example in https://stackoverflow.com/q/70771821/3286489
    z
    a
    a
    • 4
    • 6
  • c

    Colton Idle

    01/19/2022, 10:03 PM
    Is anyone super familiar with hiltViewModel() and compose nav. Starting to go crazy on this error that it can't create a VM. Am I doing something obvioiusly wrong here?
    bottomSheet(route = Screen.DebugBottomSheet.route) {
      DebugBottomSheet(previousScreenVM = hiltViewModel(remember { navController.previousBackStackEntry!! }))
    }
    my bottomsheet
    @Composable
    fun DebugBottomSheet(
        viewModel: DebugBottomSheetViewModel = hiltViewModel(),
        previousScreenVM: ViewModel,
    ) {}
    Error:
    java.lang.RuntimeException: Cannot create an instance of class androidx.lifecycle.ViewModel
    a
    j
    • 3
    • 5
  • a

    Altynbek Nurtaza

    01/19/2022, 10:06 PM
    Hi all, I have a ParentFragment with CollapsingToolbarLayout + ViewPager2, and 2 childFragments inside the viewPager: one with compose LazyColumn and another with recyclerView. The problem I am having is that collapsingToolbarLayout collapses as expected when scrolling the recyclerView, but doesn’t move when scrolling the LazyColumn. how can I solve this problem?
    • 1
    • 1
  • j

    justinbis

    01/19/2022, 11:37 PM
    The Compose roadmap has "Support Async Drawing" and "Support multithreaded scheduler" in focus, though I haven't seen anything about these since Compose went stable. Does anyone have more info on if/when Compose is implementing more multithreading or other similar performance optimizations?
    a
    • 2
    • 2
  • b

    brabo-hi

    01/20/2022, 2:01 AM
    Hi all, what is the difference between
    navController.popBackStack()
    and
    navController.navigateUp()
    i
    c
    • 3
    • 3
  • m

    Moritz Post

    01/20/2022, 11:52 AM
    Hello. I am using the
    Canvas
    composable in my compose desktop app. I have found that the
    Canvas.onDraw
    method is called multiple times although the size of the canvas has not canged. This leads to jank since the drawing is quite intensive. Next to the canvas i have a couple of items that are clickable() so they show hoover feedback for the mouse cursor. Even just hoovering over these unrelated items triggers a redraw of the canvas. Is there a way to circumvent this redrawing?
    t
    • 2
    • 4
  • a

    Asif

    01/20/2022, 12:07 PM
    anyone implemented, deep linking in compose, any example??
    👀 2
    v
    i
    • 3
    • 2
  • g

    Gerardo Ernesto Rodriguez Navar

    01/20/2022, 2:38 PM
    Does anyone know how to update a recyclerview that is inside a Compose AndroidView?
    z
    c
    • 3
    • 6
  • v

    Viktor Petrovski

    01/20/2022, 2:57 PM
    Lets say I want to design a top level pop-up, like an in-app notification that should show on top of every screen regardless where the current user is navigated. How would you design your composable? Is this something I want to setup when configuring the NavHost in the MainActivity? 🤔
    ➕ 1
    c
    • 2
    • 1
  • b

    Brian Donovan

    01/20/2022, 3:10 PM
    If I am grabbing data from a network call in the viewmodel can I show the data on my preview?
    c
    c
    • 3
    • 2
  • z

    Zoltan Demant

    01/20/2022, 4:42 PM
    If I bring up and then hide the soft-keyboard, it seems to swallow an extra back-press (even after being completely hidden). Anyone else seeing this? Im using androidx.activity.compose.BackHandler.
    z
    g
    • 3
    • 4
  • t

    Topaz Centuallas

    01/20/2022, 5:59 PM
    Hey guys, is it possible to animate between two different composables?
    c
    c
    +2
    • 5
    • 13
  • i

    Ink

    01/20/2022, 7:25 PM
    Is it possible to override ripple color for whole application in one place?
    c
    • 2
    • 3
  • l

    Laura Kelly

    01/20/2022, 9:48 PM
    I’m working on accessibility for a custom checkbox component, trying to get the error state to read out correctly on a screen reader. Right now when the checkbox has an error, the error message is not being read by TalkBack. The code looks something like:
    Box(
     modifier = modifier
       .triStateCheckbox(…)
       .requiredSize(…)
       .border(…)
       .background(…)
       .semantics {
         error("Error invalid input")
        }
    ) {
     MyIcon(
      contentDescription = null,
      modifier = Modifier.clearAndSetSemantics {}
     )
    }
    I set some breakpoints and
    SemanticsPropertyReceiver.error
    is being set correctly, but
    setContentInvalid
     in 
    AndroidComposeViewAccessibilityDelegateCompat
     is not. I tried removing the inner icon since it’s altering its semantics but that doesn’t seem to change anything. I’m trying to figure out if I am doing something wrong in using
    .semantics
    or if there might be bug here.
    z
    • 2
    • 4
  • t

    tad

    01/20/2022, 11:35 PM
    Hi, I've opened a change request to Compose in AOSP Gerrit. Should I add Code Owners myself, or does someone make the rounds for external changes?
    j
    • 2
    • 2
  • c

    Chris Fillmore

    01/21/2022, 12:01 AM
    Does it make sense to back a toggleable component (Switch/Checkbox) using a
    StateFlow<Boolean>
    ? Even if there are many such components in a list? (dozens? hundreds?)
    a
    • 2
    • 5
  • c

    Colton Idle

    01/21/2022, 4:50 AM
    SideEffect{}
    is triggered on a successful composition. Let's say all I'm doing is incrementing a variable in that block. What if I wanted to increment on every composition (successful and "failed"). Is there any sideEffect type block for that? Or would I just put that in my composable without any sideeffect-esque {} and that basically counts as failed + successful compositions?
    z
    • 2
    • 2
  • c

    Colton Idle

    01/21/2022, 7:23 AM
    I've read Zach K blog posts on the topic but I'm still encountering a situation that I can't seem to untangle. Essentially I have a list of items. This list is a mutableStateList. Every item could also have a single property that is also mutableState. When I update this item mutableState, I don't see the composable recompose. Can anyone spot any egregious issues here?
    class ScreenViewState {
      val list = mutableStateListOf<Item>()
    and my Item
    class ConcreteType(override val type: String = "") : Item {
        var something by mutableStateOf("beep")
    then in my VM I call
    (myItem as ConcreteType).something = "boop"
    My composable always beeps, but never boops.
    k
    z
    • 3
    • 10
  • m

    MRSasko

    01/21/2022, 7:45 AM
    Is there a way to persist the state of a MapView with compose? I am using bottom navigation where one of the tabs contains a mapview. But every time I go to another tab and go back to the map tab, the map gets re-compose and I lose the state. I am using these helper methods: ``````
    r
    c
    • 3
    • 4
Powered by Linen
Title
m

MRSasko

01/21/2022, 7:45 AM
Is there a way to persist the state of a MapView with compose? I am using bottom navigation where one of the tabs contains a mapview. But every time I go to another tab and go back to the map tab, the map gets re-compose and I lose the state. I am using these helper methods: ``````
r

rattleshirt

01/21/2022, 8:07 AM
I had this exact problem and solved it with:
val state by rememberSaveable(key = "mapState") {
        mutableStateOf(Bundle())
    }
and pass it to onCreate:
Lifecycle.Event.ON_CREATE -> mapView.onCreate(state)
otherwise you are always creating a new bundle and losing its state
c

Colton Idle

01/21/2022, 8:07 AM
@MRSasko Could you edit your question to put more of it in the thread? See: https://kotlinlang.slack.com/archives/CJLTWPH7S/p1616265877303000
m

MRSasko

01/21/2022, 8:24 AM
The code: example:
@Composable
fun rememberMapViewWithLifecycle(): MapView {
    val context = LocalContext.current
    val mapView = remember {
        MapView(context).apply {
            id = R.id.map
        }
    }

    // Makes MapView follow the lifecycle of this composable
    val bundle = Bundle()
    val lifecycleObserver = rememberMapLifecycleObserver(mapView, bundle)
    val lifecycle = LocalLifecycleOwner.current.lifecycle
    DisposableEffect(lifecycle) {
        lifecycle.addObserver(lifecycleObserver)
        onDispose {
            lifecycle.removeObserver(lifecycleObserver)
        }
    }

    return mapView
}

@Composable
private fun rememberMapLifecycleObserver(mapView: MapView, bundle: Bundle): LifecycleEventObserver =
    remember(mapView) {
        LifecycleEventObserver { _, event ->
            when (event) {
                Lifecycle.Event.ON_CREATE -> mapView.onCreate(bundle)
                Lifecycle.Event.ON_START -> mapView.onStart()
                Lifecycle.Event.ON_RESUME -> mapView.onResume()
                Lifecycle.Event.ON_PAUSE -> mapView.onPause()
                Lifecycle.Event.ON_STOP -> mapView.onStop()
                Lifecycle.Event.ON_DESTROY -> mapView.onDestroy()
                else -> throw IllegalStateException()
            }
        }
    }
:thank-you: 1
@rattleshirt It’s not working when I save the Bundle. I could save all of the MapState(zoom, cameraTarget) and so, into a MapViewModel?
View count: 1