StatefulComposable

fun <T : Any> StatefulComposable(state: UiState<T>, onShowSnackbar: suspend (String, SnackbarAction, Throwable?) -> Boolean, content: @Composable (T) -> Unit)

A centralized composable wrapper that handles loading states, error handling, and content display.

This composable implements the standard UI state pattern used throughout the application:

  • Displays content based on the current state data

  • Shows an overlay loading indicator when UiState.loading is true

  • Automatically displays errors via snackbar when UiState.error contains an unhandled exception

Usage Example

@Composable
fun FeatureRoute(
onShowSnackbar: suspend (String, SnackbarAction, Throwable?) -> Boolean,
viewModel: FeatureViewModel = hiltViewModel()
) {
val uiState by viewModel.uiState.collectAsStateWithLifecycle()

StatefulComposable(
state = uiState,
onShowSnackbar = onShowSnackbar
) { screenData ->
FeatureScreen(
screenData = screenData,
onAction = viewModel::handleAction
)
}
}

Parameters

T

The type of the screen data. Must be a non-nullable type.

state

The current UI state containing data, loading flag, and error events.

onShowSnackbar

Callback to display error messages. Returns true if the error was handled.

content

The screen content to display. Receives the current data from state.

See also

Samples

dev.atick.feature.home.ui.home.HomeScreendev.atick.feature.auth.ui.signin.SignInScreen