TimeCapsuleEffect
Records owner's state history for as long as this composable stays in composition, and exposes it to the TimeCapsule module for inspection and restore.
Call this once per screen, inside the screen's top-level composable. The recorded history is scoped to this composition: navigating away from the screen disposes it, and the timeline starts empty the next time the screen is composed.
Restoring a state is the integrator's risk — DevView does not guarantee the host app keeps working correctly after TimeCapsuleOwner.restoreState is invoked out of band.
Usage
@Composable
fun CounterScreen(viewModel: CounterViewModel) {
TimeCapsuleEffect(owner = viewModel)
// ...screen content
}Parameters
The screen's state holder, typically a ViewModel.
Produces the one-line description shown for each recorded entry. Defaults to state.toString().
Identifies the recorded screen in the Time Capsule header (e.g. "Recording CounterViewModel"). Defaults to owner's class name, which is null for an anonymous class — pass this explicitly in that case.
Maximum number of retained entries; the oldest is dropped once reached.
See also
Records screen state and the text and selection of explicitly declared TextFieldState properties, including edits that do not emit a new TimeCapsuleOwner.state.
TimeCapsuleEffect(
owner = viewModel,
textFields = listOf(FormState::name, FormState::description)
)Each entry captures detached text and selection values. Restore edits the fields belonging to the saved screen state before passing that state to TimeCapsuleOwner.restoreState. Other mutable objects in the screen state are not copied. Keyboard composition, focus, and undo history are not restored. Snapshot observation may coalesce rapid edits; this records state history, not every input event.
Recording ends when this effect leaves composition. Changing owner or textFields starts a new timeline. Restore and field editing must run on the UI thread.
Parameters
The screen's state holder, typically a ViewModel.
Properties of the screen state to observe and restore. Names must be unique.
A pure, read-only function producing the screen label. Captured text fields are displayed separately using their property names.
Screen name shown in the header; defaults to the owner's class name.
Maximum number of retained entries.