Prepare
fun Prepare(preview: () -> Unit = {}, data: @Composable () -> Unit = {}, dialog: @Composable () -> Unit = {}, screen: @Composable () -> Unit)
A utility composable for preparing and loading composable.
This composable facilitates the organization of logic for preview execution, data preparation, and loading of a specific composable.
Example Usage:
Prepare(
preview = {
state = mutableStateOf("For preview")
},
data = {
val viewModel = MVISampleViewModel()
state = viewModel.state.collectAsState()
doAction = { viewModel.doAction(it) }
},
screen = {
doAction(SampleAction.Error)
doAction(SampleAction.SaveString)
doAction(SampleAction.UpdateString)
Surface(
modifier = Modifier.fillMaxSize(),
color = MaterialTheme.colorScheme.background
) {
Greeting(state.value)
}
}
)
Content copied to clipboard
Parameters
preview
A lambda to execute preview-specific logic. It's triggered only when the PreparePreview composable is used. (Optional)
data
A lambda to execute data preparation logic. It's triggered when PreparePreview is not called in the composable. (Optional)
dialog
A lambda to separate composable components related to dialog handling. It's expected to contain composable components. (Optional)
screen
The main composable for the app level.