accessibilityQuickAction(style:isActive:content:)
Adds a quick action to be shown by the system when active.
Declaration
nonisolated func accessibilityQuickAction<Style, Content>(style: Style, isActive: Binding<Bool>, @ViewBuilder content: () -> Content) -> some View where Style : AccessibilityQuickActionStyle, Content : View
Discussion
The following example shows how to add a quick action to pause and resume a workout, with the prompt style.
@State private var isPaused = false
@State private var isQuickActionActive = false
var body: some View {
WorkoutView(isPaused: $isPaused)
.accessibilityQuickAction(style: .prompt, isActive: $isQuickActionActive) {
Button(isPaused ? "Resume" : "Pause") {
isPaused.toggle()
}
}
}The following example shows how to add a quick action to play and pause music, with the outline style.
@State private var isPlaying = false
@State private var isQuickActionActive = false
var body: some View {
PlayButton(isPlaying: $isPlaying)
.contentShape(.focusEffect, Circle())
.accessibilityQuickAction(style: .outline, isActive: $isQuickActionActive) {
Button(isPlaying ? "Pause" : "Play") {
isPlaying.toggle()
}
}
}