TimeCapsuleOwner

interface TimeCapsuleOwner<S : Any>

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
}
}

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.

See also

Properties

Link copied to clipboard
abstract val state: StateFlow<S>

The screen's current state, observed to build the recorded timeline.

Functions

Link copied to clipboard
abstract fun restoreState(state: S)

Pushes state back into the screen, restoring it as the current state.