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

    adjpd

    09/22/2021, 10:42 PM
    Modifier.scrollable
    and
    Modifier.horizontalScroll
    clip their children differently. Is this a bug? Code in 🧵.
    i
    a
    • 3
    • 13
  • a

    adjpd

    09/22/2021, 11:25 PM
    Where should I report broken documentation links?
    c
    • 2
    • 1
  • n

    Nathan Castlehow

    09/23/2021, 4:11 AM
    Hey, apologies if this is a bit of a boring question. I’ve had a poke at the issue tracker to no avail, I was wondering what tickets / source files should I be watching to see if / when automatic scroll to view type functionality becomes available for lazy layouts? Creating a tv app at the moment (slightly early I know). Would be thinking similar behaviour to the non lazy layouts to allow me to go down the page between the lazy list items and have them scroll into view.
    a
    • 2
    • 4
  • t

    Tolriq

    09/23/2021, 7:52 AM
    I'm trying to understand recomposition and large state object and it seems that if I collect a StateFlow with :
    val state by viewModel.state.collectAsState()
    Then all the child of that component are recomposed if any child use any property of the state. What would be a proper way to collect a large state but only update sub component on some part of the state. For example the state contains a media item and a progress state. when only the progress change I only want to recompose the progress bar and not all components that display the media information.
    z
    • 2
    • 18
  • c

    Christoffer Niska

    09/23/2021, 8:34 AM
    Hello all, 👋🏻 My name is Christoffer and I am a fullstack developer from Helsinki, Finland. I am currently working on an Android app that uses Compose. I have worked with declarative UIs a lot in the past (mainly React/React Native) and I have loved it, Compose is no exception to this. During the past weeks I have worked my way through all of the Compose related material on https://developer.android.com/ and browsed through the sample apps, but I am still struggling to find a good solution for handling UI state changes in my composables. The best example that I have found so far is the Jetnews sample app that uses MutableStateFlow for its UI state. At the moment I am working on the Login screen in our app and I need to react to the following: • I want to hide the keyboard and show a loading state when the user submits the form • I want to show an error and focus the first field if an error occurred • I want to navigate to the overview page if authentication is successful Currently, I have a ViewModel with a MutableStateFlow that is exposed as a StateFlow to the composable. In the composable I consume the state with collectAsState. To detect changes I use remember to store the previous state and compare it to the current state, and execute logic when the state changes using an if and a when statement. I feel that there should be a better way to do this, e.g. subscribe to the UI state, filter out distinct changes to the state, and execute logic when the state changes. Does anyone have any good resources that I can read or view to learn how to properly handle state changes in composable? Thank you in advance. Link to Gist: https://gist.github.com/crisu83/3f3fb978f59ddbda7d74d7a329a4bd44
    🧵 2
    t
    c
    +2
    • 5
    • 14
  • n

    Napa Ram

    09/23/2021, 9:08 AM
    HI Team i am facing issue while creating a drop down menu. 1. i want to align text from right side as per below image 2. how to add scrollbar to the dropdown
    • 1
    • 1
  • t

    theapache64

    09/23/2021, 9:45 AM
    ❓ What’s the difference between 
    @Stable
     and 
    @StableMarker
    ? 🤔🧵
    c
    y
    • 3
    • 3
  • n

    Napa Ram

    09/23/2021, 11:44 AM
    Hi All is this good to keep all composable method inside class and let them override composable method if they want to by extending class
    a
    • 2
    • 1
  • v

    Vsevolod Kaganovych

    09/23/2021, 2:15 PM
    Do we have a way to inject parameters from arguments inside viewmodel from compose navigation with hilt? For example, I have parameter, that I pass and I have
    val viewmodel: ViewModel = hiltViewModel()
    How do I pass a parameter from arguments to constructor?
    j
    • 2
    • 2
  • d

    Diego Rodriguez

    09/23/2021, 3:00 PM
    Hi everyone! Sorry if this was already discussed, I'm new here. I have a custom android view and I'm using
    AndroidView
    to compose it. Now I need to access that view when the user presses a button to get its state. To simplify, I have an EditText and I need its content when the user presses 'Next'. How Can I access the state of that view? I know I could build it from scratch using compose, but I have a lot of custom views and plan to migrate them progressively.
    t
    • 2
    • 2
  • z

    Zoltan Demant

    09/23/2021, 3:24 PM
    If a
    Column
    contains two composables with varying height, how can I make sure the bottom one is always visible, despite the top one sometimes using
    Modifier.fillMaxHeight
    ?
    c
    a
    • 3
    • 5
  • n

    nglauber

    09/23/2021, 3:56 PM
    I have a
    LazyColumn
    with multiple `item`/`ìtems`. When I navigate to a “detail” screen, and then go back, the scroll position is lost. Is this the right bug to follow? https://issuetracker.google.com/issues/179397301
    a
    • 2
    • 8
  • n

    Napa Ram

    09/23/2021, 4:35 PM
    Hi Everyone, can anyone give me any example. how to create UI for Tablet specific in compose and What are the things i should keep in mind while creating UI for tablet
    n
    a
    • 3
    • 7
  • a

    Ahmed Sellami

    09/23/2021, 4:48 PM
    How can I achieve something like Modifier.elevation(showShadow = false)? I am implementing drag to reorder feature in a list, and I want to make the item on top of others when it is dragged.
    a
    • 2
    • 2
  • t

    Tash

    09/23/2021, 6:41 PM
    Hi all! Curious if anyone has dealt with building a design system in Compose, where the design system specifies many tokens (in the 100s)… The Jetsnack approach for defining Colors, Type, etc as classes with
    MutableState
    fields might not be scalable for a system with a lot of tokens. Thinking about possible approaches, esp ones that minimize recompositions as much as possible, such as maintaining a
    Map<Token, MutableState<Color>>
    etc…Would love some suggestions on this 🙏🏼
    v
    • 2
    • 4
  • m

    Marko Novakovic

    09/23/2021, 8:13 PM
    is there a way to animate
    FontWeight
    and
    FontSize
    ?
    e
    • 2
    • 5
  • a

    Akram Bensalem

    09/23/2021, 8:58 PM
    Hello! I have an issue that I want to switch to dark mode without using
    AppCompatDelegate.setDefaultNightMode(true)
    Because when I use that it's blank and I loose the state of some variables. But when using just Theme:
    val autColors = if (isSystemInDarkTheme()) DarkColorPalette else LightColorPalette
    It works great like I want just with one issue is when navigate from screen to another a white flash apears !!! this happen just with Dark mode. So anyone here was able to solve this issue ?
    t
    • 2
    • 3
  • e

    Eric Boggs

    09/23/2021, 9:59 PM
    Hey all - I've got an issue that I don't fully understand with MutableStateFlow not triggering a re-compose when a deeply nested value changes. Basically, radio buttons set their value based on their status in state. When one is pressed, it toggles its value in state. Ideally, this should trigger a recompose but it doesn't. Made a little repro here if someone has any thoughts. https://github.com/boggsey/stateflow-test
    z
    a
    • 3
    • 9
  • t

    theapache64

    09/24/2021, 3:58 AM
    [✅ RESOLVED] Clarification: I was just going through the the official API guideline, and there are some areas I’d be like to get clarification. 🧵 cc @Adam Powell
    a
    s
    • 3
    • 5
  • r

    rajesh

    09/24/2021, 4:26 AM
    Which (and how) animation api should be used to rotate a icon button (as shown below for camera flipping)
    VID-20210924-WA0000.mp4
    t
    • 2
    • 1
  • k

    K Merle

    09/24/2021, 5:30 AM
    It seems that due to animation during orientation change (from portrait to landscape)
    focusRequester.requestFocus()
    does not open the keyboard. Adding a 300ms delay does solve the issue it seems. Anyone faces the same issue and were you able to solve it better? I'd like to avoid delay.
    LaunchedEffect(Unit) {
        delay(300)
        focusRequester.requestFocus()
    }
    s
    • 2
    • 2
  • e

    Erlan Amanatov

    09/24/2021, 6:00 AM
    How can I animate the height of a composable to 0.dp on some event, something like
    shrinkVertically()
    ExitTransition in
    AnimatedVisibility
    ?
    d
    • 2
    • 1
  • i

    iamthevoid

    09/24/2021, 7:23 AM
    don’t you think that there needs something like firebase-bom for compose and accompanist?
    👍 9
    👍🏾 1
    c
    a
    • 3
    • 3
  • a

    athos

    09/24/2021, 10:18 AM
    I am getting a fatal exception in
    painterResource()
    in a composable where the id for the resource is provided as an argument for the composable and ultimately got from a view model's
    StateFlow
    property. The id can be one of several dozen, and it always fails on the same one but only if it comes after another specific one, otherwise everything is fine, maybe I am misusing the API somehow? More details in the thread.
    a
    n
    • 3
    • 13
  • m

    myanmarking

    09/24/2021, 10:56 AM
    if i want to retrieve a themed color in a composable, not coming from the theme, but with corresponding dark/light variant, is this the correct approach for colors:
    val error: Color
        @Composable get() = if(isSystemInDarkTheme()) error else error2
    d
    a
    • 3
    • 2
  • z

    Zoltan Demant

    09/24/2021, 11:36 AM
    Is it possible to make the label of a TextField float to the top even though the input is empty? 😒miling_face_with_tear:
    • 1
    • 1
  • a

    Akram Bensalem

    09/24/2021, 11:43 AM
    How to delay SplashScreen Core API until we read some data from DataStore in Jetpack compose ?? in the official they use this How to implement the same thing with Jetpack compose ?
    👀 3
    f
    • 2
    • 1
  • e

    escodro

    09/24/2021, 12:09 PM
    Hello, everyone! 👋 Is it possible to use
    AlertDialog
    with Jetpack Compose Navigation as a destination? When using
    dialog()
    , if i add a
    AlertDialog
    in the Composable, the user have to double click outside to dismiss both. And if I don’t use the
    AlertDialog
    then I will have to implement the title, text and buttons to have the same look and feel. Do you have any suggestions? Thanks a lot! ❤️
    i
    • 2
    • 1
  • m

    Mini

    09/24/2021, 12:27 PM
    With this code
    class SomeClass{
        val list : SnapshotStateList<Int> = mutableStateListOf(5)
    }
    val someClass = SomeClass()
    snapshotFlow { someClass.list }.onEach { println(it.toString()) }.collectIn(scope)
    the onEach block is not executed despite mutating the list I must instead explicitly do
    snapshotFlow { someClass.list.toList() }
    I am kind of confused why this is the case, and I feel like this must be a pitfall Im likely to run into again. Is this the intended behaviour? Could someone explain why?
    a
    a
    • 3
    • 4
  • j

    julioromano

    09/24/2021, 1:15 PM
    What’s the best API practice for having a composable with a default size but still allow it to be overridden via modifiers?
    z
    a
    +2
    • 5
    • 26
