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

    RayeW47

    06/08/2022, 7:51 PM
    Anybody have any tips for converting a
    class
    to a
    @Composable fun
    ? I can't quite conceptualize it and for the most part I'm writing imperative UI with compose
    a
    f
    • 3
    • 7
  • f

    fengdai

    06/09/2022, 12:30 AM
    When move movable content (
    movableContentOf
    ) from/to a
    SubcomposeLayout
    , the
    AndroidView
    within it will recreate its view.
    // When rotate screen, AndroidView recreate its view
    val content = remember {
        movableContentOf { isLandscape: Boolean ->
            AndroidView(factory = { context ->
                Log.d("AndroidView", "create view")
                TextView(context).apply {
                    layoutParams = ViewGroup.LayoutParams(MATCH_PARENT, MATCH_PARENT)
                }
            }) {
                it.text = if (isLandscape) "Landscape" else "Portrait"
            }
        }
    }
    val isLandscape =
        LocalConfiguration.current.orientation == Configuration.ORIENTATION_LANDSCAPE
    BoxWithConstraints {
        if (!isLandscape) {
            content(false)
        }
    }
    if (isLandscape) {
        content(true)
    }
    Is this expected?
    a
    • 2
    • 3
  • d

    danprado

    06/09/2022, 1:53 AM
    Hey folks! Does anybody know if there’s a way to detect any user interaction (taps/clicks anywhere on the screen) within a Compose app? I tried using a container Composable with
    pointerInput
    , but that only works when I interact outside of buttons. Basically, what I need is a Compose version of the
    onUserInteraction()
    Activity callback.
    c
    z
    m
    • 4
    • 7
  • s

    Simon Stahl

    06/09/2022, 1:59 AM
    Hi. I am playing around with navigation in compose, but with no known pages. The idea is to have only one route
    page/{pageName}
    and then use
    pageName
    to to render the correct data. I mostly wanted to use navigation because of the built in backstack
    @Composable
    fun NavigationTest() {
        val navController = rememberNavController()
        Scaffold(
            bottomBar = { SimpleBottomNav(navController) }
        ) { innerPadding ->
            NavHost(navController, startDestination = "page/{pageName}", Modifier.padding(innerPadding)) {
                composable(
                    "page/{pageName}",
                    arguments = listOf(navArgument("pageName") { defaultValue = "profile" })
                ) { backStackEntry ->
                    val pageName = backStackEntry.arguments?.getString("pageName")
                    if (pageName != null) {
                        PageContent(name = pageName)
                    } else {
                        Text(text = "No page name")
                    }
                }
            }
        }
    }
    See
    SimpleBottomNav
    code in the comments. The main issues that I have is that 1.
    popUpTo()
    does not seem to work properly when the startDestination has an argument in it and 2. the compose context seems to be shared between the different pages. E.g. when i use a LazyList in them, they all share the same scroll state. Did anyone ever have the same issues or has a working example for something similar?
    i
    c
    • 3
    • 24
  • s

    Stylianos Gakis

    06/09/2022, 7:10 AM
    I know when we need to remember something that doesn’t need to then be mutated, we can simply wrap it in a remember without the mutableStateOf, like
    val item = remember(someKey) { ExpensiveConstructedThing() }
    instead of
    val item by remember(someKey) { mutableStateOf(ExpensiveConstructedThing()) }
    However after reading about this very informative article and some official docs, to my understanding when we use
    by
    on the state object, we get the neat effect of not reading the value at that moment, but deferring the read to whenever we actually need it. Which sometimes comes with the nice side-effect or reading that state object in a “smaller” recomposition scope meaning that when it changes we don’t invalidate the wider recomposition scope that the above definition may be in. So if we do not do this, but use simply
    val item = remember(someKey) { ExpensiveConstructedThing() }
    do we lose this nice side effect? When
    someKey
    does change, and the result of
    item
    changes with it, will it invalidate the recomposition scope in which it is declared in as opposed to where it is actually read?
    👀 2
    a
    k
    z
    • 4
    • 15
  • k

    krzysztof

    06/09/2022, 9:03 AM
    What would be the best way to react to
    mutableStateListOf
    changes in effects? Say, I have
    Parent
    which has state
    remember { mutableStateListOf<Int>() }
    which can be changed by one of its children.
    Parent
    also has an effect (let’s say
    DisposableEffect
    ) reading changes to the list, like
    DisposableEffect(list){/* ... */}
    . But that effect won’t be called more than once, because
    list
    won’t change instance (
    SnapshotStateList
    ), even if items are added.
    s
    s
    z
    • 4
    • 19
  • f

    Frank van der Laan

    06/09/2022, 9:09 AM
    When a library starts to use jetpack compose for some of its UI components, do all apps using the library have to setup compose dependencies as well?
    m
    c
    • 3
    • 9
  • a

    allan.conda

    06/09/2022, 9:35 AM
    We’re struggling to achieve Zoomable Images in a Pager since Pager steals all the touches and
    pointerInput
    seems doesn’t have the pointer id to detect the number of pointers on screen. Anyone tried anything similar? We can’t find an open-source code or snippet available so far.
    a
    m
    c
    • 4
    • 17
  • m

    Mehdi Haghgoo

    06/09/2022, 10:51 AM
    Why using AndroidComposeTestRule and ComposeTestRule in the same test class is not possible?
    p
    • 2
    • 1
  • s

    ste

    06/09/2022, 1:18 PM
    Is there a way to pin a
    LazyList
    item so it doesn't get removed when it goes out of bounds? This would allow scrolling when reordering the items in a list (at least looking at my implementation). I see there are
    PinnableParent
    ,
    PinnableParent.PinnedItemsHandle
    ,
    lazyListPinningModifier
    ,
    ModifierLocalPinnableParent
    and so on, but I couldn't find any example.
    👀 1
    a
    • 2
    • 6
  • j

    jasu

    06/09/2022, 1:58 PM
    I’m facing very good problem :internet-problems: I’ve AndroidView which contains EditText. I’m not hoisting the state instead letting editText hold its own state. But sometimes I want to set text from out side, lets say I want to undo the last text so how do I do it?
    b
    l
    • 3
    • 4
  • a

    Aaron Waller

    06/09/2022, 3:52 PM
    How to call functions inside AndroidView or AndroidViewBinding composable? In the old view system if I needed to update multiple views in multiple places, I simply created a function for that:
    private fun updateViews(value1: Int, value2: Int) = with(binding) {
        timelineTextView.text = "$value1, $value2"
        ... A lot of other stuff
    
    }
    How is that possible when using the AndroidViewBinding Composable?
    @Composable
    fun MainScreen(){
        AndroidViewBinding(ActivityPlayBinding::inflate) {
            playButton.setOnClickListener {
                updateViews(value1, value2)
            }
    
            playButton2.setOnClickListener {
                updateViews(value1, value2)
            }
        }
    }
    How can I call that
    updateViews
    function in Compose? Simply putting the content of updateViews function where the function gets called feels really bad cause that causes a lot of duplicate code. But I cant seem to find the right way to do it…
    m
    • 2
    • 1
  • e

    Esme

    06/09/2022, 4:24 PM
    Is there an implementation available now that you can recommend for staggered grids with lazy?
    c
    a
    • 3
    • 7
  • y

    Yann Badoual

    06/09/2022, 4:36 PM
    Any simple way to draw this kind of code
    TextField
    ? Two ideas in mind: • Using N
    TextField
    • Drawing a canvas above the actual
    TextField
    Wondering if there's no better way to do this
    j
    • 2
    • 2
  • b

    Billy Newman

    06/09/2022, 4:59 PM
    Hello all. Just getting starting with compose navigation, trying to set my general app structure. I will have some main screens to handle app setup for the user and authentication. Once authenticated I would like to navigate to the home screen, which has a bottom navigation in a scaffold. I am trying to do this with 2 NavHosts, which means I need to nav controllers. Everything works fine from the main screen to the home screen, but upon navigation from home back to main (simulated logout), if I try and go back to the home screen I get
    ViewModelStore should be set before setGraph call
    Code in comments
    c
    s
    +2
    • 5
    • 29
  • j

    Jorge Domínguez

    06/09/2022, 8:25 PM
    I'm making a simple TextField
    VisualTransformation
    to ignore blank spaces, but when I tap the space bar multiple times and then I try to undo the typing it's counting all the blank spaces that were ignored, as seen in the video. Also, when I type two blank spaces it transforms them into a "." character. Any idea what I might be doing wrong?
    val ignoreBlanksVisualTransformation = VisualTransformation { text ->
        val blanksCount = text.text.count { it.toString().isBlank() }
        val transformedText = text.text.filterNot { it.toString().isBlank() }
    
        TransformedText(AnnotatedString(transformedText), object : OffsetMapping {
            override fun originalToTransformed(offset: Int) = offset - blanksCount
            override fun transformedToOriginal(offset: Int) = offset + blanksCount
        })
    }
    Screen Recording 2022-06-09 at 3.19.17 PM.mov
    e
    • 2
    • 3
  • f

    farmerbb

    06/09/2022, 10:02 PM
    Is there any way to obtain the scroll position in pixels for a LazyListState?
    🇳🇴 1
    f
    a
    • 3
    • 4
  • e

    eygraber

    06/10/2022, 12:07 AM
    Are there any tricks to testing
    LaunchedEffect
    as far as
    TestDispatcher
    is concerned? I'm trying to
    advanceTimeBy
    past a
    delay
    in a
    LaunchedEffect
    but that isn't working because the dispatcher is a
    AndroidUiDispatcher
    (or
    FlushCoroutineDispatcher
    in desktop). As far as I can tell, the only way around this is to create a new context (
    launch
    ,
    withContext
    , etc...) that uses the
    TestDispatcher
    . Is that correct, or am I missing something?
    z
    e
    i
    • 4
    • 10
  • t

    Tomas Gordian

    06/10/2022, 2:55 AM
    Hello, I am having a problem with Ime paddings and
    BottomSheetDialogFragment
    . It looks like ime padding is not applying on APIs 29 and lower.
    ➕ 1
    z
    a
    • 3
    • 9
  • j

    julian

    06/10/2022, 3:07 AM
    What would be the consequences of not
    remember
    -ing
    backCallback
    in the following? In other words, why
    remember
    backCallback
    ?
    @Composable
    fun BackButtonHandler(
      enabled: Boolean = true,
      onBackPressed: () -> Unit
    ) {
      val dispatcher = localBackPressedDispatcher.current ?: return
      val backCallback = remember { // <--- HERE
        object : OnBackPressedCallback(enabled) {
          override fun handleOnBackPressed() {
            onBackPressed.invoke()
          }
        }
      }
      DisposableEffect(dispatcher) {
        dispatcher.addCallback(backCallback)
        onDispose {
          backCallback.remove()
        }
      }
    }
    i
    z
    • 3
    • 9
  • j

    jasu

    06/10/2022, 6:45 AM
    androidViewWebView.kt
    j
    • 2
    • 3
  • r

    Rajat Singh Jasrotia

    06/10/2022, 6:49 AM
    In Composable, how can we let some portion of the child view to inflate outside the parent’s bound. Kindly help.
    o
    • 2
    • 2
  • n

    Ngọc Nguyên Nguyễn

    06/10/2022, 8:48 AM
    Why is Modifier.statusPadding() is not working in compose 1.2beta02 -> 1.2beta03
    c
    z
    • 3
    • 5
  • m

    Mehdi Haghgoo

    06/10/2022, 10:17 AM
    Has anyone updated Kotlin to 1.7.0 in Electric Eel Alpha 03? I am having problems in my Compose project to update. Error: This version (1.2.0-alpha09) of the Compose Compiler requires Kotlin version 1.6.21 but you appear to be using Kotlin version 1.7.0 which is not known to be compatible. Please fix your configuration (or
    suppressKotlinVersionCompatibilityCheck
    but don't say I didn't warn you!).
    f
    m
    +2
    • 5
    • 6
  • a

    Ahmed Shehata

    06/10/2022, 11:04 AM
    Hi everyone, I 'm developing a music player app using compose But I want to detect if user has touched or moving the slider component so I can stop playing music and update the slider value upon the user moves. But ths Slider in compose has only onValueChange listener that has been fired after user changes the slider value not while changing the value. How can I solve this problem?
    r
    a
    b
    • 4
    • 4
  • j

    Jonas

    06/10/2022, 12:44 PM
    A11y - Screen Reader I use clearAndSetSemantics to change the order of / and combine two texts. This works great if I swipe with the screen reader to this column but I cannot select the elements / column anymore to read it out loud. When I press I hear another sound than pressing empty space but the element is not selected and not read out. Is this a bug / intended behaviour or do I miss something here?
    val value = "value"
    val label = "label"
    Column(modifier = Modifier.clearAndSetSemantics { contentDescription = "$label: $value" }) {
        Text(value)
        Text(label)
    }
    • 1
    • 2
  • p

    Programmistich

    06/10/2022, 4:51 PM
    Any ideas how to set dim in Popup Compose? In Dialog we have dim alpha from android:backgroundDimAmount, but Popup doesn`t exist
    a
    • 2
    • 15
  • t

    Tash

    06/10/2022, 6:15 PM
    Looking for a good way to draw a 45deg linear gradient. Came across this SO, but wondering if there’s a more up-to-date alternative 🤔
    c
    a
    • 3
    • 7
  • o

    orangy

    06/10/2022, 8:33 PM
    Folks, is there any easy way to animate the
    Brush
    object? At least for
    SolidColor
    ?
    c
    c
    b
    • 4
    • 10
  • b

    Billy Newman

    06/10/2022, 8:50 PM
    Hello all, seeing what I think might be a bug w/ compose navigation using a startDestination with a nullable default parameter. If my NavHost is using a route with a nullable default parameter it seems the navigation lib cannot find the route.
    navigation destination home?foo=bar is not a direct child of this NavGraph
    Code in reply
    i
    • 2
    • 10
Powered by Linen
Title
b

Billy Newman

06/10/2022, 8:50 PM
Hello all, seeing what I think might be a bug w/ compose navigation using a startDestination with a nullable default parameter. If my NavHost is using a route with a nullable default parameter it seems the navigation lib cannot find the route.
navigation destination home?foo=bar is not a direct child of this NavGraph
Code in reply
NavHost(
            navController = navController,
            startDestination = "home"
         ) {
            composable(
              route = "home?foo={bar}",
              arguments = listOf(navArgument("foo") { defaultValue = ""; })
            ) { backstackEntry ->
versions:
navigation-compose:2.4.2
compose-version:1.2.0-beta03
I have tried different combinations of nav argument with defaultValue, and nullable. Also tried to pass a dummy arg in the startDestination route. Is this a bug or am I doing something wrong?
Should note, searched through issue tracker, didn’t find anything.
i

Ian Lake

06/10/2022, 9:04 PM
Use `defaultValue`: https://kotlinlang.slack.com/archives/CJLTWPH7S/p1623851605280400?thread_ts=1623841420.270700&amp;cid=CJLTWPH7S
b

Billy Newman

06/10/2022, 9:11 PM
Ah, arguments is the issue. Thank you!
Ian, any idea if this has been discussed as a future enhancement. Things start to get messy quickly when using string constants for route values. Sure you can add “{userId}” to the route constant. However you still run into issues when trying to navigate to a route with a non default parameter if using the sting constant. In the case of using arguments, perhaps the startDestination could match on the everything but the args. I am sure there is a lot more at play, just a thought
i

Ian Lake

06/10/2022, 9:57 PM
If this is anything to do with your previous thread and how you are trying to build dynamic destinations, then you're just misusing arguments entirely 🙂
The start destination of your graph should just be
home
because your route for your screen should be
home
- arguments shouldn't be a part of it at all
👍 2
I commented back on your other thread with what I was suggesting
b

Billy Newman

06/10/2022, 10:49 PM
Ugh, sorry Ian, that makes sense. Home will not be my app entry point, it is temporarily as I build out the app.
View count: 10