I am new in android development. Question: If I w...
# compose
v
I am new in android development. Question: If I want to add , suppose circular loading UI/screen for any process ongoing like fetching/uploading. Is it good approach to create only one common composable, one viewmodel to hold loading states and use it all over app, whenever there is loading? Or should I create different for some different processes? Thank you.
d
It depends on the complexity of the application. Usually you have one viewmodel per screen, each being responsible for loading its resources. So you would put a loading animation on each screen and show it depending on the viemodels state.
v
So one common composable of loading. But different loading states as per different screens. Right?
d
I'm not sure what you mean with one common composable of loading.
a
As Daniel mentioned, you can have a viewmodel that controls the state on the screen, one of those states could be loading, in that point you show the circular progress bar, now, you can create a simple component (like a column with
fillMaxSize
modifier and in the center a circular progress bar) for the loading, and it can be used on different screens when the state is the correct one
v
@Daniel Weidensdörfer sir I mean, creating one composable function specially for loading screen and reuse it. When to show in a particular screen, It'll depend on viewmodel states created for that particular screen.
a
Yes, that is ok
v
@Alejandro Rios Thanks sir! So one viewmodel for loading states is enough, no need to create different for different screens.
a
No, you need a viewmodel for each main screen(by main screens I mean something like login screen, detail screen, etc) each viewmodel will launch a loading state on which you show your loading screen
v
Oh got it! Thanks sir