hi everybody, how do you guys show and hide a pro...
# compose
m
hi everybody, how do you guys show and hide a progress indicator while some data is being loaded?
k
Compose allow us to write code in a declarative approach. All you have to do is describe how the layout should look.
Copy code
@Composeable fun compose() {
   ...
   if (!isLoaded) {
       ShowProgressBar()
   } 
   ...
}
m
well in my case, I have something similar and it doesn’t fully work
Copy code
@Composable
fun RemotiCircularProgressIndicator(
    modifier: Modifier = Modifier,
    isLoading: Boolean = true,
    setIsLoading: (Boolean) -> Unit = {}
) {
    if (isLoading) {
        CircularProgressIndicator(
            modifier.then(
                Modifier
                    .fillMaxHeight(0.25f)
                    .fillMaxWidth(0.25f)
            )
        )
    }
}
in my case, that’s always being shown
I call it from another composable with
Copy code
val (isLoading, setIsLoading) = remember { mutableStateOf(viewState.loading) }
RemotiCircularProgressIndicator(
            modifier = Modifier.align(Alignment.CenterHorizontally),
            isLoading = isLoading,
            setIsLoading = setIsLoading,
        )
p
well looks like isLoading is never changing, looks like viewState.loading should be converted to state in a different way.
LiveData.observeAsState()
for example
👍 1
m
mmmm I didn’t think of converting it to a state itself
p
otherwise compose doesn't know that it has to recompose
👍 3
m
thanks for the tip Jose 👍
c
@ppvi do you think there would be a benefit to write a lint check that basically somehow be able to detect "Your type is not observable and so it will never recompose". I've hit this issue myself and so I'm just curious if there's more we can do here.