allan.conda
07/03/2020, 10:13 AMAndrey Kulikov
07/03/2020, 10:19 AMallan.conda
07/03/2020, 10:37 AMLilly
07/03/2020, 2:45 PMusername
state into Screen
function. You should break down your composables into smaller ones at your own discretion.
Regarding the question about putting state in ViewModel or composable function...I have a question:
@Andrey Kulikov Does remember
or by state
survive a configuration change. If not, I would put state in ViewModel
if it has to survive configuration changes otherwise in composables.Andrey Kulikov
07/03/2020, 3:03 PMrememberSavedInstanceState
and savedInstanceState
that behaves as remember
and state
, but also survives the configuration change/process recreationallan.conda
07/03/2020, 3:52 PMLeland Richardson [G]
07/03/2020, 6:31 PMTop
, which will then call Screen, which will then call some other things and eventually TextField.
You can see how in this example the top one is going to be the more efficient of the two, but it also means that the username
state can’t be used in very many places (just the scope where you defined it). In a way, that’s not an accident. This is why we generally say to define the state as deep as possible, which is to say, the deepest common ancestor of all of the places in the tree that actually need to read it.
I also might say that the best advice might be just to write it in a way that “feels good”. That is, declare the username variable in a place where it feels natural to declare it. For me, that would probably be at the top of the Screen composable, but not in the Top composable, even though the version you posted was more efficient, putting the variables at the top fo the function is generally what feels right to me. And I do so not for performance reasons, but just for readability etc.Leland Richardson [G]
07/03/2020, 6:32 PMLeland Richardson [G]
07/03/2020, 6:34 PMLilly
07/03/2020, 8:02 PMallan.conda
07/06/2020, 5:09 AMSean McQuillan [G]
07/06/2020, 8:52 PMSean McQuillan [G]
07/06/2020, 8:53 PMSean McQuillan [G]
07/06/2020, 8:56 PM