KScreen
Legacy lifecycle-aware screen wrapper for KViewModel-driven Composables.
KScreen is the original screen wrapper in the Kindling hierarchy. It centralizes the boilerplate required for a standard feature screen:
State collection: Automatically collects the ViewModel's KViewModel.state and provides it to the content block.
Event dispatching: One-shot side effects emitted via KViewModel.events are handled here. If an event implements KDestination, it triggers automatic navigation.
Back press handling: Optional custom handling for the system back button, with automatic focus clearing.
Basic usage
@Composable
fun ProfileScreen(
viewModel: ProfileViewModel,
navController: NavController
) {
KScreen(
viewModel = viewModel,
navController = navController,
onEvent = { state, vm, event ->
when (event) {
is ProfileEvent.ShowToast -> {
// Handle toast
}
}
}
) { state, vm ->
// Screen content
ProfileContent(
name = state.name,
onLogout = vm::onLogoutClick
)
}
}Automatic Navigation
Any event emitted by the ViewModel that implements KDestination is automatically intercepted and used to navigate via the provided navController.
Parameters
The KViewModel instance driving this screen.
NavController used for automatic navigation when KDestination events occur.
Optional back press handler. Receives the latest state and ViewModel. Focus is cleared automatically before this callback is invoked.
Handler for non-navigation events emitted by viewModel. Receives the latest state, the ViewModel, and the event object.
The main UI content of the screen.
Type Parameters
UI state type produced by viewModel.
ViewModel type, must extend KViewModel<State>.