View ModifieriOS 17.0+macOS 14.0+tvOS 17.0+watchOS 10.0+visionOS 26.0+
Overloads
4 ways to call compose().sensoryFeedback(). Each is one SwiftUI overload, picked by the arguments you pass.
compose().sensoryFeedback<T>(
feedback: SwiftUI.SensoryFeedback,
options: {
trigger: T;
}
)nonisolated func sensoryFeedback<T>(
_ feedback: SensoryFeedback,
trigger: T
) -> some View
where T : EquatableParameters
feedback*SwiftUI.SensoryFeedbackWhich type of feedback to play.
options.trigger*TA value to monitor for changes to determine when to play.
Discussion
For example, you could play feedback when a state value changes:
struct MyView: View {
@State private var showAccessory = false
var body: some View {
ContentView()
.sensoryFeedback(.selection, trigger: showAccessory)
.onLongPressGesture {
showAccessory.toggle()
}
if showAccessory {
AccessoryView()
}
}
}See also
More in Input and interaction.
- allowsHitTestingConfigures whether this view participates in hit test operations.
- allowsWindowActivationEventsConfigures whether gestures in this view hierarchy can handle events that activate the containing window.
- buttonRepeatBehaviorSets whether buttons in this view should repeatedly trigger their actions on prolonged interactions.
- disabledAdds a condition that controls whether someone can interact with this view.
- handlesExternalEventsSpecifies the external events that the view's scene handles if the scene is already open.
- helpAdds help text to a view using a localized string resource that you provide.
- invalidatableContentMark the receiver as their content might be invalidated.
- keyboardShortcutAssigns a keyboard shortcut to the modified control.
- scrollClipDisabledSets whether a scroll view clips its content to its bounds.
- scrollDisabledDisables or enables scrolling in scrollable views.
- scrollDismissesKeyboardConfigures the behavior in which scrollable content interacts with the software keyboard.
- userActivityAdvertises a user activity type.