Vadim Kapustin
11/13/2020, 11:53 AMAnimesh Sahu
11/13/2020, 12:27 PM.collectAsState()
to get state representation of the StateFlow.
As far as I understood, every event fires redraw event of all the children UI elements, but only whose state changed actually gets executed and changed. When using a StateFlow, and directly calling StateFlow.value
you'll be redrawing the UI for every single event like mouse move, mouse enter, mouse click, to the element you are using it with, even if the value wasn't changed.Vadim Kapustin
11/13/2020, 1:08 PMgildor
11/13/2020, 1:36 PMZach Klippenstein (he/him) [MOD]
11/13/2020, 3:33 PMShawn Witte
11/13/2020, 5:55 PM@Compose
function, I use Flow
(or whichever subclass is appropriate, e.g. StateFlow
), because Flow
is fairly universal. However, the first few lines of my @Compose
functions all convert those to State
via collectAsState()
because I know the composables will properly handle updates to State
.