CustomHoverEffect

A type that represents how a view should change when a pointer hovers over a view, or when someone looks at the view.

ProtocoliOS 18.0+tvOS 18.0+visionOS 2.0+CustomHoverEffect in SwiftUI

Declaration

React
type CustomHoverEffect =
  | 'automatic'
  | 'highlight'
  | 'lift'
  | AutomaticHoverEffect
  | HighlightHoverEffect
  | HoverEffect
  | LiftHoverEffect;
Swift
protocol CustomHoverEffect

Pass a literal, or build one with SwiftUI.CustomHoverEffect from import { SwiftUI } from 'swiftui-react-native'.

Type properties

  • 'automatic'SwiftUI.CustomHoverEffect.automatic

    The default hover effect based on the surrounding context.

  • 'highlight'SwiftUI.CustomHoverEffect.highlight

    A hover effect that highlights views using a light source to indicate position.

  • A hover effect that slides the pointer under the view and disappears as the view scales up and gains a shadow.

Overview

Custom hover effects apply their inactive values when the effect is inactive, and their active values when the effect is active. For example, the following effect causes a view to be partially transparent when inactive, but animate to fully opaque when active:

struct FadeInHoverEffect: CustomHoverEffect {
    func body(content: Content) -> some CustomHoverEffect {
        content.hoverEffect { effect, isActive, proxy in
            effect.animation(.easeOut) {
                $0.opacity(isActive ? 1 : 0.5)
            }
        }
    }
}

This effect can be applied to a view using the hoverEffect(_:) modifier:

Color.red
    .hoverEffect(FadeInHoverEffect())

Hover effects do not affect a view's layout, and may be applied to a view out-of-process. Therefore an effect's current phase may not be visible within your app.

From Apple’s SwiftUI documentation. Code samples there are Swift.

Used by

See also

More in Gestures and input.