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

    Peter

    12/05/2022, 2:36 AM
    Hi, I have a simple screen using Scaffold with the topAppBar and the content. The content is just a Column with a BasicTextField and a Text below it.I want to make the content of the BasicTextField automatically scroll when typing .When I use
    setDecorFitsSystemWindows(window, false)
    setSoftInputMode(SOFT_INPUT_ADJUST_RESIZE)
    inside the activity, it works as expected .But my application contains a lot of fragment , If I setDecorFitsSystemWindows and setSoftInputMode inside the fragment it doesn't work,the text Text goes below the keyboard .I tried both Compose 1.3 and accompanist insets library. Someone already asked https://issuetracker.google.com/issues/192043120#comment15 Anyone know how to fix it.
  • t

    Tim Malseed

    12/05/2022, 3:03 AM
    It took me ages to find this ‘documentation’ on custom
    NavType
    in Jetpack Navigation. You shouldn’t have to lean on this too often, as it’s not considered good practice to pass structured data via navigation arguments if you’re using route-based navigation. Instead, it’s better to pass an identifier for your data, and then go and retrieve it from your repository - if you can. But, if your data isn’t uniquely-identifiable, or it only really exists at the UI layer, then there are times when it can be useful to serialize your structured data and pass it around. That’s where custom
    NavType
    comes in handy - and there’s a little explanation of how to do it, buried in this guide to the navigation DSL: https://developer.android.com/guide/navigation/navigation-kotlin-dsl#custom-types
    v
    1 reply · 2 participants
  • m

    Mohan manu

    12/05/2022, 3:27 AM
    while trying to run macrobenchmark test , I get this . Not able to select module is there any solution for this ? thanks in advance
    y
    r
    4 replies · 3 participants
  • d

    Daniele Segato

    12/05/2022, 9:11 AM
    Hey, there, I've seen the official example and your article here that move it to a modifier. I've also read this comment from Ralson Da Silva about what they think the API will look like. I've the say the current API looks a bit unreliable, sometimes it will autocomplete and sometimes it wont. For instance I've a form to edit user profile where I marked FirstPersonName etc that don't get autocompleted.
    b
    4 replies · 2 participants
  • d

    Daniele Segato

    12/05/2022, 9:21 AM
    Is there some news on the Compose Autofill API? I've seen this comment by Ralson Da Silva from 2 years ago (Jan 2021) but it looks like the API hasn't been released yet, and I can't find a tracking issue about it. The official example is not great and I've tried that and the variation proposed by Bryan Herbst. But they all seems to work a bit unreliably (sometimes I don't get the option to autocomplete, for example in a FirstName / LastName form field). Furthermore once I log-in I would expect the user to be asked if they wanna save the credentials (or update them) but this doesn't happen. (I believe this is called Password Smart-Lock nevermind no I don't know how this is called). How do you handle autofill with Compose (on Android)?
    c
    3 replies · 2 participants
  • k

    KamilH

    12/05/2022, 9:35 AM
    Is it possible to tell
    SnapFlingBehavior
    to snap only to specific items (positions)? I want to snap only to
    stickyHeaders
    , not any item on the list.
    d
    3 replies · 2 participants
  • d

    david.bilik

    12/05/2022, 10:52 AM
    Hello, I have a very simple layout - parent
    Box
    and a single
    Box
    as a child. I have a long press listener on the parent and normal click listener on a child. My problem is - when I long press the child, the parent long press listener is not fired. Is there any way how to achieve this without specifying the long press listener on the child as well?
    1 reply · 1 participant
  • e

    Elio Maroun

    12/05/2022, 11:00 AM
    is swipeTorefresh deprecated in jetpack compose and i should replace it with pullrefresh??
    z
    d
    8 replies · 3 participants
  • l

    Luis Daivid

    12/05/2022, 11:05 AM
    When the focus is on email or password and keyboard is shown up, I want to move the screen up and the Login button is visible, as shown in the image on the right. And I want to enable scrolling. adjustResize is applied, and setDecorFitsSystemWindows is also set to false. here is my current Login Screen composable sudo code.
    Column(
     modifier = Modifier.verticalScroll(scrollState)
    ) {
      Box(modifier = Modifier.fillMaxWidth().weight(1f) {
        LogoImage()
       }
    
       Buttons(modifier = Modifier.fillMaxSize())
    }
    I have textfields inside Buttons, but when focused, the keyboard just hides the elements. How should I implement it?
    n
    a
    +2
    8 replies · 5 participants
  • a

    AmrJyniat

    12/05/2022, 12:56 PM
    Is there a way to detect the touch offset of the original bitmap not the
    Image()
    Composable itself?
    d
    k
    6 replies · 3 participants
  • t

    theapache64

    12/05/2022, 8:07 PM
    data class Car(val name: String)
    
    @Composable
    private fun Test() {
        var car by remember { mutableStateOf(Car("Audi")) }
        var remCar = remember { car }
        LaunchedEffect(car) {
            remCar = car
        }
        println("remCar is `${remCar.name}`")
        Button(
            onClick = {
                car = Car("BMW - ${System.currentTimeMillis()}")
            }
        ) {
            Text("CHANGE CAR")
        }
    }
    Pressing
    CHANGE CAR
    button always prints
    remCar is Audi
    Why it’s not printing
    BMW
    ? 🤔
    j
    k
    11 replies · 3 participants
  • e

    eygraber

    12/05/2022, 8:30 PM
    Will the "internals" of material3 components ever be made not
    internal
    ? For example, all of the tokens, things like
    ButtonColors
    , etc... Would be helpful to have access to them in some scenarios, especially since they are read only anyways.
    f
    e
    +2
    9 replies · 5 participants
  • j

    Jaime

    12/05/2022, 10:09 PM
    Hello everyone, it is possible to reset the value of a
    rememberSwipeableState
    to leave the swipe in the initial state
    z
    2 replies · 2 participants
  • m

    mattinger

    12/05/2022, 10:14 PM
    Hello folks, So i’m building some snapshot testing with paparazzi, but i’m having trouble with snapshotting dialogs. I assume it’s because they appear asynchronously.
    private fun snapshot(content: @Composable () -> Unit) {
            paparazzi.snapshot {
                XfinityTheme {
                    Surface {
                        content()
                    }
                }
            }
        }
    This ends up screenshotting the screen where the dialog will be over, but not the actual dialog. Not sure if there’s a way to have paparazzi delay the snapshot or not.
    a
    4 replies · 2 participants
  • z

    Zach

    12/05/2022, 11:04 PM
    Howdy. I am attempting to implement jetpack navigation within my compose-only single activity app. Right now I have normal navigation working but I am attempting to work with back navigation and
    popBackStack
    on a screen with a text field. For some reason on back press, either via the nav bar back button or an onscreen back button calling
    popBackStack
    , the screen kind of just flashes and then the keyboard flashes, but it doesn’t go to the previous composable. If I spam the back button, it does eventually return to the previous screen. How do I get around this and have just 1 press of back button go to the previous screen without using
    navigate()
    ?
    m
    4 replies · 2 participants
  • s

    Sam Stone

    12/06/2022, 5:35 AM
    Great podcast:

    https://www.youtube.com/watch?v=R2HAxIYhcBE▾

  • n

    Noop

    12/06/2022, 6:48 AM
    I use rememberLauncherForActivityResult
    rememberLauncherForActivityResult(
        contract = ActivityResultContracts.GetMultipleContents()
    )
    I got below style uri, but I want absolute path, How do I get?
    <content://com.android.providers.media.documents/document/image%3A1000080935>
    c
    1 reply · 2 participants
  • s

    Slackbot

    12/06/2022, 9:06 AM
    This message was deleted.
  • m

    Mikołaj Kąkol

    12/06/2022, 9:36 AM
    hello, more internal stuff question. Is there way to force redraw
    LayoutNode
    ? My usecase is that drawing params (shader) has change but compose don't know about that. So I would like to force a redraw on next frame a composable function.
    z
    s
    +1
    30 replies · 4 participants
  • t

    Tower Guidev2

    12/06/2022, 12:01 PM
    Hi is there an online generator for compose theme Typography in the same way theres one for colour themes? i have switched from using default Roboto to my organisaions preferred font and now all my applications text is too small. all i changed was the font though and still kept the sizes/weights etc that were being set for Roboto
    p
    2 replies · 2 participants
  • m

    Maciej S

    12/06/2022, 3:56 PM
    Hey people, sorry if this is off-topic. Did anyone have a chance to read this book yet? Didn’t see too many opinions online so far but it looks interesting, would be curious to hear from people that read it.
    j
    d
    +2
    11 replies · 5 participants
  • d

    Daniele Segato

    12/06/2022, 5:33 PM
    Hi, I've a Box with header / footer and a scrollable content that can cover header and footer. The scrollable content is blocking clicks inside header and footer. What are my options?
    Box(Modifier.fillMaxWidth) {
      Header()
      Footer(Modifier.align(Alignement.BottomCenter))
      Main(
        modifier = Modifier.fillMaxWidth()
            .verticalScroll(state)
            .padding(headerFooterPadding)
      )
    }
    Is it intended for the scrollable container to block clicks happening in Header and Footer? What are my options?
    o
    c
    +1
    31 replies · 4 participants
  • s

    Sebastian Kürten

    12/06/2022, 5:34 PM
    I've seen that compose-richtext is very experimental and undermaintained, I'm still wondering if anyone managed to make markdown rendered into a richtext and have links clickable while text being selectable?
    j
    h
    6 replies · 3 participants
  • s

    Sebastian Kürten

    12/06/2022, 5:36 PM
    Also, is there a more stable alternative to compose-richtext?
  • z

    Zach

    12/06/2022, 7:04 PM
    Does
    FocusRequester.createRefs()
    still require using
    remember
    inside of a composable? Curious how to use this API
    c
    1 reply · 2 participants
  • k

    KotlinLeaner

    12/06/2022, 8:30 PM
    I have a 3 Column. In 1st Column of components are 2nd and 3rd Column. In 2nd Column there are so many components inside that. In last 3rd Column I have a few items and I am sticking at the bottom of screen. I have done without any problem . In smaller screen item is going behind, so my supervisor mention that all item will automatically scroll of 2nd Column which is clearly above of 3rd Column.
    k
    m
    +1
    33 replies · 4 participants
  • e

    Erlan Amanatov

    12/07/2022, 4:51 AM
    Hi, I'm looking into source code of
    Checkbox
    and
    FilterChip
    default colors. So for
    Checkbox
    colors are implemented as
    object CheckboxDefaults {
    
    	fun colors(..) : CheckboxColors {
    		return remember (...) { DefaultCheckboxColors(...) }
    	}
    }
    and for
    FilterChip
    default colors are implemented as
    object ChipDefaults {
    	fun filterChipColors(...) : SelectableChipColors {
    		return DefaultSelectableChipColors(...)
    	}
    }
    My question is: Why was
    remember
    used in one of the cases and not in the other one?
    z
    l
    4 replies · 3 participants
  • z

    Zaki Shaikh

    12/07/2022, 5:53 AM
    Hello everyone I am using per-app language preference to change my app's language it is working but I want to listen to configuration change in my composable but it doesn't work. Code in thread.
    2 replies · 1 participant
  • o

    oday

    12/07/2022, 9:31 AM
    so a change that will trigger recomposition must be a change as .value on a Flow
    c
    4 replies · 2 participants
  • j

    julioromano

    12/07/2022, 10:19 AM
    I was looking at @Ian Lake’s

    Type safe, multi-module best practices with Navigation Compose▾

    video and was trying to apply the pattern suggested in it to an app of mine. I’ve run in a situation that seems to break the pattern proposed in the video as soon as I had to do “conditional navigation”. 🧵
    p
    i
    +2
    15 replies · 5 participants
Powered by Linen
Title
j

julioromano

12/07/2022, 10:19 AM
I was looking at @Ian Lake’s

Type safe, multi-module best practices with Navigation Compose▾

video and was trying to apply the pattern suggested in it to an app of mine. I’ve run in a situation that seems to break the pattern proposed in the video as soon as I had to do “conditional navigation”. 🧵
Example of conditional navigation: - user taps logout button. - logout business logic runs. - if logout logic fails then navigate to an alert dialog. - if logout logic succeeds then empty the back stack and navigate to the welcome screen. The problem is that business logic runs in the
ViewModel
but navigation actions must be invoked on the
NavController
object which is inside the composition in the
Activity
. Since the lifecycle of the
Activity
is shorter than that of the
ViewModel
we can’t pass references to functions such as
NavController.popUpToWelcomeScreen()
from the
Activity
to the
ViewModel
(besides the potential of memory leaks, we’ll loose the reference to the function any time the activity is recreated). How to properly encapsulate conditional navigation using the pattern proposed in the video?
p

Pablichjenkov

12/07/2022, 2:44 PM
You set an ObservableState/ReactiveState in the ViewModel that your composable function subscribe to observe changes and react accordingly. Sort of:
@Composable
fun LogoutScreen(accountViewModel: AccountViewModel) {
  val loginStatus by accountViewModel.loginStatus.collectAsState()
  when(loginStatus) {
    LogIn -> { paintLogoutUI() }
    LogOut -> { navController.navigate("WelcomePage") }
  }
}
You don’t pass a reference from anywhere to the ViewModel, so the ViewModel invoke/callback later on, instead invert the flow. You request execution to the ViewModel and listen for the result of the execution. The ViewModel doesn;t know about its client, doesn’t call functions in its clients
i

Ian Lake

12/07/2022, 4:18 PM
See https://manuelvivo.dev/viewmodel-events-antipatterns
c

Colton Idle

12/07/2022, 6:35 PM
I've been in this situation before, and basically the solution here is that your logout failed and logout succeeded code flows should not trigger a logout failed event or a logout succeeded event. instead they should update some state that you observe in your composable. and then your composable reacts to that state. pretty much what the people above me said. checkout these docs too: https://developer.android.com/topic/architecture/ui-layer/events#handle-viewmodel-events
j

julioromano

12/12/2022, 3:21 PM
The proposed pattern works, thanks! It is indeed a valid solution but, from a purely architectural PoV, wouldn’t it be all leaner if the
NavHost
would allow its state to be hoisted so that we could directly manipulate it? After all isn’t Jetpack Compose about manipulating hoisted state to trigger updates to the UI instead of having to manually change a `View`’s internal state by calling its setters? Every time I do a
navController.navigate()
I feel like I’m doing something like
textView.setText()
.
i

Ian Lake

12/12/2022, 4:06 PM
NavController is already the hoisted state of the NavHost.
navigate
is just how you update the state of the NavController, just like how you call
open
or
close
on a
DrawerState
A NavController is indeed tied to the composition lifecycle and can't be hoisted into a ViewModel, that is true though. There are quite a few composition state holders that can't be hoisted out of composition safety though - ScrollState looks like it can be hoisted, but any attempt to change the state from a ViewModel actually just crashes..
p

Pablichjenkov

12/12/2022, 7:13 PM
Any rule for that Ian? - for determining if a State has to live within the composition lifecycle. I bet is usually state containing layout/drawing information about the composable itself? It is very tempting to have a reference of the navController out of the composable tree.
i

Ian Lake

12/12/2022, 8:09 PM
In this case, you'll leak the whole activity and every Navigator (which also has hard references to other things in composition), so that should show up right away when you use LeakCanary (and won't work either)
p

Pablichjenkov

12/12/2022, 9:07 PM
I see, yeah that’s another point to consider, leakage, ok
j

julioromano

12/13/2022, 7:52 AM
There are quite a few composition state holders that can’t be hoisted out of composition safety though - ScrollState looks like it can be hoisted, but any attempt to change the state from a ViewModel actually just crashes..
This opens the pandora’s box of architectural opinions: Should a given composable’s state be manageable by the ViewModel/BusinessLogic or should it be exclusive to the UI layer? I don’t think there’s a definitive answer for this. Take
ScrollState
for instance, in most cases most people would be okay with it being exclusive to the UI layer, so that the business logic can be agnostic about it and the UI will transparently take care of restoring the scroll position of a list. But things change as soon as the business requirements say that the list must be programmatically scrolled to a certain position whenever a certain business operation has been completed. In this case we would like for the
ScrollState
to be hoisted to our ViewModel/BusinessLogic to better control it. So maybe it boils down to a matter of balancing “how complicated is it to make a certain state work out of the composition” with “how useful is it to actually be able to hoist a certain state out of the composition”. IMHO (just my 2 cents that are worth much less than that 🙂 ) for
ScrollState
the usefulness would be minimal, but for
NavHost
I’d say quite the opposite.
c

Colton Idle

12/13/2022, 9:08 AM
woah. thanks for the info Ian
NavController is already the hoisted state of the NavHost.
navigate
is just how you update the state of the NavController, just like how you call
open
or
close
on a
DrawerState
🤯 @Manuel Vivo i guess this also goes hand in hand with how we talked about the fact that you can't actually hoist the state of a bottom sheet into a ViewModel
m

Manuel Vivo

12/13/2022, 11:47 AM
We added more info about that topic @Colton Idle 🙂 you can hoist it there but you gotta be careful. We added that caveat to the docs as well: https://developer.android.com/jetpack/compose/state-hoisting#caveat
j

julioromano

12/13/2022, 12:25 PM
It doesn’t seem that
NavHost
falls in that caveat’s topic though,
navController.navigate()
is not suspending.
p

Pablichjenkov

12/13/2022, 2:03 PM
An open Pandora box 😁 funny, but I prefer the Android freedom over other platforms that force you to do stuff one unique way. The Android team just "recommend" stuff 🙂
View count: 8