Colton Idle

    Colton Idle

    1 year ago
    In the compose state codelab it goes through a trivial example of having a tint color that is calculated via Random and this is done every recomposition. They show that if you wrap it in a remember {} function giving it a key, then it no longer generates a new random when an item is added to the list. BUT at the bottom it says "this makes it idempotent"
    An idempotent composable always produces the same result for the same inputs and has no side-effects on recomposition.
    But since this composable is in a LazyColumn, if you scroll up and down then Random is triggered again after the composable goes off the screen and comes back. Doesn't this go against the whole "same result for the same inputs"? Is the codelab "wrong" in stating that this is idempotent?
    😂 Just got to the end of the codelab
    There's also a really subtle bug with our 
     usage. Try adding enough todo rows to scroll a few off screen by clicking "Add random todo" repeatedly then scrolling. As you scroll, you'll notice that the icons change alpha every time they scroll back onto the screen.