https://kotlinlang.org logo
#compose
Title
# compose
m

Mariano Zorrilla

03/11/2020, 2:41 PM
if I remove the comment, sends the error cc @Adam Powell
I'd tried with "state" directly, with a fun @Composable, etc and nothing, and there's no info online
a

Adam Powell

03/11/2020, 2:44 PM
You are indeed calling a composable function from a non-composable function as the error suggests 🙂
m

Mariano Zorrilla

03/11/2020, 2:44 PM
how do I add then a new item to my list so my AdapterList has more values?
I'm clueless, sorry
a

Adam Powell

03/11/2020, 2:45 PM
It's ok 🙂 lots of new stuff in play here
There are two things you need to accomplish: add more data and make sure compose knows about it to update
m

Mariano Zorrilla

03/11/2020, 2:46 PM
I know 😋 trying to get lot of info to make a Meetup, help folks over SoF and Medium and trying to investigate A LOT
a

Adam Powell

03/11/2020, 2:47 PM
You've declared ListCounter to be
@Model
which will notify compose if any of its vars change, but you're not changing one of its vars, you're changing a mutable list contained therein
You'll want to remove
@Composable
from your
emitter
- it doesn't need to be special, and you don't want to wrap the change in
state {}
- that's for declaring a tracked
MutableState<T>
and `remember {}`ing it at that point in the composition. You already have your state object and don't need to create another.
You have two ways to go: you can make the mutable list changes visible to compose, or you can use immutable lists and change the model class var that is already tracked by compose
m

Mariano Zorrilla

03/11/2020, 2:51 PM
thanks! and how to I make my mutable list visible to compose?
a

Adam Powell

03/11/2020, 2:53 PM
You can use
modelListOf
instead of
mutableListOf
If you go that direction you should make the list a
val
rather than a
var
m

Mariano Zorrilla

03/11/2020, 2:55 PM
life saver! Thanks
👍 1
this March 18th I'll do a talk about Jetpack Compose in Argentina and was planning to host one in San Francisco (when I get sure there's not health issues) for Jetpack Compose, Flutter and Swift UI that I think it will be awesome to compare all new declarative UIs
I'll add you to the slides 😋
is there any way to get the AdapterList current index?
z

Zach Klippenstein (he/him) [MOD]

03/11/2020, 6:13 PM
Call
withIndex()
on your list before passing it to
AdapterList
.
m

Mariano Zorrilla

03/11/2020, 6:20 PM
Thank you so much! I also noticed adding items to modelList is ok but removing creates an out of bounds exception
withIndex().toList() over AdapterList works as well for index 🙂
a

Adam Powell

03/11/2020, 7:41 PM
please file a bug for the removal thing so we can investigate
you might also find it useful to experiment with the
kotlinx.collections.immutable
library's
PersistentList
and assign the new immutable lists to a model field or
State<T>
- we use those collections internally in compose so it's not going to add any more overhead to your apk size than is already there
😮 1
m

Mariano Zorrilla

03/11/2020, 7:43 PM
Thanks! I'm trying to "break it" 😉 to check all I can do with AdapterList
I'll check that and file the bug
a

Adam Powell

03/11/2020, 7:45 PM
AdapterList is a very early prototype of the API shape and some approaches to the internal composition and layout model for virtualized layouts like this - I'm sure there are many ways to break it at the moment 🙂
r

Ryan Mentley

03/13/2020, 8:24 AM
If you did file that bug, please send it to me - I am aware of it from a StackOverflow post but hadn't filed an issue with a repro case yet
If you haven't, I'll file it soon
m

Mariano Zorrilla

04/10/2020, 2:36 PM
Amazing! Thanks!
3 Views