I have the following screen:
fun ItemsScreen(
viewModel: ItemsViewModel = hiltViewModel()
) {
val showProgressBarState = remember { mutableStateOf(false) }
if (showProgressBarState.value) { ShowProgressBar() }
when(val resource = viewModel.state.value) {
is Loading -> ShowProgressBar() //Works perfectly
is Success -> LazyColumn {
items(
items = resource.data
) { item ->
ItemCard(
item = item
)
}
when(val r = viewModel.s.value) {
is Loading -> showProgressBarState.value = true
is Success -> showProgressBarState.value = false
is Failure -> Log.d(TAG, "Failure")
}
}
is Failure -> Text(
text = r.message,
modifier = Modifier.padding(16.dp)
)
}
}
@Composable
fun ShowProgressBar() {
Column(
modifier = Modifier.fillMaxSize(),
verticalArrangement = Arrangement.Center,
horizontalAlignment = Alignment.CenterHorizontally
) {
CircularProgressIndicator()
}
}
The second "when" is for a delete state. I want when a item is deleted to start the progress bar. It starts but behind the LazyColumn. How to add it in front?
This is what I have in the activity class:
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContent {
Scaffold(
//
) {
ItemsScreen()
}
}
}