Powered by Linen
Title
j

julioromano

09/24/2021, 1:15 PM
What’s the best API practice for having a composable with a default size but still allow it to be overridden via modifiers?
I was thinking something like:
@Composable
fun SomethingNice(
  modifier: Modifier = Modifier,
) {
  Box(
    modifier = modifier.size(24.dp),
  ) {
    // Something more...
  }
}
It is working. But I was afraid the “default” 24dp modifier would be called after the one passed in via parameter therefore always overriding it. Turns out this is not true. But can’t understand why.
z

Zoltan Demant

09/24/2021, 1:28 PM
Have you seen this? I havent used it myself in practice, but Ive seen it used in the material library to seemingly do what youre looking for 🙂
Modifier.defaultMinSize()
a

Adam Powell

09/24/2021, 1:59 PM
Layout sizing modifiers alter the measurement constraints of their element more or less as (pseudocode)
min = max = myRequestedSize.coerceIn(parentSuppliedMin, parentSuppliedMax)
If the incoming constraint range doesn't include the requested size then it will try to get as close as it can
But only the
requiredSize
modifiers override parent constraints
j

julioromano

09/24/2021, 2:04 PM
Not sure I’m following. What I meant was: If I draw this:
SomethingNice()
It gets drawn at 24dp as expected. And if I draw this:
SomethingNice(modifier = Modifier.size(64.dp))
It gets drawn at 64dp. But it is strange to me as in the code it will happen something like:
@Composable
fun SomethingNice() {
  Box(
    modifier = Modifier.size(64.dp).size(24.dp),
  ) {
    // Something more...
  }
}
Shouldn’t the second call to
.size(24.dp)
override the first call to
.size(64.dp)
?
a

