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

    Kulwinder Singh

    01/24/2022, 8:51 AM
    Hi, I’m unable to position Popup
    DropdownMenu
    using
    offset
    property. I have tried to use
    Modifier.onGloballyPositioned{}
    but not getting expected results, How i should position Popup menu at depending on other view ?
    f
    t
    z
    • 4
    • 5
  • m

    myanmarking

    01/24/2022, 10:45 AM
    I noticed a strange issue on textField with KeyboardType.Number. when i click to enter text, the keyboard shows right. But when i request focus manually, the keyboard shows an extra bar with undesirable inputs. Like this:
    z
    • 2
    • 3
  • j

    julioromano

    01/24/2022, 3:01 PM
    Does
    derivedStateOf
    track reads of
    State
    objects at run time or compile time (or perhaps I should say dynamically or statically)? 🧵
    a
    n
    +2
    • 5
    • 25
  • m

    marios proto

    01/24/2022, 3:32 PM
    Hi 👋 , I have an accessibility issue with Compose, if anyone could help please. Let’s say I have a
    Row { 
    Text()
    Button()
    }
    and on using the largest font in the device I want to have them both visible, text and button, and if needed to break the content in two lines, is it even possible? So far, I only managed to have them both visible with ellipse of their text
    s
    • 2
    • 2
  • m

    myanmarking

    01/24/2022, 4:04 PM
    Is it possible to align text inside Row, vertically and by baseline ?
    ➕ 1
    c
    • 2
    • 8
  • f

    Filip Stanis

    01/24/2022, 6:37 PM
    Hey all! Is there an advantage to passing a lambda vs wrapping it? E.g.
    @Composable
    fun MyButton(onClick: () -> Unit) {
        Button(onClick = onClick) { ... }
    }
    // vs
    @Composable
    fun MyButton(onClick: () -> Unit) {
        Button(onClick = { onClick() } { ... }
    }
    (this is probably a more general kotlin question, but I see both patterns in compose code and it's unclear if one is better / worse than the other)
    z
    a
    +2
    • 5
    • 15
  • b

    Billy Newman

    01/24/2022, 6:44 PM
    Hello all. I have a question about button text color in regards to the primary color. Should the text color automatically change from black to white based on the buttons primary color? Example in reply.
    c
    l
    • 3
    • 4
  • m

    myanmarking

    01/24/2022, 6:49 PM
    what would be the correct KeyboardType for number only (not decimal). NumberPassword or Phone ?
    b
    • 2
    • 7
  • a

    Arun Joseph

    01/24/2022, 7:39 PM
    Can we somehow simplify this?
    if (enabled) {
                        Icon(
                            painter = painterResource(id = iconId),
                            contentDescription = null,
                            modifier = Modifier.size(32.dp),
                            tint = iconColor
                        )
                    } else {
                        Icon(
                            painter = painterResource(id = iconId),
                            contentDescription = null,
                            modifier = Modifier.size(32.dp),
                        )
                    }
    I am trying something along these lines
    Icon(
                            painter = painterResource(id = iconId),
                            contentDescription = null,
                            modifier = Modifier.size(32.dp),
                            tint = if (enabled) iconColor else ...
                        )
    m
    j
    • 3
    • 6
  • h

    henrikhorbovyi

    01/25/2022, 12:48 AM
    Hello, everyone 🙂 What's the best way to implement a nested scroll screen on Compose? My hierarchy is:
    MyScreen:
        Column():
            Text("Nice Title")
            LazyVerticalGrid:
                items(n) { MyItem() }
    ➕ 2
    t
    r
    • 3
    • 10
  • i

    iona bartishvili

    01/25/2022, 7:35 AM
    Hey, everyone. i have a question regarding the Snackbar in androidx.compose.material. i have an action text which shows up at the start of the snackbar view. Instead, i want this text to show up at the end of the snackbar view. can enyone tell me what i am missing ?
    n
    • 2
    • 2
  • m

    Marcin Środa

    01/25/2022, 9:00 AM
    Hey, does anyone implemented custom emoji picker in Compose?
    h
    • 2
    • 4
  • m

    Matthew Laser

    01/25/2022, 3:22 PM
    hey all - is the best practice when using compose to still use fragments, or are the composable functions intended to just live in an activity without that layer
    i
    m
    +2
    • 5
    • 8
  • j

    Jan

    01/25/2022, 5:35 PM
    I have a question for ViewModel. I know that I can just use something like that for getting the newest entries:
    class AbsenceViewModel : ViewModel() {
    
        val absencesFlow = MutableStateFlow<List<DBItem>>(emptyList())
    
        init {
            viewModelScope.launch {
                kotlin.runCatching {
                    AbsenceRepository.getAll()
                }.onSuccess {
                    absencesFlow.value = it.toList()
                }.onFailure {
                    absencesFlow.value = emptyList()
                }
            }
        }
    
    }
    but whats when I modify the entries on the rest api? Or if I want to modify them locally?
    • 1
    • 2
  • f

    Filip Stanis

    01/25/2022, 6:32 PM
    I'm wrapping a multiline
    TextField
    in a scrollable column and I realized that by default the column won't scroll to the bottom if it goes off screen. Attached gif of what I mean - the
    TextField
    grows until it reached the height of the
    Column
    , then it goes off-screen - but I can still scroll to it. Can I make the scroll position follow focus? I'd expected that to happen by default, maybe I'm doing something wrong?
    val scrollState by remember { mutableStateOf(ScrollState(0)) }
    var value by remember { mutableStateOf("") }
    Column(
        Modifier
            .padding(8.dp)
            .height(60.dp)
            .verticalScroll(scrollState)
    ) {
        BasicTextField(
            modifier = Modifier
                .fillMaxWidth()
                .background(Color.White)
                .padding(8.dp),
            value = value,
            onValueChange = { value = it }
        )
    }
    • 1
    • 1
  • l

    Lucien Guimaraes

    01/25/2022, 7:34 PM
    Is possible to have a navigation between Standard sheets? ModalBottomSheetLayout from Accompanist only works for Modal sheets. And even by setting the
    scrimColor
    parameter to
    Color.Unspecified
    , to make sheets looks like standard sheets, we don't have control over the peekHeight.
    i
    c
    • 3
    • 6
  • v

    vgonda

    01/25/2022, 8:29 PM
    Can you use
    AndroidComposeTestRule
    for end-to-end tests that work through multiple activities?
    👀 1
    d
    • 2
    • 4
  • m

    myanmarking

    01/25/2022, 8:58 PM
    What is the different between this two. And what purpose each ones serves:
    LazyColumn{
    item(item, {item.key}){
    MyItem()
    }
    }
    LazyColumn{
    item(item){
    key(item.key){
    MyItem()
    }
    }
    }
    a
    • 2
    • 1
  • m

    Marko Novakovic

    01/25/2022, 9:49 PM
    am a bit confused. when using
    AnimatedNavHost
    from
    Accompanist
    composable(...) {...}
    is recomposed multiple times due to animation. so every value inside the
    composable
    lambda should be `remember`ed right? for extracting arguments it doesn't really matter because they are static but with
    remember
    we avoid constant extraction of arguments? what about
    hiltViewModel
    inside
    composable
    lambda? is it ok to do something like this:
    composable(
        route = Screen.Checkout.route,
        arguments = ...,
        enterTransition = { forwardTransitionSharedAxisXIn() },
        exitTransition = { backwardsTransitionSharedAxisXOut() },
    ) { backStackEntry ->
        val someArg = remember { backStackEntry.arguments!!.getFloat("arg") }
        val viewModel = hiltViewModel<CheckoutViewModel>(backStackEntry)
        CheckoutScreen(
            ...
            navigateUp = navController::popBackStack,
        )
    }
    ?
    i
    • 2
    • 4
  • a

    Aditya Murthy

    01/25/2022, 11:22 PM
    I have container that houses a few composable buttons in it. Is there a way to make the contents of the container visible, without making them clickable? I know I can individually add logic to the buttons and make them un-clickable, but I wanted to check if I can control this at a higher level (Similar to a glass panel - you can still see everything behind the panel, but can't interact with it)
    c
    a
    • 3
    • 6
  • m

    marios proto

    01/26/2022, 12:02 AM
    👋 Is there any way to have a
    Lazycolumn
    inside an
    AbstractComposeView
    , contained in a ScrollView(in an xml layout)? it seems there is no way around the exception of
    Nesting scrollable in the same direction layouts like LazyColumn and Column(Modifier.verticalScroll()) is not allowed.
    👀 1
    h
    a
    • 3
    • 3
  • j

    jannis

    01/26/2022, 9:56 AM
    Is there a good way to detect that the user pasted something via the context menu instead of writing in a
    TextField
    ?
    a
    • 2
    • 1
  • j

    Jan Skrasek

    01/26/2022, 10:31 AM
    I have some Composable accepting an icon and I wanna be more strict about the accepted type. What is the proper way? •
    Painter
    - seems to have mutability issues and I didn't found any copy/clone method. •
    @Composable () -> Unit
    - for custom rendering icon is too benevolent for me •
    @Composable () -> Painter
    - is what I'm ended up. Is it the correct solution?
    h
    z
    • 3
    • 2
  • a

    Ashu

    01/26/2022, 2:13 PM
    How can I intercept click events on child composables? I have a form where I am trying to show a toast to the user if the form is not editable. So clicking on form elements which normally would trigger some form action needs to be intercepted and instead I want to show a toast to the user.
    s
    • 2
    • 2
  • t

    Teck Wei Chan

    01/26/2022, 2:25 PM
    Okay, I'm not really sure what's going on... But
    var show by rememberSaveable { mutableStateOf(false) }
    causes
    ClassCastException: Boolean can't be cast to String
    on configuration change.
    remember { ... }
    works fine, of course. afaik,
    rememberSaveable
    uses bundle to save values so it should be fine, no?
    d
    c
    z
    • 4
    • 5
  • g

    Guilherme Delgado

    01/26/2022, 3:01 PM
    Is there any
    animateItemPlacement
    implementation (or alternative) for
    LazyGridScope
    ? 🤔
    m
    • 2
    • 1
  • c

    Colton Idle

    01/26/2022, 4:18 PM
    I have this in my composable screen, but ideally I'd like to control this state from my vm. Is that frowned upon or is it normal to move these
    remember*State
    calls to my VM? Example:
    val bottomSheetScaffoldState = rememberBottomSheetScaffoldState(bottomSheetState = BottomSheetState(BottomSheetValue.Collapsed))
    f
    f
    • 3
    • 7
  • m

    myanmarking

    01/26/2022, 7:28 PM
    I don’t understand why the image is not loading with coil. Can some1 spot the mistake? It’s a valid url
    a
    • 2
    • 6
  • s

    Simon Stahl

    01/26/2022, 7:48 PM
    Anyone knows if there is something in the works to support previews with viewmodels?
    t
    c
    • 3
    • 7
  • f

    Filip Wiesner

    01/26/2022, 7:50 PM
    Another snapshot question: When I have snapshot inside snapshot (nested snapshot) and I change some state twice inside the inner snapshot and apply, shouldn't the outer snapshot see only one write? I am seeing the write observer being triggered twice 🤔 Code in a thread :thread-please:
    a
    c
    • 3
    • 8
Powered by Linen
Title
f

Filip Wiesner

01/26/2022, 7:50 PM
Another snapshot question: When I have snapshot inside snapshot (nested snapshot) and I change some state twice inside the inner snapshot and apply, shouldn't the outer snapshot see only one write? I am seeing the write observer being triggered twice 🤔 Code in a thread :thread-please:
val writeObserver: (Any) -> Unit = { writtenState ->
    val s = writtenState as MutableState<String>
    println("State was changed to ${s.value}")
}


var state by mutableStateOf("")

val snap = Snapshot.takeMutableSnapshot(writeObserver = writeObserver)
snap.enter {
    state = "A"
    Snapshot.withMutableSnapshot {
        state = "B"
        state = "C"
    }
}

snap.apply()
snap.dispose()

//The Result is:
//  State was changed to A
//  State was changed to B
//  State was changed to C
The documentation (of
takeNestedMutableSnapshot
which is called by
takeMutableSnapshot
) clearly states that this shouldn't be the case:
Take a mutable snapshot of the state values in this snapshot. Entering this snapshot by calling enter allows state objects to be modified that are not visible to the this, the parent snapshot, until the apply is called.
What am I missing?
Ok, this works:
val snap = Snapshot.takeMutableSnapshot()
snap.enter {
    Snapshot.observe(writeObserver = writeObserver) {
        state = "A"

        val nestedSnap = snap.takeNestedMutableSnapshot()
        nestedSnap.enter {
            state = "B"
            state = "C"
        }
        nestedSnap.apply()
        nestedSnap.dispose()
    }
}
snap.apply()
snap.dispose()

//The Result is:
//  State was changed to A
But frankly I have no idea why. And it also doesn't work like I thought it will. It observes only the "A" change but not the "C" change which kinda makes sense.
Maybe the
currentSnapshot()
function returns the global snapshot and not the
snap
like I thought it will. So when I create snapshot inside another, they are both in GlobalSnapshot. But even then it doesn't make sense to me 😞
@Adam Powell I am really sorry for the ping but I am out of ideas. What am I getting wrong?
a

Adam Powell

02/02/2022, 4:49 PM
I would need to sit down and read this more closely than I can at the moment, @Chuck Jazdzewski [G] might get to it before I do
c

Chuck Jazdzewski [G]

02/02/2022, 5:11 PM
The write observer is not an apply observer. The read and write observers observe all reads and writes, respectively, at the time they are performed and parent snapshots observe all reads and writes of the child snapshots at the time they are performed. The intent of write observers is to notify the observe when a change might be arriving, such as the
GlobalSnapshotManager
does, so it can schedule some action. It is not intended to be used as apply observer which will only send a notification at most once for each change.
objects to be modified that are not visible to the this, the parent snapshot, until the apply is called.
This is referring to the values of the objects not the notification sent to the read and write observers. Changing the value of
state
in
nestedSnap
is not visible in
snap
until
nestedSnap
is applied.
View count: 3