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

    Vitaliy Zarubin

    05/20/2021, 4:40 PM
    Please tell me what's wrong
    n
    f
    • 3
    • 23
  • m

    Michal Klimczak

    05/20/2021, 5:34 PM
    I have an interesting design to implement. Have a LazyColumn which can consist of any number of items but as whole this list should be shown on a card. So it should have rounded corners at the top and bottom and also a border along the whole thing. I visualized it on a screenshot - the red lines delimit LazyColumn items. I will probably need to draw these backgrounds directly on a Canvas, but maybe you can think of a more high-level way of doing that? I can't think of any - the border always outlines the whole shape, can't restrict it to just a part of a shape.
    ✔️ 1
    n
    c
    +2
    • 5
    • 17
  • b

    Billy Newman

    05/20/2021, 7:38 PM
    Not seeing a subtitle property in TopAppBar. Is this coming soon, or possible to implement in another way?
    c
    • 2
    • 5
  • z

    Zach Klippenstein (he/him) [MOD]

    05/20/2021, 8:49 PM
    Is this change intended to solve internal issues, or external ones? Exhaustive when breaking when enums are changed is a feature of kotlin, I would think if consumers are writing exhaustive whens on these things then they’d want them to break if the API changes.
    s
    a
    • 3
    • 14
  • a

    Ahmed Mourad

    05/21/2021, 1:17 AM
    Hey everybody, I just encountered some bizarre behavior and I don't think it's intentional. So when using a
    LazyVerticalGrid
    , you can pass an instance of
    LazyListState
    as a parameter, which itself takes
    initialFirstVisibleItemIndex
    as a parameter:
    LazyVerticalGrid(
        cells = GridCells.Fixed(cellsPerRow),
        state = rememberLazyListState(initialFirstVisibleItemIndex)
    )
    The problem is that the index passed to
    rememberLazyListState
    is used as a row index instead of an item index. So if I pass 5 as
    cellsPerRow
    in the above example, and I pass 7 as the
    initialFirstVisibleItemIndex
    , I would expect the second row to be the top of my list, but instead it's 7th row that is at the top. At this point I usually have to do this to get the correct behavior:
    rememberLazyListState(initialFirstVisibleItemIndex / cellsPerRow)
    a
    a
    • 3
    • 2
  • j

    Jason Ankers

    05/21/2021, 2:36 AM
    Is it possible to get scroll offset in pixels for
    LazyColumn
    ? Can only see
    firstVisibleItemScrollOffset
    which is relative to items in the list
    a
    j
    a
    • 4
    • 14
  • t

    Tin Tran

    05/21/2021, 3:13 AM
    I’m having a weird problem with
    Icon
    . All my
    Icon
    turned black when using in a composable and I have to use
    tint
    to turn it into the right color. Does anyone else having the same issue?
    a
    p
    b
    • 4
    • 12
  • c

    Colton Idle

    05/21/2021, 3:34 AM
    Really simple question, but what's the easiest way to have two equally sized buttons in a row. Code in thread
    t
    n
    +3
    • 6
    • 16
  • j

    jean

    05/21/2021, 4:42 AM
    As a rule of thumb, you should create a view model to hold your state […] when the composable is close to the root of the screen.
    When that’s not the case, for examples, composables that are reusables […], don’t use a view model , instead create a regular state holder class to manage state and expose events.
    This is said shortly after 7:32 in the video, the slide at that time refers to a
    Carousel
    and a
    ExpandableCard
    but I couldn’t find any related code in the compose-sample project. Does anyone hasve a concrete/sharable example of such a “regular state holder class”?

    https://youtu.be/0z_dwBGQQWQ?t=452▾

    a
    s
    • 3
    • 8
  • y

    Yuri Drigin

    05/21/2021, 5:24 AM
    Hi folks! I need run
    infiniteTransition
    with scale effect for 3 different views, but each transition should start with delay after previous.
    dalay
    in AnimationSpec doesn’t help. Cuz I need only start delay not for every cycle
    Untitled.kt
    d
    • 2
    • 2
  • s

    Saiedmomen

    05/21/2021, 7:38 AM
    I am trying to use the top current item of
    LazyColumn
    as a state and recompose another composable based on it. I have found
    listState.layoutInfo.visibleItemsInfo
    which works mostly except that it gets updated with every minuscule scroll and causes performance issues. Is there a pattern to implement filter or debounce like behavior with compose state? Is my approach completely wrong?
    a
    a
    • 3
    • 3
  • i

    iamthevoid

    05/21/2021, 8:18 AM
    I want to implement mechanism to force select app day-night theme. For example: if set returns it, else returns
    isSystemInDarkTheme()
    . For example this fun will be called
    isAppInDarkTheme()
    . I also want to recompose all dependent composables. Which parts and mechanism of compose is better to use to achieve behavior like it?
    a
    • 2
    • 3
  • n

    nitrog42

    05/21/2021, 8:58 AM
    btw, does the locale parameter of the @Preview works for you ?
    @Preview(locale = "fr")
    it remains in english for me 😄 (I'm providing a values-fr/strings.xml) and of course I also tried
    @Preview(locale = "fr-rFR")
    c
    n
    • 3
    • 10
  • a

    Aditya Thakar

    05/21/2021, 9:58 AM
    Hi folks! Is this the right way to show SplashScreen or there is a better way?
    @Composable
    fun SplashScreen(navController: NavController) {
        SplashScreenContent()
        val coroutineScope = rememberCoroutineScope()
        SideEffect {
            coroutineScope.launch {
                delay(2000)
                navController.popBackStack()
                navController.navigate(Screen.Home.route)
            }
        }
    }
    p
    l
    +3
    • 6
    • 7
  • v

    Vitaliy Zarubin

    05/21/2021, 10:18 AM
    implementation("com.google.accompanist:accompanist-glide:0.10.0")
    🙁 What an accompanist wants? https://google.github.io/accompanist/glide/
    a
    a
    • 3
    • 10
  • f

    Felipe Passos

    05/21/2021, 11:59 AM
    Hello, i'm trying to only change a variable only when this column is focused, but it keeps getting the inicial last_location value when it is not focused. PS: location is a state variable
    Sem título.kt
    s
    • 2
    • 3
  • a

    alorma

    05/21/2021, 1:35 PM
    Hi! One question. how can I make all the content scroll when the bottom
    LazyColumn
    scrolls? Should I set all the content inside a
    LazyColumn
    ?
    :yes-black: 2
    t
    n
    • 3
    • 3
  • a

    alorma

    05/21/2021, 1:54 PM
    keeping with last post... Is a good or bad practice to do this?
    fun LazyListScope.postsListEmpty() {
        item {
            Box(
                modifier = Modifier.fillMaxSize(),
                contentAlignment = Alignment.Center,
            ) {
                Text(text = "No items")
            }
        }
    }
    m
    • 2
    • 1
  • a

    allan.conda

    05/21/2021, 2:17 PM
    What would be the best practice for defining multiple required arguments for compose navigation? Let’s say there’s multiple ids I need to pass. How about something like this?
    screenA/itemId/userId/someToken
    Or is below better even though the syntax is for optional arguments…
    screenA/itemId?userId={userId}&someToken={someToken}
    i
    p
    • 3
    • 4
  • n

    natario1

    05/21/2021, 3:13 PM
    Is TextAlign supposed to be working in
    BasicTextField
    ? The three fields below all have text set
    "x"
    , and alignment is TextAlign.Start, Center and End. I'm setting the alignment from text style.
    c
    • 2
    • 4
  • r

    rudolf.hladik

    05/21/2021, 5:04 PM
    Is there some example of sticky header in compose?
    h
    • 2
    • 1
  • a

    Alex

    05/21/2021, 5:05 PM
    Is there a way to align text to the right and have other text leftalign based on that first text's contents? (Pictures in thread)
    h
    j
    n
    • 4
    • 14
  • m

    Marco Pierucci

    05/21/2021, 5:30 PM
    Hello All! I have a question about state hoisting. Based on the docs and recent videos aiming for stateless composables should be the way to go. State is recevied as a function param and we transmitted through lambas. I find this quite compelling but am currently working on a rotationary dial. Within I have so inner state ( texture angle, gesture angle, pointer info etc). Does it makes sense to push for a stateless component on this scenario? It feels weird that my domain layer needs to be aware of such thing
    z
    g
    • 3
    • 5
  • z

    Zach Klippenstein (he/him) [MOD]

    05/21/2021, 5:31 PM
    People who are building design systems in Compose: Are yall using prefixes/suffixes on your component functions to identify them as part of your design system? E.g.
    Button
    ->
    MaterialButton
    . (Would love to hear your thinking about this in the thread! Why are you or aren’t you using prefixes?)
    :yes: 2
    🇳🇴 11
    k
    k
    +4
    • 7
    • 14
  • y

    YASAN

    05/21/2021, 6:07 PM
    Is it possible to initiate outside of a composable function? I use my navController on
    onNewIntent()
    of my activity but it can sometimes throw a null exception due to it not being initiated yet.
    i
    • 2
    • 4
  • h

    Halil Ozercan

    05/21/2021, 6:08 PM
    I've seen some comments about how Previews work way better in Bumblebee but I had to see it with my own eyes. There's a huge difference. Congratz to Compose Tooling team for such a great update 😛arty-parrot:
    :party-parrot: 12
    j
    y
    +2
    • 5
    • 4
  • c

    Colton Idle

    05/21/2021, 7:35 PM
    Is there such thing as an auto size text view in compose? I searched cs.android.com without being able to find anything related to compose. Like this?

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

    z
    s
    +2
    • 5
    • 8
  • i

    iamthevoid

    05/21/2021, 8:47 PM
    Is it possible to group composable to apply modifier on this group? For example i have scrollable column with 50 elements, but i want to apply padding only for composables from 17 to 33. Is it possible? Note that if i wrap it to another layout then all will be collapsed no matter which layout i would to select
    a
    • 2
    • 3
  • t

    tad

    05/21/2021, 10:58 PM
    Should
    rememberSaveableStateHolder()
    restore the scroll state of a
    LazyColumn
    in a child composable?
    z
    • 2
    • 5
  • h

    Halil Ozercan

    05/21/2021, 11:23 PM
    Implemented this view by using
    swipeable
    modifier. However,
    swipeable
    accepts a predefined map of anchors which are limited unless the developer wants to put thousands of anchor points in there. Instead, I reset the swipe state everytime it gets settled and aggregate the total swipe amount. My question; is there a canonical way of doing this snapping behavior without swipeable?
    out.mp4
    ➕ 1
    d
    • 2
    • 8
Powered by Linen
Title
h

Halil Ozercan

05/21/2021, 11:23 PM
Implemented this view by using
swipeable
modifier. However,
swipeable
accepts a predefined map of anchors which are limited unless the developer wants to put thousands of anchor points in there. Instead, I reset the swipe state everytime it gets settled and aggregate the total swipe amount. My question; is there a canonical way of doing this snapping behavior without swipeable?
out.mp4
➕ 1
The weird swipe reset looks like this
val swipeableState = rememberSwipeableState(initialValue = 0)
var daysOffset by remember { mutableStateOf(0) }
val progress = swipeableState.progress

LaunchedEffect(progress) {
    if (progress.fraction == 1f && <http://progress.to|progress.to> == progress.from) {
        daysOffset -= <http://progress.to|progress.to>
        swipeableState.snapTo(0)
    }
}
.swipeable(
    state = swipeableState,
    anchors = (-7..7)
        .map {
            it * (24 * 3600 / secondPerPixel) to it
        }
        .toMap(),
    orientation = Orientation.Horizontal
)
Only 7 anchors are enough because view is limited by a week. If there is no swipe reset, scrolling would completely stop in one week range.
d

Doris Liu

05/22/2021, 12:18 AM
For this type of more custom snapping behavior that has outgrown the convenient
swipeable
API, you might want to reach for a lower level API. In this case, I'd recommend
dragable
and
Animatable
. It may not be that much more code than the hack you have right now. 😛 At the end of the drag, you'd need to use that velocity to calculate the natural stopping point, find the closest anchor among any number of anchors that you might have, and
animateTo
it. In fact, there's a good example in the animation codelab for this.
Under gesture animation, there's a section on how to calculate the natural stopping point/targetValue: https://developer.android.com/codelabs/jetpack-compose-animation#7
➕ 4
You could probably achieve the same using a
scrollable
with a custom
FlingBehavior
🙂
➕ 5
h

Halil Ozercan

05/22/2021, 6:31 AM
Thanks a lot @Doris Liu, I'll try both methods 👍
👍 1
@Doris Liu scrollable+fling felt like the better approach here considering the trade-offs. Animatable + Draggable required lower level API operations that felt unnecessary for this kind of use-case. Swipeable hack also rarely caused crashes. That actually happens whenever I use swipeable and want to access
swipeable.progress
.
d

Doris Liu

05/25/2021, 12:05 AM
Could you file a bug including a stack trace of the crash? I don't expect crashes here even with the hack. 🙂
View count: 4