🖼️Composable

A Dashboard Composable Screen example

@Composable
fun DashboardScreen(
    uiState: DashboardUiState,
    handleEvent: (DashboardUiEvent) -> Unit,
    modifier: Modifier = Modifier
) {
    LaunchedActionEffect(uiState) { action: DashboardUiAction ->
        when (action) {
            DashboardUiAction.NavigateToNext -> {}
        }
    }

    when (uiState.state) {
        is DashboardUiState.ContentState.Loading -> DashboardLoadingContent()
        is DashboardUiState.ContentState.Error -> DashboardErrorContent()
        is DashboardUiState.ContentState.Content -> DashboardContent(uiState.state)
    }
}

@Composable
fun DashboardLoadingContent(
    modifier: Modifier = Modifier
) {
    // Do something with loading
}

@Composable
fun DashboardErrorContent(
    modifier: Modifier = Modifier
) {
    // Do something with error
}

@Composable
fun DashboardContent(
    content: DashboardUiState.ContentState.Content,
    modifier: Modifier = Modifier
) { 
    // Do something with content
}

Note that as DashboardUiState implements Actionable , we need to use the LaunchedActionEffect function to consume only once the UiAction:

LaunchedActionEffect(uiState) { action: DashboardUiAction ->
    when (action) {
        DashboardUiAction.NavigateToNext -> {}
    }
}

Last updated