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

    Alderson Elliot

    02/12/2022, 2:03 PM
    When I jump to a new path, the viewmodel instance of the previous path does not seem to be recycled because onCleared is not called.
    i
    • 2
    • 3
  • b

    brabo-hi

    02/12/2022, 9:37 PM
    Hi all, how could we change the configuration locale ?
    val configuration = LocalConfiguration.current
    configuration.setLocale(locale)
    Doesn’t look to have any effect unless we add
    resources.updateConfiguration(configuration, resources.displayMetrics)
    but this method looks deprecated
    n
    u
    • 3
    • 6
  • s

    Sam

    02/12/2022, 10:47 PM
    Hi folks, Compose 1.1.0 can’t seem to handle ?: with null values, doesn’t generate text on null input. It works fine in 1.0.5 with Kotlin 1.5.31
    @Composable
    fun Greeting(name: String?) {
        name?.let { Text(text = "Hello $name!") } ?: Text(text = "Hello!")
    }
    🤔 1
    r
    a
    +2
    • 5
    • 20
  • j

    jasu

    02/13/2022, 2:36 PM
    How do I scroll Lazy list to 0th index when there’s new item added, updated or deleted to the list? I’ve currently LaunchedEffect with notes as key but when I come to note list screen from note detail (without creating, updating or deleting the item) it scrolls the list to 0th position regardless of data changed or not?
    NoteList(
        notes = viewmodel.notes.collectAsState().value,
        onItemClick = { noteId ->
            Log.e(TAG, "NotesListingScreen: noteId: $noteId clicked")
            onEditNote(noteId)
        }
    )
    @Composable
    fun NoteList(notes: List<Note>, onItemClick: (String) -> Unit) {
        val listState = rememberLazyListState()
    
        LaunchedEffect(key1 = notes) {  // when any item changes, scroll list to 0th index
            listState.animateScrollToItem(0)
        }
    }
    a
    • 2
    • 7
  • b

    Brian Donovan

    02/13/2022, 4:11 PM
    Hi All, I have no idea why this test is passing. Can I get some guidance on understanding what is going on please. Thanks
    @RunWith(AndroidJUnit4::class)
    class LoginTest {
    
        @get:Rule
        val composeTestRule = createAndroidComposeRule<MainActivity>()
    
        @Test
        fun logInButtonEnabledTest() {
    
            composeTestRule.setContent {
                WHApplicationTheme {
                    LoginScreen({}, {}, {})
                }
            }
    
            val email = "sampl"
            val password = "Sa"
    
            val isValidEmail: Boolean = EmailValidator.isValid(email)
            val isValidPassword: Boolean = PasswordValidator.isValid(password)
    
            if (isValidEmail && isValidPassword) {
                composeTestRule
                    .onNodeWithTag(EMAIL_TEXT_FIELD)
                    .performTextInput(email)
                composeTestRule
                    .onNodeWithTag(PASSWORD_TEXT_FIELD)
                    .performTextInput(password)
            }
    
            composeTestRule
                .onNodeWithTag(LOG_IN_BUTTON)
                .performClick()
        }
    }
    interface FormValidator {
        fun isValid(value: String): Boolean
    }
    object PasswordValidator : FormValidator {
    
        override fun isValid(value: String): Boolean {
            return value.length > 5 && !value.contains(" ")
        }
    }
    
    object EmailValidator : FormValidator {
    
        override fun isValid(value: String): Boolean {
            val emailCheck = "^[A-Za-z](.*)([@])(.+)(\\.)(.+)"
            return emailCheck.toRegex().matches(value)
        }
    }
    :thread-please: 2
    p
    • 2
    • 12
  • b

    brabo-hi

    02/13/2022, 8:07 PM
    hi all, what is the difference between
    navController.navigate("next") {
        popUpTo("current") { inclusive = true }
    }
    and
    navController.navigateUp()
    navController.navigate("next")
    i
    • 2
    • 3
  • g

    gpaligot

    02/13/2022, 8:17 PM
    Hello here! I was reading the Compose documentation about Managing states and I found this section: https://developer.android.com/jetpack/compose/state#viewmodels-source-of-truth. I’m pretty surprised about this. 1. The official recommendation is to link my ViewModel to Compose and no more emit my UiState with a StateFlow (or a LiveData)? 2. If you have a data class (here
    ExampleUiState
    ) as single source of truth for the UI and because you can’t pass a state as parameter inside a Composable (otherwise, lint error), does that means I’m forced to redraw my entire screen at each change of my state? Thanks in advance for your time! :)
    a
    s
    • 3
    • 16
  • j

    james

    02/14/2022, 4:27 AM
    is there a consensus on how video playing should be handled in a Compose-first application? is the best option to create a Composable wrapper around AndroidView & ExoPlayer?
    n
    a
    • 3
    • 2
  • p

    pavankumar

    02/14/2022, 8:24 AM
    Hi all, I trying to create a snappable widget where any user can drag a widget within its parent bounds and when user lifts his/her finger then child widget should snap to nearest corner (like to one of top-left, top-right, bottom-left, bottom-right). i wrote below code but it didn't quite achieved the goal. Help is needed to understand where i'm doing wrong. help is much appreciated.
    Code snipper in the thread.
    :thread-please: 2
    c
    • 2
    • 3
  • t

    T.Ishikawa

    02/14/2022, 12:27 PM
    https://github.com/android/compose-samples All the samples are too difficult. Are there any samples that are easier? The SwiftUI tutorial was easy and clear.
    g
    a
    c
    • 4
    • 4
  • e

    Erlan Amanatov

    02/14/2022, 12:36 PM
    Hi, I want to navigate to a new screen and clear the back stack. Am I doing it in a right way? Code in 🧵
    ➕ 1
    i
    f
    • 3
    • 7
  • j

    jasu

    02/14/2022, 1:08 PM
    How can I put image inside the TextFiled in compose? Like shown in video
    Screenrecorder-2022-02-14-18-33-41-425(0).mp4
    j
    s
    • 3
    • 10
  • b

    Bino

    02/14/2022, 2:53 PM
    (how) can i adjust the elevation color for example with a
    Card
    ?
    c
    • 2
    • 1
  • t

    theapache64

    02/14/2022, 3:11 PM
    Can anyone show me the difference between
    compositionLocal
    vs
    staticCompositionLocal
    with a code snippet and output ?
    👀 1
    r
    n
    • 3
    • 2
  • c

    Chris Fillmore

    02/14/2022, 3:42 PM
    Hey Compose team, there are many duplicate issues related to null-branching in Compose: https://issuetracker.google.com/issues/219091191 https://issuetracker.google.com/issues/198511576 https://issuetracker.google.com/issues/204600178 (there may be more) Is there an authoritative issue which you are using to track this?
    a
    • 2
    • 3
  • c

    Colton Idle

    02/14/2022, 5:08 PM
    Is my googling and cs.android.com failing me? Is there no date/time picker in compose?
    b
    m
    c
    • 4
    • 9
  • l

    Lukasz Kalnik

    02/14/2022, 5:23 PM
    public interface MutableState<T> : State<T>
    A mutable value holder where reads to the value property during the execution of a Composable function, the current RecomposeScope will be subscribed to changes of that value.
    To be honest I feel like some words are missing from this sentence...
    ➕ 2
    a
    • 2
    • 3
  • l

    Lucca Beurmann

    02/14/2022, 5:28 PM
    Hello guys, does anyone knows if there's a way to scroll the bottomsheet up when the keyboard opens so it wont cover the bottomsheet?
    Screenshare - 2022-02-14 2:27:21 PM.webm
    c
    • 2
    • 8
  • r

    Ravi

    02/14/2022, 6:18 PM
    how to reduce internal padding of tabs in
    ScrollableTabRow
    ?
    c
    • 2
    • 3
  • c

    Chris Fillmore

    02/14/2022, 8:13 PM
    Is a non-zero
    blurRadius
    required for
    Shadow
    to be visible? I am just trying to use shadow in a TextStyle. If I don’t specify a non-zero blur radius, there is no shadow. This seems unexpected. I’d expect to be able to use shadow without blur. I’m on compose
    1.2.0-alpha02
    c
    s
    n
    • 4
    • 34
  • m

    Mohan manu

    02/15/2022, 5:10 AM
    Is there a way we can customise keyboard with compose? Not able to find any blogs related to this Thanks in advance
    j
    z
    • 3
    • 7
  • y

    YASAN

    02/15/2022, 5:39 AM
    I am working on a simple multi module library but I get
    Backend Internal error: Exception during IR lowering
    on the code that worked fine on my app module.
    a
    • 2
    • 5
  • s

    Sean Proctor

    02/15/2022, 8:01 AM
    I'm encountering a bit of a change between compose 1.0 and 1.1. I believe the 1.0 behavior was correct, but maybe someone can clarify. On one screen, I have:
    @Composable
    fun ScreenXContent() {
        val focusRequester = remember { FocusRequester() }
        TextField(
            modifier = Modifier.focusRequester(focusRequester),
            ...
        )
        LaunchedEffect(Unit) {
            focusRequester.requestFocus()
            focusRequester.captureFocus()
        }
    }
    When the user navigates away from that screen: in compose 1.0, the focus is freed and can be requested by something else; in compose 1.1, the focus is not freed and all subsequent focus requests fail. Should I be using a disposable effect to free the focus?
    ➕ 1
    z
    • 2
    • 1
  • b

    Big Chungus

    02/15/2022, 9:52 AM
    Has anyone came up with an issue of having to sync compose state to some external state each time it changes on compose side? How did you tackle it?
    t
    a
    +2
    • 5
    • 13
  • a

    Archie

    02/15/2022, 10:23 AM
    Hi, Anyone worked on the new Google Maps Compose . Just wondering how to handle the touches inside the Maps Area so that it doesn’t get dropped when the map is inside a scrollable (BottomSheet, LazyColumn, LazyRow). Any ideas how to deal with this? Thanks in advance
    • 1
    • 1
  • a

    Adib Faramarzi

    02/15/2022, 11:19 AM
    Is there a way to have an
    item
    in a lazy column that fills the rest of the screen with its height? (
    .fillMaxHeight
    does not work).
    f
    z
    +2
    • 5
    • 27
  • v

    Vikas Singh

    02/15/2022, 4:34 PM
    Can we control the duration in case of spring animation while using them as animation spec ?
    c
    d
    • 3
    • 4
  • k

    K Merle

    02/15/2022, 5:55 PM
    What is the best way to prevent navigation fast double-tap opening same screen twice?
    a
    • 2
    • 2
  • j

    jcechace

    02/15/2022, 6:50 PM
    Hi. Does somebody have an experience with compose desktop being used from java? Writing new component is not an issue. We are interesting in creating desktop application with Java (educational course, java is required). Since we want to avoid Swing we are exploring other options.
    b
    • 2
    • 2
  • g

    galex

    02/15/2022, 7:25 PM
    What is the right “pattern” to access the data of an observedAsState
    StateFlow
    inside a lambda inside a
    @Composable
    ? Using
    rememberUpdatedState
    or is there anything else I should be doing instead?
    s
    • 2
    • 16
Powered by Linen
Title
g

galex

02/15/2022, 7:25 PM
What is the right “pattern” to access the data of an observedAsState
StateFlow
inside a lambda inside a
@Composable
? Using
rememberUpdatedState
or is there anything else I should be doing instead?
s

Stylianos Gakis

02/15/2022, 7:27 PM
Yeah sounds about right, if that lambda is only created once and doesn’t change on recomposition you can do that.
:tnx: 1
g

galex

02/15/2022, 7:32 PM
It is created and passed into a custom modifier applied on a
LazyColumn
s

Stylianos Gakis

02/15/2022, 7:36 PM
Yeah I was just referring how some of them also are provided keys, like the PointerInput or
LaunchedEffect
etc you can instead provide the keys that the lambda refers to. Otherwise
rememberUpdatedState
should be fine afaik.
:today-i-learned: 1
g

galex

02/15/2022, 7:55 PM
It’s kind of scary I have to say! The reference you pass as a parameter in a
Composable
is not the value you get inside a lambda in that
Composable
🤯 I think I get the recomposition idea but it’s like you have to think in 4 dimensions for what looks like a normal function!
s

Stylianos Gakis

02/15/2022, 8:03 PM
Hey I’m totally with you in general. But after a point when it “clicks” you unlock a ton of possibilities. With plenty more to learn of course 😄 Regarding the “…is not the value you get inside a lambda…” comment, what do you mean exactly? It is the same value that you have passed to the composable at least initially. It’s just that if the value is updated and the lambda isn’t (or
rememberUpdatedState
isn’t used) then it becomes “stale” in a sense. That’s what you’re referring to right?
g

