Thread
#compose
    Colton Idle

    Colton Idle

    1 year ago
    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
    Adam Powell

    Adam Powell

    1 year ago
    Looking pretty good! I'd move this:
    model.getItems()!!.observe(viewLifecycleOwner, {
        setContent {
            ComposeTrialScreen(response = it)
        }
    })
    to be:
    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
    Colton Idle

    Colton Idle

    1 year ago
    😁 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?
    Adam Powell

    Adam Powell

    1 year ago
    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
    2. yes, you would bring that expanded/collapsed state up to your data model in some form
    Colton Idle

    Colton Idle

    1 year ago
    @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?
    Adam Powell

    Adam Powell

    1 year ago
    Not sure what you mean
    Colton Idle

    Colton Idle

    1 year ago
    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?
    Adam Powell

    Adam Powell

    1 year ago
    Ah. It'd be a real shallow gesture; you're one refactor/extract method away from still having the same issue