Rive 101 logoRive 101
β„Ή AboutπŸ“‹ ChangelogδΈ­
0%
Progress0/88
8.13

List Index

10m 55s
Rive 101 - List Index

This course tackles an advanced design-to-handoff challenge: enabling nested components to sense their own position within dynamic lists. By introducing the List Index view model property, Rive assigns a native, read-only integer ID to each nested component instance. The core business benefit is that designers can completely bypass complex manual scripting, using the List Index directly as a state machine condition to achieve tailored effects like "single-item color coding" or "global mutual exclusion (radio-button selection mechanics)" for large-scale production lists.

  • Zero-Based Index System: Any component embedded within an Artboard List features a read-only List Index starting at 0 for the first item, followed sequentially by 1, 2, 3, etc. This value is handled implicitly by the parent list container and cannot be edited manually.
  • Mathematical Logic for Mutual Exclusion: Radio selection relies on comparing local component properties against global state parameters using State Machine conditions:
    • Transition into active state: $$index num = List Index$$
    • Transition out of active state: $$index num \neq List Index$$

By manipulating a single global index num variable via listeners, changing its value forces all other unselected instances to detect an inequality (β‰ ) and return to idle.

  • Initialization Boundary Protection: In complex state setups, state machine tracker variables should never default blindly to 0 if 0 represents a valid interactive index. Setting it to an out-of-bounds boundary constant (like -1 here) safeguards the file against unintended triggers on load.
  • Preview Bound Values: When working with data-bound lists, elements inside the list container appear blank on the canvas by default until the state machine is initialized. Turning on the "Preview Bound Values" toggle solves this by rendering layout instances statically during assembly.