Skip to content

Feature: Add SwiftUI ViewModifier for shake animation#6

Open
haaakon wants to merge 4 commits into
masterfrom
feature/swiftui-view-modifier
Open

Feature: Add SwiftUI ViewModifier for shake animation#6
haaakon wants to merge 4 commits into
masterfrom
feature/swiftui-view-modifier

Conversation

@haaakon
Copy link
Copy Markdown
Owner

@haaakon haaakon commented May 11, 2026

Summary

  • Adds ShakeEffect — a GeometryEffect that drives a sine-wave horizontal translation, matching the UIKit version's back-and-forth oscillation behaviour.
  • Adds ShakeModifier — a ViewModifier wrapping ShakeEffect. Increment its trigger: Int to start a new shake. Accepts an optional accessibilityAnnouncement that is posted via UIAccessibility when VoiceOver is active (mirrors postAccessabilityNotification in the UIKit version).
  • Adds a .shake(trigger:accessibilityAnnouncement:) convenience extension on View so usage stays a single line.
  • Adds Package.swift for Swift Package Manager distribution alongside the existing CocoaPods podspec.
  • Updates README.md with a full SwiftUI usage section (basic, VoiceOver, and full button-driven example).

Usage

// Basic – increment trigger to shake
TextField("Username", text: $username)
    .shake(trigger: errorCount)

// With VoiceOver announcement
TextField("Username", text: $username)
    .shake(trigger: errorCount,
           accessibilityAnnouncement: "Username field is required")

Test plan

  • Build the package with swift build (requires Xcode 13+ / swift-tools-version 5.5)
  • Add SingleLineShakeAnimation via SPM in a SwiftUI project and verify .shake(trigger:) compiles
  • Tap a button that increments errorCount and confirm the target view shakes visually
  • Enable VoiceOver, increment trigger, confirm announcement is read and visual shake still fires
  • Verify the existing UIKit UIView.shake(_:) API is unaffected

haaakon added 4 commits May 11, 2026 13:58
Add ShakeModifier (and a .shake(trigger:) View extension) that mirrors the
UIKit UIView shake behaviour using a GeometryEffect-based approach, including
VoiceOver accessibility announcement support. Also introduce Package.swift for
Swift Package Manager distribution.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant