1 import ABI49_0_0ExpoModulesCore 2 3 public class HapticsModule: Module { definitionnull4 public func definition() -> ModuleDefinition { 5 Name("ExpoHaptics") 6 7 AsyncFunction("notificationAsync") { (notificationType: NotificationType) in 8 let generator = UINotificationFeedbackGenerator() 9 generator.prepare() 10 generator.notificationOccurred(notificationType.toFeedbackType()) 11 } 12 .runOnQueue(.main) 13 14 AsyncFunction("impactAsync") { (style: ImpactStyle) in 15 let generator = UIImpactFeedbackGenerator(style: style.toFeedbackStyle()) 16 generator.prepare() 17 generator.impactOccurred() 18 } 19 .runOnQueue(.main) 20 21 AsyncFunction("selectionAsync") { 22 let generator = UISelectionFeedbackGenerator() 23 generator.prepare() 24 generator.selectionChanged() 25 } 26 .runOnQueue(.main) 27 } 28 29 enum NotificationType: String, EnumArgument { 30 case success 31 case warning 32 case error 33 toFeedbackTypenull34 func toFeedbackType() -> UINotificationFeedbackGenerator.FeedbackType { 35 switch self { 36 case .success: 37 return .success 38 case .warning: 39 return .warning 40 case .error: 41 return .error 42 } 43 } 44 } 45 46 enum ImpactStyle: String, EnumArgument { 47 case light 48 case medium 49 case heavy 50 toFeedbackStylenull51 func toFeedbackStyle() -> UIImpactFeedbackGenerator.FeedbackStyle { 52 switch self { 53 case .light: 54 return .light 55 case .medium: 56 return .medium 57 case .heavy: 58 return .heavy 59 } 60 } 61 } 62 } 63