Presenting ActionSheet views
The SwiftUI ActionSheet and Alert views are both used to request additional information from the user by interrupting the normal flow of the app to display a message. ActionSheet provides the user with additional choices related to an action they are currently taking, whereas the Alert view informs the user if something unexpected happens or they are about to perform an irreversible action.
In this recipe, we will create an action sheet that gets displayed when the user taps some text in the view.
Getting ready
Create a SwiftUI app named PresentingActionSheet.
How to do it
We will implement an action sheet by adding a .actionSheet() modifier to a view as well as a trigger that changes the value of a variable used to determine if the sheet is shown or not. The steps are as follows:
- Below the
ContentViewstruct but above thebodyvariable, add an@Statevariable to store the state of the action sheet:@State private var showSheet =...