UNPKG

2.6 kBJavaScriptView Raw
1import { NativeModules, Platform, Vibration } from 'react-native';
2const VIBRATION_DURATION_MS = 100;
3/**
4 * Notification Feedback Type
5 * The type of notification feedback generated by a UINotificationFeedbackGenerator object.
6 * https://developer.apple.com/documentation/uikit/uinotificationfeedbacktype
7 */
8export var NotificationFeedbackType;
9(function (NotificationFeedbackType) {
10 /**
11 * A notification feedback type indicating that a task has completed successfully
12 */
13 NotificationFeedbackType["Success"] = "success";
14 /**
15 * A notification feedback type indicating that a task has produced a warning
16 */
17 NotificationFeedbackType["Warning"] = "warning";
18 /**
19 * A notification feedback type indicating that a task has failed
20 */
21 NotificationFeedbackType["Error"] = "error";
22})(NotificationFeedbackType || (NotificationFeedbackType = {}));
23/**
24 * Impact Feedback Style
25 * The mass of the objects in the collision simulated by a UIImpactFeedbackGenerator object.
26 * https://developer.apple.com/documentation/uikit/uiimpactfeedbackstyle
27 */
28export var ImpactFeedbackStyle;
29(function (ImpactFeedbackStyle) {
30 /**
31 * A collision between small, light user interface elements
32 */
33 ImpactFeedbackStyle["Light"] = "light";
34 /**
35 * A collision between moderately sized user interface elements
36 */
37 ImpactFeedbackStyle["Medium"] = "medium";
38 /**
39 * A collision between large, heavy user interface elements
40 */
41 ImpactFeedbackStyle["Heavy"] = "heavy";
42})(ImpactFeedbackStyle || (ImpactFeedbackStyle = {}));
43/**
44 * Triggers notification feedback.
45 */
46export function notification(type = NotificationFeedbackType.Success) {
47 if (Platform.OS === 'ios') {
48 NativeModules.ExponentHaptic.notification(type);
49 }
50 else {
51 console.warn('`Expo.Haptic` is only available on iOS');
52 Vibration.vibrate(VIBRATION_DURATION_MS, false);
53 }
54}
55/**
56 * Triggers impact feedback.
57 */
58export function impact(style = ImpactFeedbackStyle.Medium) {
59 if (Platform.OS === 'ios') {
60 NativeModules.ExponentHaptic.impact(style);
61 }
62 else {
63 console.warn('`Expo.Haptic` is only available on iOS');
64 Vibration.vibrate(VIBRATION_DURATION_MS, false);
65 }
66}
67/**
68 * Triggers selection feedback.
69 */
70export function selection() {
71 if (Platform.OS === 'ios') {
72 NativeModules.ExponentHaptic.selection();
73 }
74 else {
75 console.warn('`Expo.Haptic` is only available on iOS');
76 Vibration.vibrate(VIBRATION_DURATION_MS, false);
77 }
78}
79//# sourceMappingURL=Haptic.js.map
\No newline at end of file