Modifiers
onAppear
Adds an onAppear modifier that calls a function when the view appears.
onAppear(handler)
| Parameter | Type | Description |
|---|---|---|
handler | () => void | Function to call when the view appears. |
Adds an onAppear modifier that calls a function when the view appears.
Returns: ModifierConfig
See: Official SwiftUI documentation.
Works with
You can add onAppear to any view. It changes what you see on 33 of the 39 components.
Needs care
It works on these components, but not in the way that you may expect.
| Component | What to know |
|---|---|
| BottomSheet | Runs for the anchor, not for the sheet. To know when the sheet opens, put it on a view in the sheet content. |
| Alert | Runs for the trigger, not for the alert. |
| ConfirmationDialog | Runs for the trigger, not for the dialog. |
| Popover | Runs for the trigger, not for the popover. To know when the popover opens, put it on a view in Popover.Content. |
| TabView | Runs for the whole tab view, not for one tab. Put it on the content of a tab. |
No visible effect
These components accept it, but you see no change.
| Component | Why nothing happens |
|---|---|
| Spacer | In SDK 57, Spacer does not send modifier events to JavaScript, so the handler does not run. |
| Divider | In SDK 57, Divider does not send modifier events to JavaScript, so the handler does not run. |
| Slider | In SDK 57, Slider does not send modifier events to JavaScript, so the handler does not run. |
| Menu | In SDK 57, Menu does not send modifier events to JavaScript, so the handler does not run. |
| ContextMenu | In SDK 57, ContextMenu does not send modifier events to JavaScript, so the handler does not run. |
| AccessoryWidgetBackground | In SDK 57, AccessoryWidgetBackground does not send modifier events to JavaScript, so the handler does not run. |
Sources
The original Expo docs for this page:
- onAppear (Modifiers) (
source-of-truth/versions/v57.0.0/sdk/ui/swift-ui/modifiers.md)