galex

02/15/2022, 8:08 PM
Yes indeed, I was really surprised by this behavior
But when you think about the sequence of recompositions (4d) and that a lambda is after all just an anonymous class, it made sense and I understood I have to use
rememberUpdatedState
. I hope I’ll be getting that click soon enough 😄
That’s also what
items
is getting from
LazyList
inside
LazyColumn
which proved me that was right
But still, feels weird somehow
👍 1
s

Stylianos Gakis

02/15/2022, 8:14 PM
“That’s also what 
items
 is getting…” Are you referring to this or what? I lost you there a bit 😄
g

galex

02/15/2022, 8:14 PM
Correct
👍 1
s

Stylianos Gakis

02/15/2022, 8:15 PM
Everything feels weird, until it doesn’t 😅 That’s my way of thinking about this 😄
:true-story: 1
g

galex

02/15/2022, 8:16 PM
I think this is the point where I leave the honeymoon phase with Compose and reality starts to hit 😂
Are there any resources to learn more about things like that? I plan on getting https://leanpub.com/composeinternals but wonder if there are other resources you know about?
s

Stylianos Gakis

02/15/2022, 8:38 PM
Tbh most of the stuff I’ve learned about compose have been all the codelabs and then linger in this slack channel and read a shit ton of threads. Particularly some people stand out to me like: Ian Lake, Adam Powell, Zach Klippenstein, Andrey Kulikov, Albert Chang, Doris Liu, Alex Vanyo, Jim Sproch (and more that I am forgetting right now for sure). If you just search for stuff written just by them on this channel you’re probably gonna learn much more things than you’d imagine. I think this is how I’ve learned all the more “tricky” stuff about compose. And of course using it for hobby projects and later (luckily) for work and exploring what’s going on. I guess these two things also stand out as far as articles go are Zach, Vinay. And then honestly I’ve been very surprised at how readable a lot of the source code of compose is, so when I am using something, using the IDE to navigate inside the sources has taught me a shit ton as well. That’s all I got as far as “resources” for compose 😄
❤️ 1
:tnx: 1
g

galex

02/15/2022, 9:11 PM
Yes, the code is definitely a big help. Thanks for all of those people, I’ll check those who I don’t know yet, lots of amazing info is all over the channel that’s for sure 👍
👍 1
View count: 1