Ellen Spertus
08/13/2022, 1:37 AMOliver.O
08/13/2022, 9:23 AMMutableState
properties as a source of truth would ease understanding. That combination could provide a good basis for getting a glimpse on how attractive UIs are created today.Youssef Shoaib [MOD]
08/13/2022, 1:26 PMOliver.O
08/13/2022, 1:52 PMEllen Spertus
08/13/2022, 6:24 PMEllen Spertus
08/13/2022, 6:29 PMOliver.O
08/13/2022, 7:36 PMEllen Spertus
08/14/2022, 3:31 AMOliver.O
08/14/2022, 12:28 PMArkadii Ivanov
08/14/2022, 5:59 PMOliver.O
08/15/2022, 3:15 PMModifier.recomposeHighlighter()
on Row
, which will quickly color the entire board in yellow to red (source code).
An alternative would be a Board
comprising an array of cells, each cell having a mutable state, and then using a Cell
Composable enclosing the different cell types. Only the mutable state on the cell level would then change, allowing Compose to skip everything but the Cell
Composable.
Again, it's not necessarily a problem in this case, but when introducing UI concepts or showing examples to newbies, I'd start with habits that avoid common problems. In this case, pushing state reads down the tree as far as possible (also recommended in Compose best practices). When to short-cut such practices would be the topic of a later lesson.Arkadii Ivanov
08/15/2022, 3:45 PMBoard
class at the very top and passing sub-parts down the tree aligns with the state hoisting principle and SSoT. The fact that in this particular case Compose cannot infer that some sub-parts have not changed is another concern. I believe this could be solved by using immutable persistent collections or maybe by using special Compose annotations. But unless the performance is affected, I would not over-engineer the code. Again, recomposing is usually fast and doesn't imply re-rendering. Also in the future, composition should run on a background thread, this should further improve the performance.
Here is another example of having one single state object with lots of data. The performance is very good there as well. https://github.com/arkivanov/compose-3dOliver.O
08/15/2022, 4:56 PMoletjens
08/16/2022, 2:03 PMOliver.O
08/16/2022, 3:44 PMYoussef Shoaib [MOD]
08/16/2022, 3:55 PMoletjens
08/16/2022, 4:26 PMOliver.O
08/16/2022, 4:48 PMoletjens
08/16/2022, 4:56 PMEllen Spertus
08/16/2022, 5:25 PM