My first screen that I did in compose! The entire...
# compose
c
My first screen that I did in compose! The entire fragment is only ~70 lines long, but I don't think it's idiomatic. Can anyway take some time to critique? https://gist.github.com/ColtonIdle/85db918c763076cbb147b722e6807007
a
Looking pretty good! I'd move this:
Copy code
model.getItems()!!.observe(viewLifecycleOwner, {
    setContent {
        ComposeTrialScreen(response = it)
    }
})
to be:
Copy code
val items = model.getItems() ?: error("items missing")
setContent {
    ComposeTrialScreen(items.observeAsState().value)
}
but it's a bit of 6 of one, half dozen of the other
c
😁 Yeah, I figured that would be one issue potentially. I still suck at this whole observables thing. I have a hard time knowing what's a observable type/method from kotlin or compose or flowable or rx. Ya know?
@Adam Powell two more things. 1. Is that
error("items missing")
a popular way to go about this? First time I've seen that. 😃 2. Just noticed that scrolling up and down loses my expand/collapsed items. So in this case... I want to "hoist" the state up into my VM most likely?
a
1. was just my way of translating your
!!.
null-assertion to give it a better error message; removing the nullability there entirely would probably be ideal
🎉 1
2. yes, you would bring that expanded/collapsed state up to your data model in some form
🎉 1
c
@Adam Powell i may have asked this before... but do you think its worth filing for a lint issue here to flag a user down that a composable is used inside of a "volatile" layout and so the state should be hoisted up?
a
Not sure what you mean
c
Like. I didn't notice the collapse/expandable state is basically worthless until I started playing around with a longer list and then noticed that my state was being lost once I scrolled off the list.
So it seems like if your Composable has state inside of it, and the composable is placed inside of a Lazy* container, then lint could warn you of potential state loss?
a
Ah. It'd be a real shallow gesture; you're one refactor/extract method away from still having the same issue
👍 1