How it works
AutomaticHoverEffect is the hover effect that lets the system decide how a view should respond when a pointer moves over it, rather than committing you to a specific look like highlight or lift. It is the value behind HoverEffect.automatic, and it exists so you can opt a view into pointer interactions without hard-coding an appearance that might not suit the platform, the device, or the kind of view being decorated. Reach for it whenever you want sensible, platform-appropriate hover feedback on iPadOS, visionOS, or other pointer-aware environments and you would rather defer the exact treatment to SwiftUI.
Apply it through hoverEffect(_:)
You don't construct
AutomaticHoverEffectdirectly; you attach it with thehoverEffect(_:)view modifier, which takes aHoverEffectand applies it when a pointer hovers the view. In the example both theText("Hover over me")and theButton("Tap or Hover")receive their behavior from a single.hoverEffect(...)call.Select it with HoverEffect.automatic
Passing
.automaticis what resolves to anAutomaticHoverEffectinstance, telling SwiftUI to pick the effect for you. Writing.hoverEffect(.automatic)on a view is the entire opt-in: there are no parameters to tune, because choosing the appearance is precisely the responsibility you are handing back to the system.Let the effect adapt to the view it decorates
Because the choice is automatic, the same
.hoverEffect(.automatic)can read differently depending on what it modifies. The decoratedTextwith its.background(.blue.opacity(0.2), in: RoundedRectangle(cornerRadius: 12))and theButtonstyled with.buttonStyle(.borderedProminent)each get hover feedback the system deems suitable for that shape and role.Position it relative to other modifiers
The effect applies to the view as configured up to that point in the modifier chain, so order matters. Placing
.hoverEffect(.automatic)after.background(...)on theText, and after.buttonStyle(.borderedProminent)on theButton, ensures the hover treatment is derived from the fully styled, rounded, padded result.
.hoverEffect(.automatic) on the Text("Hover over me") for .hoverEffect(.highlight) and compare the two views under a pointer to see how the automatic effect's system-chosen treatment differs from a fixed one.Example & preview
Press Run live & edit to compile it in your browser — then edit the Swift on the left and the preview re-renders live.
struct AutomaticHoverEffectDemo: View {
var body: some View {
VStack(spacing: 16) {
Text("Hover over me")
.padding()
.background(.blue.opacity(0.2), in: RoundedRectangle(cornerRadius: 12))
.hoverEffect(.automatic)
Button("Tap or Hover") { }
.buttonStyle(.borderedProminent)
.hoverEffect(.automatic)
}
.padding()
}
}