A delightful Swift library for adding micro-interactions to your iOS apps with haptic feedback, sounds, and animations.
- 🎯 Easy Integration - Simple API with minimal setup required
- 📱 Haptic Feedback - Support for all iOS haptic types including custom patterns
- 🔊 Sound Effects - Built-in sounds with fallback to system sounds
- ✨ Animations - Beautiful animations including bounce, shake, pulse, and more
- 🎨 Themes - Pre-built themes and full customization support
- ♿️ Accessibility - Respects system settings and VoiceOver
- 🔋 Battery Conscious - Adaptive feedback and battery-saving mode
- 📊 Analytics Ready - Built-in analytics handler support
- 🐛 Debug Mode - Visual indicators for development
Add SwiftMicroInteractions to your project through Xcode:
- File → Add Package Dependencies
- Enter:
https://github.com/dawncr0w/SwiftMicroInteractions - Click Add Package
Or add to your Package.swift:
dependencies: [
.package(url: "https://github.com/dawncr0w/SwiftMicroInteractions", from: "1.0.1")
]Coming soon - For now, please use Swift Package Manager
Coming soon - For now, please use Swift Package Manager
Note: Version 1.0.1 includes improved compatibility for non-SPM integration methods
import SwiftMicroInteractions
// Basic configuration (optional - has sensible defaults)
SwiftMicroInteractions.configure { config in
config.isHapticEnabled = true
config.isSoundEnabled = true
config.defaultIntensity = 0.7
}// Simple tap interaction
button.addMicroInteraction(.tap)
// With completion
button.addMicroInteraction(.success) {
print("Success animation completed!")
}
// Advanced configuration
button.addMicroInteraction(.tap)
.withDelay(0.1)
.withIntensity(0.8)
.withCondition { return self.isEnabled }
.withCompletion { print("Tap completed") }
// Programmatic trigger
view.triggerMicroInteraction(.success)// Basic usage
Button("Save") {
// Action
}
.microInteraction(.tap)
// Toggle with interaction
Toggle("Enable Feature", isOn: $isEnabled)
.microInteraction(.toggle)
// Custom trigger
Text("Hello")
.microInteraction(.pulse, trigger: .onAppear)
// Manual trigger with binding
@State private var showSuccess = false
Button("Submit") {
// Perform action
showSuccess = true
}
.microInteraction(.success, trigger: .manual)- Basic:
tap,longPress,swipe - States:
success,failure,warning,loading - Actions:
toggle,refresh,delete,favorite,share
// Create custom interaction
let customInteraction = MicroInteraction.custom(
name: "powerUp",
feedback: .combined([
.haptic(.heavy),
.sound(.custom(fileName: "powerup")),
.animation(.elastic)
])
)
view.addMicroInteraction(customInteraction)// Apply pre-built themes
SwiftMicroInteractions.applyTheme(DefaultTheme())
SwiftMicroInteractions.applyTheme(SubtleTheme())
SwiftMicroInteractions.applyTheme(EnergeticTheme())struct MyCustomTheme: MicroInteractionTheme {
var tapFeedback: FeedbackType {
.combined([.haptic(.medium), .sound(.pop)])
}
var successColor: UIColor { .systemGreen }
var animationDuration: TimeInterval { 0.35 }
// ... implement other properties
}
SwiftMicroInteractions.applyTheme(MyCustomTheme())// Quick presets for common scenarios
SwiftMicroInteractions.Presets.applySubtle() // Minimal feedback
SwiftMicroInteractions.Presets.applyEnergetic() // Strong feedback
SwiftMicroInteractions.Presets.applySilent() // No sounds
SwiftMicroInteractions.Presets.applyAccessible() // Accessibility-friendly
SwiftMicroInteractions.Presets.applyBatterySaving() // Reduced battery usageSwiftMicroInteractions.setAnalyticsHandler { interaction in
Analytics.track("micro_interaction", properties: [
"type": interaction.name,
"timestamp": Date()
])
}// Enable visual indicators for all interactions
SwiftMicroInteractions.enableDebugMode(true)The library automatically reduces feedback intensity for frequently used interactions to prevent user fatigue.
// Enable/disable adaptive feedback
SwiftMicroInteractions.configure { config in
config.isAdaptiveFeedbackEnabled = true
}// Preload custom sounds
SwiftMicroInteractions.preloadSound(fileName: "myCustomSound")
// Use in interaction
.sound(.custom(fileName: "myCustomSound"))button.addTapInteraction()
button.showSuccess()
button.showFailure()switch.addToggleInteraction()slider.addSlideInteraction()textField.addEditingInteraction()refreshControl.addRefreshInteraction()- Use Sparingly - Micro-interactions should enhance, not overwhelm
- Be Consistent - Use the same interactions for similar actions
- Respect User Preferences - Always respect system accessibility settings
- Test on Device - Haptics don't work in simulator
- Consider Context - Reduce feedback in quiet environments
Check out the included example app for comprehensive demonstrations:
cd Example/ExampleApp
open ExampleApp.xcodeproj- iOS 13.0+
- Swift 5.7+
- Xcode 14.0+
SwiftMicroInteractions automatically uses iOS system sounds, so no additional sound files are required. The library maps interactions to appropriate system sounds:
- tap/click → Keyboard tap sound
- pop → SMS received sound
- success → Begin recording sound
- error/failure → SMS sent sound
- warning → Keyboard delete sound
- whoosh → Mail sent sound
You can add your own sound files by including .caf files in your app bundle:
- Place sound files in your app's Resources folder
- Use the same names as above (e.g.,
tap.caf,success.caf) - The library will automatically use your custom sounds when available
We welcome contributions! Please see CONTRIBUTING.md for details.
SwiftMicroInteractions is released under the MIT license. See LICENSE for details.
- Inspired by the micro-interactions concept from Dan Saffer
- Built with love for the iOS community
- 🐛 Fixed Bundle.module compatibility for non-SPM integrations (CocoaPods, Carthage)
- 🔒 Improved thread safety with main thread assertions
- 🛡️ Enhanced associated object key safety
- 🎭 Fixed SwiftUI onDisappear animation handling
- 🧪 Added comprehensive test coverage for all components
- 📦 Better support for various integration methods
- 🎉 Initial release with full feature set
- ✅ Core functionality implemented and tested
- ✅ UIKit and SwiftUI support
- ✅ Comprehensive test suite with edge case coverage
- ✅ Example app included
- ✅ Documentation complete
- ✅ Thread-safe and production ready
- ✅ Compatible with SPM, CocoaPods, and Carthage
Made with ❤️ by the SwiftMicroInteractions Contributors