TimeCapsuleOwner
Contract implemented by a screen's state holder (typically a ViewModel) so its state history can be recorded and restored by the TimeCapsule module.
Usage
class CounterViewModel : ViewModel(), TimeCapsuleOwner<CounterState> {
private val _state = MutableStateFlow(CounterState())
override val state: StateFlow<CounterState> = _state.asStateFlow()
override fun restoreState(state: CounterState) {
_state.value = state
}
}Content copied to clipboard
Restoring state is the integrator's responsibility to use safely: DevView does not guarantee the host app keeps working correctly after a state is pushed back into a running screen out of band.
States containing TextFieldState properties can use the TimeCapsuleEffect overload accepting property references to capture and restore their text and selection. Other mutable objects are retained by reference, not deep-copied.
See also
Properties
Functions
Link copied to clipboard
Pushes state back into the screen, restoring it as the current state.