Pablo
12/16/2022, 7:55 PMAdel Ayman
12/16/2022, 8:09 PMmattinger
12/16/2022, 10:20 PMmattinger
12/16/2022, 10:24 PMdata class UIState(
val someValue: Int
)
class MyVM: ViewModel() {
private val _state = mutableStateOf(UIState())
val state: State<UIState> get() = _state
fun somethingWasSelected() {
_state.value = _state.value.copy( /* apply mutations here *?)
}
}
@Composable
fun MyViewLayer(uiState: UIState, somethingSelected: () -> Unit) {
// draw your UI here
}
@Composable
fun MyView(viewModel: MyVM) {
MyViewLayer(
viewModel.state.value,
{ viewModel.somethingWasSelected() }
)
}
Colton Idle
12/17/2022, 5:04 PM