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

    Lawrence

    08/18/2022, 6:38 PM
    I am trying to implement this Stepper component from React with a similar API in Compose. I am trying to see if this is the Compose way of doing things.
    // React
    <Stepper activeStep={1}>
      {steps.map((label) => (
        <Step key={label}>
          <StepLabel>{label}</StepLabel>
        </Step>
      ))}
    </Stepper>
    // Compose
    Stepper(Modifier.fillMaxSize(), step) {
       steps.forEach { Step(Modifier.padding(15.dp, it) }
    }
    Implementation in thread
    c
    8 replies · 2 participants
  • t

    Tolriq

    08/18/2022, 8:13 PM
    Is there a proper way to know if a Textview is visible on screen or have another composable over it?
    z
    7 replies · 2 participants
  • l

    Landry Norris

    08/18/2022, 9:00 PM
    Is there a way to have a background color with alpha on the popup for an ExposedDropDownMenu? It looks like there’s not a modifier being passed down to ExposedDropdownMenuPopup. When I apply a background color that has alpha, it looks like there’s still white color behind it.
    1 reply · 1 participant
  • l

    Lilly

    08/18/2022, 9:22 PM
    Is there a construct to determine when a screen starts?
    r
    l
    +1
    44 replies · 4 participants
  • s

    Sterling Albury

    08/19/2022, 1:57 AM
    I've got a composable that I want to navigate to - a bottom sheet - and I want to pass a string to it as an arg for a display message. the text is a bit long and has double quotes an other special characters in it. what's a good way to serialize this to pass it as a nav arg?
    i
    1 reply · 2 participants
  • a

    Alex Vanyo

    08/19/2022, 4:04 AM
    I'd play around with changing layoutInDisplayCutoutMode. There isn't a way at the moment to change that via accompanist/systemuicontroller, so you'll have to set it directly yourself.
    z
    1 reply · 2 participants
  • s

    Stylianos Gakis

    08/19/2022, 8:13 AM
    When using
    movableContentOf()
    , got an issue where the state does not persist when (I think) I’m using the content normally on one end, and inside a SubComposeLayout on the other call site. More details in Thread 🧵
    f
    6 replies · 2 participants
  • m

    Michael Flathe

    08/19/2022, 11:27 AM
    Hi, we are using Compose for a Big Screen Application however the scroll performance on the
    LazyVerticalGrid
    is really bad. Our Composables are pretty simple. We assign a key to every item and have only one
    contentType
    yet it's still lagging noticeably. For the scrolling we are using
    LazyGridState#animateScrollToItem
    (no real difference when using
    LazyGridState#animateScrollBy
    or a release build with R8 enabled). Any idea how the scroll performance can be improved or is this just like it is with compose these days? Following a video showing a "full page" scroll. (1.2.1 of compose-ui is used)
    z
    a
    +1
    3 replies · 4 participants
  • d

    dazza5000

    08/19/2022, 3:39 PM
    what would be the equivalent of setting and accessibility delegate in compose?
    ViewCompat.setAccessibilityDelegate(login_text_view_as_button_with_role,
        object : AccessibilityDelegateCompat() {
            override fun onInitializeAccessibilityNodeInfo(v: View, info: AccessibilityNodeInfoCompat) {
                super.onInitializeAccessibilityNodeInfo(v, info)
                info.roleDescription = "Button"
            }
    })
    v
    5 replies · 2 participants
  • a

    AmrJyniat

    08/19/2022, 4:41 PM
    I created sealed class for UiState as the following:
    sealed class LoginUiState
    data class LoginEmailUiState(val email: String = ""): LoginUiState()
    data class ResetPasswordUiState(val email: String = ""): LoginUiState()
    .....
    Each class represent a page, then I hide\ show the proper page based on MutableStateFlow in VM like so:
    val properUiState = MutableStateFlow<LoginUiState>(LoginEmailUiState())
    fun setUiState(newUiState: LoginUiState){
         uiStateSealed.value = newUiState
    }
    Then produce the UiState with its updated value like so:
    val uiState = properUiState.map {
            when(it){
                is LoginEmailUiState ->  combine(
                    email, password, rememberLogin
                ) { em, pass, rememberLog ->
                    LoginEmailUiState(em, pass, rememberLog)
                }
                is ResetPasswordUiState -> email.map {
                    ResetPasswordUiState(it)
                }
                ....
            }
        }.flatMapLatest { it }.stateIn(viewModelScope, LoginUiState())
    Last thing I collect the
    uiState
    from compose and represent the proper ui based on its value like so:
    @Composable
    fun Container(loginUiState: LoginUiState){
       Card{
          when (loginUiState) {
             is LoginEmailUiState -> {
                LoginEmailContainer(loginUiState)
             }
             is ResetPasswordUiState -> {
                ResetPasswordContainer(loginUiState)
             }
             ...
          }
       }
    }
    s
    3 replies · 2 participants
  • c

    Colton Idle

    08/19/2022, 5:03 PM
    I have a launched effect that doesn't seem to trigger a nav event like 0.1% of the time during app startup. My thought is that it's just some race condition, but if anyone is familiar with compose-nav and launchedEffects wants to take a look at my scenario I'd appreciate it. Short sample code in thread
    a
    j
    +1
    21 replies · 4 participants
  • l

    Landry Norris

    08/19/2022, 6:02 PM
    Does material specifically forbid alpha in the popup for a dropdown menu? It appears that ExposedDropDownMenu does not support this, so I had to copy the source code from
    ExposedDropDownMenu
    ,
    AndroidMenu
    ,
    ExposedDropDownMenuPopup
    , and
    Menu
    and explicitly handle the case where the popup background should have alpha. Is this a bug in Compose, where I should contribute the ‘fix’, or is this expected behavior? For reference, if you set Modifier.background to a color with alpha on ExposedDropDownMenu, you can see there is always an opaque white background applied behind.
    c
    17 replies · 2 participants
  • a

    Alex Styl

    08/20/2022, 6:24 PM
    Modifier code: https://github.com/alexstyl/compose-tinder-card/blob/main/lib/src/main/java/com/alexstyl/swipeablecard/SwipableCard.kt
    2 replies · 1 participant
  • d

    dan.the.man

    08/20/2022, 9:19 PM
    If I have something like
    @Composable
    fun showList(actions:MutableSharedFlow<Action>){
        val scope = rememberCoroutineScope()
                Box(contentAlignment = Alignment.Center) {
                    Column(Modifier.clickable {
                        scope.launch { actions.emit(NewEvent())}
    This works, but if I navigate back to the page, and repeat the action, the event fires 2x, and then 3x if I navigate back etc. What am I missing here? Changing it to a method that's passed in instead of creating a lambda results in what I'd expect
    @Composable
    fun showList(actions:(Action) -> Unit){
        val scope = rememberCoroutineScope()
                Box(contentAlignment = Alignment.Center) {
                    Column(Modifier.clickable {
                       actions(NewEvent())
    ^ that works, I guess it has to do with stable?
    z
    l
    10 replies · 3 participants
  • a

    adjpd

    08/21/2022, 3:17 AM
    What's the best way to communicate values, like a position, back up the layout tree? I have mutable state in a composition local currently. Is there a better way?
    s
    12 replies · 2 participants
  • o

    Oleksandr Balan

    08/21/2022, 9:03 AM
    Sources 👇 https://github.com/oleksandrbalan/pagecurl
    s
    a
    +2
    8 replies · 5 participants
  • o

    oday

    08/21/2022, 12:48 PM
    I seem to have something misunderstood here, we’re still using Activities and Fragments yes? I mean it’s not just 1 Activity where you switch out composables to display content for example I have the MainActivity here showing either Authentication Composable or Home Composable depending on whether the user is logged in or not .. I think I should be opening the HomeActivity instead and inside set the content to Home
    a
    c
    +1
    4 replies · 4 participants
  • o

    oday

    08/21/2022, 1:58 PM
    so if I have Activity A that setContent to Authentication composable Authentication has a viewmodel, inside the viewmodel I’m calling signIn and it’s a long-running process and then a result appears, I hate uiState.value to be the user that I just fetched and so it’s a successful login where do I listen to this state so that I could setContent to a new Composable “Home”? and if I do that where will Home be loaded, in MainActivity as well yea?
    c
    6 replies · 2 participants
  • m

    Marko Novakovic

    08/21/2022, 3:39 PM
    Am using Accompanist
    Pager
    to represent calendar view. Every month is separate page. Problem I have is with selecting date. Am exposing selected date from state object. When I select new date every page of
    Pager
    recomposes,
    HorizontalPager
    content
    lambda is called again for every page, and that creates really bad UI junk. How can I avoid that?
  • j

    Jasmin Fajkic

    08/21/2022, 4:52 PM
    Is it stupid idea to create
    CompositionLocalProvider
    that provides navcontroller so that i do not need to pass navcontroller from parent down to child composable?
    f
    c
    +1
    9 replies · 4 participants
  • a

    adjpd

    08/21/2022, 10:48 PM
    If I click on a
    TextField
    at the bottom of the screen in a
    LazyColumn
    the keyboard popups up momentarily, and then quickly disappears: you can't then enter input. Is this a known issue? Code in 🧵.
    m
    z
    +1
    10 replies · 4 participants
  • z

    Zoltan Demant

    08/22/2022, 3:53 AM
    Im trying to blur some content in compose.
    Modifier.blur
    seems like the way to go, but Im also trying to support this effect all the way down to API 21. Has anyone had any success with alternative approaches?
    c
    m
    21 replies · 3 participants
  • n

    nuhkoca

    08/22/2022, 8:06 AM
    Hello, I need to set
    startDestination
    dynamically based on a flag. However,
    btAppGraph
    doesn’t recompose it after the initial value. How do I do it?
    val isManager by viewModel.isManager.collectAsStateWithLifecycle()
    
    private fun NavGraphBuilder.btAppGraph(
        appState: BTAppState,
        isManager: Boolean
    ) {
        ...
        navigation(
            route = Screen.Home.route,
            startDestination = if (isManager) HomeSections.TaskApproval.route else HomeSections.Tasks.route
        ) {
            addHomeGraph(appState)
        }
    }
    r
    1 reply · 2 participants
  • s

    Stylianos Gakis

    08/22/2022, 8:15 AM
    I don’t think such an arrangement exists by default. The closest thing I’ve done before where things are in a row, but items may take more space than others if needed is this inspired from this discussion. Maybe you can take that and adjust it for your use case
    l
    c
    +2
    10 replies · 5 participants
  • e

    efemoney

    08/22/2022, 8:23 AM
    How can I draw a background around just a couple of items in a
    Column
    ? Like my entire column content was divided into sections and I want to draw a bg behind some of those children
    c
    m
    +1
    5 replies · 4 participants
  • c

    Can Korkmaz

    08/22/2022, 9:59 AM
    Hello all, I've question regarding AndroidView update field. Assuming I put a mutableState.value lambda inside update field, and assuming I set a textListener ( say EditText) inside update, does the text listener stay intact when mutableState lamdba changes? I assume it does but not sure.
    j
    z
    3 replies · 3 participants
  • j

    jasu

    08/22/2022, 10:09 AM
    I have a LazyVerticalGrid inside Column (vertical scroll enabled) I want to have only column’s scroll but the same time don’t want to disable scroll of grid (as it’ll not report scroll action to the column) due to this, scroll is not that smooth
    z
    3 replies · 2 participants
  • a

    abbic

    08/22/2022, 12:25 PM
    hello, i have a screen with events i am refactoring from livedata to compose. previously i would handle events by having them on one livedata and doing
    viewmodel.events.observe { when (event) etc etc }
    now my instinct is to have the events be a val on the uiState like
    UiState(val event)
    and then in the composition
    SomeScreen(uiState) {
       LaunchedEffect(uiState.event) {
          when (event) etc etc
       }
    }
    but this causes a problem where in livedata you could post the same event in a row multiple times and the observer would trigger each time. i have to assume that if you copy the uiState and set the same event now the LaunchedEffect wont trigger. I can clear the event manually in the state each time, but the slight overhead makes me wonder if there's a better way to do it?
    f
    a
    +1
    6 replies · 4 participants
  • e

    Erfannj En

    08/22/2022, 1:05 PM
    Hi guys I create a simple but attractive design calculator if you like, you can take a look at it https://github.com/ErfanSn/SiliconeCalculator
  • k

    K Merle

    08/22/2022, 1:40 PM
    In
    Text
    composable, if word does not fit in the line, it goes to the next line. Is it possible to still leave the word in the same line and have that hard break of the word? Example:
    Lorem Ipsum is simply dummy text of the 
    printing and typesetting industry. Lore
    m Ipsum has been the industry's standar
    d dummy text ever since the 1500s.
    z
    r
    +2
    21 replies · 5 participants
Powered by Linen
Title
k

K Merle

08/22/2022, 1:40 PM
In
Text
composable, if word does not fit in the line, it goes to the next line. Is it possible to still leave the word in the same line and have that hard break of the word? Example:
Lorem Ipsum is simply dummy text of the 
printing and typesetting industry. Lore
m Ipsum has been the industry's standar
d dummy text ever since the 1500s.
z

Zach Klippenstein (he/him) [MOD]

08/22/2022, 1:48 PM
We’re in the process of designing a line breaking API, but as of right now i don’t believe there’s any way to get the Text composable to do this.
k

K Merle

08/22/2022, 3:32 PM
Seems like replacing white space char, with a no-line-break characters does the trick of keeping text in a same line (example above). https://en.wikipedia.org/wiki/Whitespace_character
r

Rick Regan

08/22/2022, 7:11 PM
I have been doing this and it works well. I put a “\uFEFF” after characters like space, period, and forward slash. Check out this feature request I wrote in Jan 2021 (and star if you like 😀).
a

Alex Vanyo

08/22/2022, 11:51 PM
That’s a neat trick:
val sourceText = "Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s."
val modifiedText = sourceText.toList().joinToString("\u200B")
Text(modifiedText)
r

Rick Regan

08/22/2022, 11:59 PM
If I use
" \u200B"
instead of
"\uFEFF"
in my code I don’t get the non-breaking behavior.
a

Alex Vanyo

08/23/2022, 12:04 AM
Is the space there intentional?
\uFEFF
also works for me, although the Wikipedia article says that one is deprecated?
\u2060
also works. I’m just trying all of these out for fun, not sure how supported this is or if this is a reasonable approach. There’s also
TransformedText
and
VisualTransformation
, which might be the correct thing to do for something like this
r

Rick Regan

08/23/2022, 1:01 AM
The space was part of my quick and dirty test to replace space with space+non-breaking space (I neglected to remove it before I pasted it here).
I did not know
\uFEFF
was deprecated! (Thanks.) Maybe I will switch to
\u2060
, which appears to works as well.
What’s interesting is that sometime in the last year and a half plus that I’ve been using Compose the forward slash and the period no longer cause a line break without the non-breaking space (if we weren’t playing around with it right now I never would have known). I wonder what could have changed? I have a restricted set of special characters that my
Text
uses, and at the time I experimented with all of them (a left or right parenthesis, for example, never caused a problem — and still don’t). Space, period, and forward slash were the three that I needed to insert the non-breaking space after. Now it appears only space requires it. (I don’t know that I would remove the code in my app that inserts them, just to be safe — unless I got a definitive reason why the behavior changed.)
And thanks — I will look into
TransformedText
as the better way to do this.
k

K Merle

08/23/2022, 5:10 AM
@Rick Regan Have you by any chance been adding hyphens at the end of lines? I've been experimenting yesterday, and can't make it perfect for now.
s

Siyamed

08/23/2022, 5:13 AM
I didn't understand the problem/question :/ Is the screenshot desired or non-desired output?
I don't think in conpose line breaking changed intentionally. It might be android usage and some tricks we played on staticlayout having a side effect.
k

K Merle

08/23/2022, 5:17 AM
@Siyamed Code block was a desired output.
r

Rick Regan

08/23/2022, 12:49 PM
K Merle: I have not used hyphens (they’re not part of my limited input characters).
Siyamed: The desired behavior in this case is only line-breaking forced by the end of the
Text
. The use of the non-breaking space for the few problematic symbols was how I dealt with it. Having fewer symbols to account for is better in some sense, but still I’d like to know if it’s a bug or a feature. I’ll see if I can figure out when it changed (I’m on the latest Compose and Material 3 currently, and API 33 for that matter).
s

Siyamed

08/23/2022, 2:25 PM
Got it. The need is allow break at letter boundaries instead of words.
r

Rick Regan

08/23/2022, 2:28 PM
And in my case specifically, the “words” are numeric expressions, and the “letters” are digits and symbols.
After looking into it I think it was my code that changed (
Text
width) and not line breaking behavior of forward slash and period. Sorry for the false alarm.
View count: 8