https://kotlinlang.org logo
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
benchmarks
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
confetti
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
hiring-french
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
lincheck
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
Title
o

OG

02/07/2022, 8:59 PM
Hello everyone, šŸ‘‹ I was wondering if anyone has any suggestions on the best way to approach building a curved/arced horizontally scrolling list of items with "Snap to Center" behavior + having the beginning of the list positioned in the center of the screen. I've found an article that does something like what I am trying to do, but with RecyclerView + custom layout manager. Posted gif from link below for quick reference as well.
I don't think this can be easily done with just using a LazyRow + custom modifiers. I think compose viewpager will give me snap to center behavior but not the curved/arced scrolling/path.
I am thinking the way to go is to create a custom Layout composable where I handle all the measuring + layout + offset + scrolling manually.
Possibly leveraging how LazyRow works under the hood but the difference being how each child measurable is laid out (using some x offset from center to determine its y offset)
and then the last part would be figuring out how to handle the snap to center and list starting from the center of the screen
would appreciate any feedback/thoughts/sanity check on my approach or any other approach here. thanks!
z

Zun

02/07/2022, 9:14 PM
I actually have no idea, but what about horizontal pager with custom transition animation?
šŸ‘ 1
o

OG

02/07/2022, 9:27 PM
I think with that you can apply probably fade in/out and expand/contract of each item but I dont believe you would be able to achieve what I am looking for here.. I could be wrong though. I will have to take a closer look at the source code
d

dewildte

02/07/2022, 10:53 PM
Math probably would help here
lol
:troll:
o

OG

02/07/2022, 11:20 PM
Lol yeah that's what I'm thinking.. especially if I go with custom Layout. Should've paid more attention in calc in the college days I guess.... šŸ™ƒ
r

raghunandan

06/08/2022, 2:16 AM
Did you figure it out. Looking for solution on similar lines.
o

OG

06/20/2022, 10:21 PM
Custom layout , and it's pretty tricky, but I'll send this to channel in case there's alternatives solutions/ideas that may be easier to implement. Lots of compose changes since I originally posted this, so maybe there's a more sane way now to achieve this...
s

steelahhh

06/21/2022, 4:36 AM
I feel like ScalingLazyColumn could be a source of inspiration for achieving this
r

raghunandan

07/24/2022, 4:02 PM
https://fvilarino.medium.com/creating-a-circular-list-in-jetpack-compose-29924c70e3e0. Can use this for inspiration. Seems custom layout and bit of maths should work. In case you do figure out can you post the gist somewhere for others to see?
https://gist.github.com/raghunandankavi2010/133b9a821b483cea584d5c7de658ba08. Horizontal scrolling with scaling and alpha. However offset of y nees to be calculated for your case i guess.
o

OG

07/31/2022, 8:44 PM
Nice solution! This use case I was looking for is actually pretty easy to do with horizontal swiping pager, with a custom transition of offsetting y and scaling. The outer ring that always is around the centered item is actually a composable that sits above the pager and is centered.
I'll see if I can find some time to pull it out into a demo app or gist and share here, for anyone else that comes this use case.
r

raghunandan

08/01/2022, 2:51 AM
Yeah. Interesting. I tried with pager. But since we need to place more items in one page i had to hardcode some padding values to center the initial. I may be wrong. can you post a gist of pager solution as well.
@OptIn(ExperimentalPagerApi::class)
@Composable
fun PagerDemo(modifier: Modifier = Modifier) {

    HorizontalPager(
        count = 30,
        // Not sure if i can remove this hardcoded value.
        contentPadding = PaddingValues(horizontal = 160.dp),
        itemSpacing = 8.dp,
        modifier = modifier
    ) { page ->
        Card(
            modifier = Modifier
                .graphicsLayer {
                    val pageOffset = calculateCurrentOffsetForPage(page).absoluteValue
                    // Set the item alpha and scale based on the distance from the center
                    val percentFromCenter = 1.0f - (pageOffset / (5f / 2f))
                    val itemScale = 0.5f + (percentFromCenter * 0.5f).coerceIn(0f, 1f)
                    val opacity = 0.25f + (percentFromCenter * 0.75f).coerceIn(0f, 1f)

                    alpha = opacity
                    scaleY = itemScale
                    scaleX = itemScale
                }
                .clip(CircleShape)
                .size(50.dp)
        ) {
            Image(
                painter = painterResource(R.drawable.ic_launcher_background),
                contentDescription = null,
                modifier = Modifier
                    .size(50.dp)

            )
        }
    }
}
contentPadding = PaddingValues(horizontal = 160.dp)
This is something that is hardcoded would like to replace this.
o

OG

08/01/2022, 2:42 PM
Use a parent
BoxWithConstraints
to get the available width, you know your item width (e.g. 50dp), and then you can do some easy math to figure out the content padding without hardcoding, so the first item is centered
r

raghunandan

08/01/2022, 2:49 PM
Got it. Thanks!