if I remove the comment, sends the error cc <@UJBK...
# compose
m
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
You are indeed calling a composable function from a non-composable function as the error suggests ๐Ÿ™‚
m
how do I add then a new item to my list so my AdapterList has more values?
I'm clueless, sorry
a
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
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
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
thanks! and how to I make my mutable list visible to compose?
a
You can use
modelListOf
instead of
mutableListOf
If you go that direction you should make the list a
val
rather than a
var
m
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
Call
withIndex()
on your list before passing it to
AdapterList
.
m
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
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
Thanks! I'm trying to "break it" ๐Ÿ˜‰ to check all I can do with AdapterList
I'll check that and file the bug
a
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
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
Amazing! Thanks!