Adam Powell

09/24/2021, 2:28 PM
24.coerceIn(64, 64) = 64
24 is out of range of the constraints given by
size(64.dp)
so it's coerced into the constraints of the upstream parent
j

julioromano

09/24/2021, 2:31 PM
But it works even the other way around (e.g. if I pass in
Modifier.size(12.dp)
) In this case we’d have:
24.coerceIn(12, 12) = ?
But nevertheless
SomethingNice
it is displayed with 12dp size
Wait a sec… so by “the upstream parent” you mean “the upstream modifier” OR the “enclosing (i.e. outer) composable”?
Gosh I’m confused. So there’s no way to create a composable that would size itself to a default value while at the same time offering the (opt-in) possibility of sizing it to any other value?
In the end swapping
modifier = modifier.size(24.dp)
with
modifier = Modifier.size(24.dp).then(modifier)
Solve any issues with sizing I had 🤷
s

Scott Kruse

09/24/2021, 3:52 PM
Maybe I’m not understanding the question, but can’t you can solve this with default argument for modifier?
j

julioromano

09/24/2021, 3:53 PM
Nope, because a user may wish to add any modifier other than the size one while still keeping the default size
a

Adam Powell

09/24/2021, 6:51 PM
You should never need to invert the modifier order that way, you can still change the size externally with the component expressing its own default using the standard ordering.
"upstream parent" means the modifier that comes before it if there is one, or the parent layout composable if there are no more modifiers before it
👍 1
the layout process is one where each parent (and modifier) tells the next link in the chain, "you must be between
min
and
max
size; how big are you?"
Modifier.size
narrows those min and max constraints to be as close to the requested value as possible, within the constraints of how it was measured by its immediate parent (whether that parent is another layout modifier or a layout composable)
so if I write:
@Composable fun DefaultSizeBox(
  modifier: Modifier = Modifier,
  content: @Composable BoxScope.() -> Unit
) = Box(modifier.size(24.dp), content = content)
and then call it like this:
DefaultSizeBox(Modifier.size(64.dp)) {
  Text("Hello, world")
}
then the final modifier for the
Box
created by
DefaultSizeBox
is
Modifier.size(64.dp).size(24.dp)
. Measurement then proceeds; let's say the parent of the
DefaultSizeBox
measures it with the constraints
(min = 0, max = 500)
(simplified to only one dimension here for the sake of this discussion; both width and height each have a min and max)
👍 1
That measurement operation reaches the first
.size(64.dp)
. 64 is between 0 and 500, so now the measurement proceeds, but with
(min = 64, max = 64)
next, measurement reaches
.size(24.dp)
. 24 is not between 64 and 64; in order to be within that range the constraints are "changed" to
(min = 64, max = 64)
. The final box is measured with those constraints, and reports that it is size 64. The "outer" modifier passed to the
DefaultSizeBox
call thereby overrode the requested default defined in `DefaultSizeBox`'s implementation.
j

julioromano

09/27/2021, 9:23 AM
Thanks for the thorough explanation Adam, it took a while but I eventually digested all of this 🙂
👍 1
r

Rafiul Islam

09/28/2021, 11:49 AM
Hey , I goy this far. next, measurement reaches 
.size(24.dp)
. 24 is not between 64 and 64; in order to be within that range the constraints are "changed" to 
(min = 64, max = 64)
But what happened in this case? 24.coerceIn(12, 12) = ?
j

julioromano

09/28/2021, 11:53 AM
= 12
https://github.com/JetBrains/kotlin/blob/34e57a45f2d4283be572137b4b497414b8833ee7/libraries/stdlib/common/src/generated/_Ranges.kt#L1189
r

Rafiul Islam

09/28/2021, 11:56 AM
Ops. I know what coerceIn function does actually It was a stupid question As I see you mentioned you were getting 12. Anyway thanks
View count: 2