Skip to content

Instantly share code, notes, and snippets.

@catalinghita8
Last active July 11, 2021 11:52
Show Gist options
  • Save catalinghita8/6a69c8328bd214c7f6fd2b9922e791d4 to your computer and use it in GitHub Desktop.
Save catalinghita8/6a69c8328bd214c7f6fd2b9922e791d4 to your computer and use it in GitHub Desktop.
@Composable
fun FoodCategoriesScreen(
state: FoodCategoriesContract.State,
effectFlow: Flow<FoodCategoriesContract.Effect>?,
onEventSent: (event: FoodCategoriesContract.Event) -> Unit,
onNavigationRequested: (navigationEffect: FoodCategoriesContract.Effect.Navigation) -> Unit
) {
// Listen for side effects from the VM
LaunchedEffect(LAUNCH_LISTEN_FOR_EFFECTS) {
effectFlow?.onEach { effect ->
when (effect) {
is FoodCategoriesContract.Effect.ToastDataWasLoaded -> { ... }
is FoodCategoriesContract.Effect.Navigation.ToCategoryDetails ->
onNavigationRequested(effect)
}
}?.collect()
}
Box {
FoodCategoriesList(foodItems = state.categories, onItemClicked = { itemId ->
onEventSent(FoodCategoriesContract.Event.CategorySelection(itemId))
})
if (state.isLoading)
LoadingBar()
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment