Contents

hoverEffect(_:in:isEnabled:)

Applies this effect in parallel with the given effect.

Declaration

func hoverEffect(_ effect: some CustomHoverEffect, in group: HoverEffectGroup? = nil, isEnabled: Bool = true) -> some CustomHoverEffect

Parameters

Discussion

Use hoverEffect(_:) to combine two effects into a single effect that applies both effects in parallel. Modifiers like hoverEffectDisabled(_:) applied to effect will not apply to this effect.

For example, in the following effect only the ScaleUpEffect is disabled, since modifiers applied to that effect are applied independently.

struct FadeAndScaleEffect: CustomHoverEffect {
    @Environment(\.accessibilityReduceMotion) var accessibilityReduceMotion
    func body(content: Content) -> some CustomHoverEffect {
        content
            .hoverEffect { effect, isActive, _ in
                effect.opacity(isActive ? 1 : 0.9)
            }
            .hoverEffect(
                ScaleUpEffect().hoverEffectDisabled(accessibilityReduceMotion)
            )
    }
}

struct ScaleUpEffect: CustomHoverEffect {
    func body(content: Content) -> some CustomHoverEffect {
        content.hoverEffect { effect, isActive, _ in
            effect.scaleEffect(isActive ? 1.05 : 1.0)
        }
    }
}
  • Returns a new effect that applies both effects in parallel.

See Also

Creating custom hover effects