Member-only story
How to Handle Tap Gestures on Widgets?
This article is originally published at swiftsenpai.com
If you’ve interacted with widgets before, you may have noticed that they all have a default behavior when tapped, which is to launch the host app. However, it’s important to know that this behavior can actually be customized based on the widget configuration.
Moreover, it’s worth noting that not all SwiftUI components will work as expected in a widget. For instance, Buttons no longer work, and Links only work under specific conditions.
If you’re interested in learning more about these topics, keep reading!
How Do Tap Gestures Work on Widgets?
Even though widgets are essentially SwiftUI views under the hood, they have their own quirks when it comes to handling tap gestures. When a widget detects taps, it will launch its host app, and this behavior cannot be altered. However, we can customize what happens after the app launches, in a similar way to how we use deep links to customize app actions after launch.
These are the quirks that we need to be aware of:
- SiwftUI
Button
does not work on widgets - SwiftUI
Link
is supported on thesystemMedium
andsystemLarge
widget families - SwiftUI
Link
is not…