Triggers
When your steps run: tapped, shown, loading, a value changing and more.
A trigger is the When at the top of a view's Actions tab: what makes its steps run. A view can have several, each with its own steps.
#Pick a When
- Select the view and open the Inspector's Actions tab.
- Tap the WHEN card at the top. The menu lists every When this view offers. A dot (•) marks the ones that already have steps.
- Pick one, then tap Add action to give it steps. See How steps run.
To clear the current When, open the same menu and choose Remove These Actions. Only that When's steps go; the others stay.
#Several Whens on one view
Each When has its own steps, and a view can use as many as it needs. A list of orders might load them When Loading and load them again When Pulled to Refresh. Put the shared steps in a reusable action and run it from both. Switch between a view's Whens with the WHEN card; the dots show which ones have steps.
Most Whens are modifiers too. Picking one and adding a step also adds a modifier of the same name to the view, under the Style tab's All modifiers. That's where a When's extra settings are: Watch and Run at Start for When a Value Changes, Run Again When for When Loading. Removing the modifier there removes the When and its steps. A Button's When Tapped and a Slider's When Dragging Starts or Stops are the exceptions: they're the view's own settings.
#Which views offer which
Every view offers the general Whens below, from When Tapped to When Apple Pencil Is Squeezed. The menu doesn't narrow them down by the kind of view, so put each one where it can happen:
- When Tapped on a Button runs the button's own action. On any other view, it makes the view tappable.
- When Return Is Pressed belongs on a Text Field or a Password Field. On a view that holds several fields, like a Form, Return in any of them runs it.
- When Pulled to Refresh belongs on a List or a Scroll Area: they're what people pull down.
- When Hovered needs a trackpad, a mouse or an Apple Pencil that hovers.
- A Slider adds When Dragging Starts or Stops.
#The screen's own Whens
The screen has Whens of its own. Tap an empty part of the canvas, outside the device, or the screen's row at the top of Layers: the Inspector shows the screen, with Screen under its title. Its Actions tab offers When Shown, When Loading, When Hidden and When a Value Changes. A screen's When Loading is the place to load what the whole screen shows.
#Values a When gives its steps
Some Whens hand their steps a value named event, which formulas in those steps can read:
| When | event |
|---|---|
| When a Value Changes | event.oldValue is the value before, event.newValue the value now. |
| When Hovered | true while the pointer is over the view, false when it leaves. |
| When Dragging Starts or Stops | true while the knob is held, false when it's let go. |
| When Apple Pencil Is Squeezed | event.phase is began, changed or ended. |
Here's every When, and where it works:
#When Tapped
When the view is tapped or clicked.
Works on a Button's own Action setting; any view, through the When Tapped modifier.
#When Long-Pressed
When the view is touched and held.
Works on any view, through the When Long-Pressed modifier.
#When Shown
Each time the view appears on screen.
Works on any view, through the When Shown modifier.
#When Loading
When the view appears; stops if it disappears before finishing. The right place for API calls.
Works on any view, through the When Loading modifier.
#When Hidden
When the view leaves the screen.
Works on any view, through the When Hidden modifier.
#When a Value Changes
When the value in Watch changes, from typing, a slider, an action…
Works on any view, through the When a Value Changes modifier.
#When Return Is Pressed
When Return is pressed in a text field.
Works on any view, through the When Return Is Pressed modifier.
#When Pulled to Refresh
When a List or Scroll Area is pulled down. The spinner stays until the steps finish.
Works on any view, through the When Pulled to Refresh modifier.
#When Dragging Starts or Stops
When a slider's knob is grabbed or let go.
Works on a Slider's own When dragged setting.
#When Hovered
When a trackpad pointer or an Apple Pencil hovers over the view, and when it leaves.
Works on any view, through the When Hovered modifier.
#When Apple Pencil Is Double-Tapped
When the side of an Apple Pencil is double-tapped.
Works on any view, through the When Apple Pencil Is Double-Tapped modifier.
#When Apple Pencil Is Squeezed
When an Apple Pencil Pro is squeezed.
Works on any view, through the When Apple Pencil Is Squeezed modifier.