Listener Action Scripts in Rive — Detecting Double Clicks
Rive's listener action scripts let you run custom logic when a listener fires in a state machine. One practical use case: distinguishing a double click from a single click, which is tricky to do with standard listeners alone.
Here's how the double click detector works:
The script uses three properties in its type definition: a threshold number (default 0.3 seconds), a clicked trigger, and a doubleClicked trigger pulled from the view model, plus a lastClickTime number initialized to -1.
In init, it grabs the view model and resolves both triggers by name.
In performAction, it checks that the incoming action is a pointer event, then captures the current time. It compares lastClickTime against the threshold:
• If lastClickTime >= 0 and time elapsed ≤ threshold → fires doubleClicked, resets lastClickTime to -1
• Otherwise → fires clicked, sets lastClickTime to now
Because threshold is exposed as a script input, you can override it per-listener without touching the script itself. In the demo it's set to 0.3s by default, adjustable to 0.5s or whatever feels right for your use case.
To wire it up: select your listener target shape, add a listener, set the event to Click, choose the listener action script type, and pick your script. The threshold input appears inline. Then in the state machine, use the Any State node with clicked and doubleClicked trigger conditions to drive transitions to whichever animations you want.
The video shows this applied to a bubble animation — single click triggers a grow-and-shrink, double click triggers a pop.