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
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
c

Colton Idle

01/18/2021, 10:34 PM
I have a List of Movies (list of movies could be in the 10000s) and each movie has a reviews. There can be hundreds of reviews left on a movie. I know its bad UX/design, but I want to show a list of Movies with ALL of the reviews listed in the same movie card. I'm not sure how to build this, because in the "android" world I would make the Movie List a RecyclerView, and each review section in the MovieCard would be a recyclerView too. But compose doesn't let you do that.
LazyColumn{
    items(movies){
        MovieCard(it)
    }
}

MovieCard(movie: Movie){
    Text(movie.name)
    LazyColumn{
        items(movie.reviews){
            ReviewItem(it)
        }
    }
}
You get an error like this
java.lang.IllegalStateException: Nesting scrollable in the same direction layouts like ScrollableContainer and LazyColumn is not allowed. If you want to add a header before the list of items please take a look on LazyColumn component which has a DSL api which allows to first add a header via item() function and then the list of items via items().
Problem is solved if the LazyColumn in MovieCard just become a Column and I iterate with a for loop. BUT I want that inner loop to be performant and handle being super long. So I don't want a "dumb" Column. I need something that will recycle those ReviewItems.
j

jim

01/18/2021, 10:41 PM
Take a look at 
Modifier.nestedScroll
c

Colton Idle

01/18/2021, 10:43 PM
@jim and that would just go on the inner Column right? I understand that, but I guess my question is does the inner Column/ScrollableColumn become "lazy" just because it's used in a LazyColumn parent?
j

jim

01/18/2021, 10:44 PM
No, a child should never behave differently just because of the parent it happens to be placed within.
c

Colton Idle

01/18/2021, 10:47 PM
Bah. Alright. Back to square one though. How do I make sure that the inner column stays performant (like the outer LazyColum)?
k

Kirill Grouchnikov

01/18/2021, 10:47 PM
Maybe go back to the "I know it's bad UX / design" part
c

Colton Idle

01/18/2021, 10:48 PM
There have to be some designs where a LazyColumn inside of a LazyColumn would be applicable right? I just don't see any way of doing that in compose and I don't know if it's a missing "feature" or if it's possible and I'm just not sure how to do it.
a

Andrey Kulikov

01/19/2021, 3:23 PM
LazyColumn{
    movies.forEach { movie ->
         item {
              Text(movie.name)
         }
         items(movie.reviews){
             ReviewItem(it)
         }
    }
}
c

Colton Idle

01/19/2021, 4:04 PM
@Andrey Kulikov thanks. But the Movie itself is a card and inside of the card there should be Text and under the text should be a list of ReviewItems. Still the only thing I can think of is:
LazyColumn{
    items(movies){
        MovieCard(it)
    }
}
MovieCard(movie: Movie){
    Text(movie.name)
    LazyColumn{
        items(movie.reviews){
            ReviewItem(it)
        }
    }
}
@Andrey Kulikov don't mean to bother again as I'm sure I'll figure it out. But do you see my point in how your sample code doesn't necessarily line up for what I'm trying to do? It's almost as if my MovieCard uses "slot api" where I'm trying to pass in a LazyColumn into that.
a

Andrey Kulikov

01/20/2021, 6:14 PM
yes, unfortunately there is no good solution at least yet when you want to combine multiple elements into something like card. it will only work nicely if you can split the card drawing into something like
item { CardHeader() } items { … } item { CardFooter() }
so it visually looks like card, but it is not that easy with elevations. in you can’t split them then your whole card should be a one item with just Column instead of LazyColumn inside and you kinda loosing the laziness. note that in your example where you said that in Android you usually just wrap RecyclerView inside RecyclerView it was working in pretty much the same way: the inner RecyclerView was measured with the infinity constraints which means all the elements were created and added straightaway with loosing the whole recycling mechanism. the same issue is happening in Compose, but we decided to throw an exception when we detect such case so users are aware that they do something inefficiently
c

Colton Idle

01/21/2021, 7:11 AM
Interesting. In typical android I have done RV inside of an RV a bunch of time. Sometimes the inner RV is vertical (to enable this kind of list within a list) and sometimes it's horizontal (in order to make a carousel. like airbnb app for example). I had NO idea that RV inside of an RV was basically not really working as I intended (👀 "loosing the whole recycling mechanism"). I do like that COmpose just throws an exception. This would be a cool problem to solve, or prodvide guidance around though in the docs. I feel like for now we might just go for a LazyColumn and then internally in the card we just use a column. @Andrey Kulikov thank you so much again. My team is eager to move to compose to really simplify RVs, carousels, etc. and this use case is actually something we hit a lot of and its nice to know the limitations of compose. Really appreciate it
a

Andrey Kulikov

01/21/2021, 11:40 AM
Sorry, I might confused you again. Nesting RecyclerViews scrolling in different directions will work fine. The same with nesting LazyRow inside LazyColumn. But when you nest vertical RecyclerViews inside vertical RecyclerViews the inner one has no size limits anymore and can’t recycle within its viewport as it will basically just create views for all the children and wrap them
c

Colton Idle

01/21/2021, 5:17 PM
@Andrey Kulikov that makes sense to me. So you can't do LazyCol inside of LazyCol because LazyCol is essentially a no size limit and so it can't recycle it's viewport. Crazy idea: I could perf test a LazyCol containing a Col with a foreach internally (Basically movie cards will be lazy but reviews INSIDE of a card would not be lazy) AND I could perf test the reverse. Have a Col of Movies, and the reviews inside of movies can be a LazyCol. I could perf test those two and see which performs better?
a

Andrey Kulikov

01/21/2021, 5:47 PM
the second option will not really work as just Column is not scrollable. only reviews will scroll
c

Colton Idle

01/21/2021, 5:55 PM
@Andrey Kulikov sorry. when I say Column I mean Column with scrollable modifier enabled or just using ScrollableColumn (but I think that was deprecated)
a

Andrey Kulikov

01/21/2021, 5:56 PM
yes, I deprecated it recently. if you try to nest ScrollableColumn and LazyColumn they will crash with the same exception for the same reason. when something is scrollable it means their content is measured with infinity constraints(maximum height)
c

Colton Idle

01/21/2021, 5:58 PM
@Andrey Kulikov thanks. this all is making a lot more sense to me. appreciate your help! maybe i can end up trying the movie details in the top half of a card, and having the reviews in a bottom half of a card in order to give the illussion of one full card. Thank you!
j

Johan Reitan

03/05/2021, 1:11 PM
Did you experiment more with this? I have the same use case, and I've had it in several projects in the past as well. I have successfully implemented this with RV before with header, content and footer, but it seems elevation works a bit differently in Compose than it did in the View system. I tried the same in Compose, like @Andrey Kulikov suggested, but this is what I get, which of course has elevation issues:
This is just `Card`s with different `shape`s depending on their positions