Arjan van Wieringen
12/30/2022, 9:55 AM@Composable fun EventDetail(
selectedEvent: String,
viewModel: EventDetailViewModel = viewModel(selectedEvent),
modifier: Modifier = Modifier
) {
val state by viewModel.state.collectAsState()
EventDetail(
state = state,
onAmountToRecordChange = { raw -> viewModel.updateAmountToRecord(raw) },
onRecordingOffsetChange = { raw -> viewModel.updateRecordingOffset(raw) },
onRecordingStart = { viewModel.startRecording() },
onRecordingStop = { viewModel.stopRecording() },
onTrash = { viewModel.clearRecords() },
modifier = modifier
)
}
The state object is a simple data-class produced in the viewModel (which consists of some hot flows as well). The EventDetail composable gets triggered every frame even though the state doesn't change (the hashcode is consistently the same). Is this due to the collectAsState
implementation? Does that trigger every frame?