hoverEffectDisabled(_:)
Disables this hover effect.
Declaration
func hoverEffectDisabled(_ isDisabled: Bool = true) -> some CustomHoverEffect
Parameters
- isDisabled:
A Boolean value that determines whether the hover effect is disabled or not. Specifying
truetakes precedence overfalse. Default:true.
Return Value
A conditionally disabled hover effect.
Discussion
Use hoverEffectDisabled(_:) to prevent a hover effect from becoming active. When an effect is disabled, all contained effects are also disabled and cannot be re-enabled.
In the following example, the scale effect is disabled if the accessibilityReduceMotion setting is enabled:
struct ScaleAndFadeEffect: CustomHoverEffect {
@Environment(\.accessibilityReduceMotion) var accessibilityReduceMotion
func body(content: Content) -> some CustomHoverEffect {
content.hoverEffect { effect, isActive, _ in
effect.scaleEffect(!isActive ? 0.95 : 1.05)
}
.hoverEffectDisabled(accessibilityReduceMotion)
.hoverEffect { effect, isActive, _ in
effect.opacity(!isActive ? 0.9 : 1)
}
}
}