Skip to content

Commit 916000e

Browse files
committed
feat(utils): ⚡ add useHaptics hook returning functions for specific haptics
1 parent 9077325 commit 916000e

File tree

2 files changed

+34
-0
lines changed

2 files changed

+34
-0
lines changed

src/utils/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,5 @@ export * from "./isUndefined";
1111
export * from "./react";
1212
export * from "./styleAdapter";
1313
export * from "./types";
14+
export * from "./useHaptic";
1415
export * from "./useScaleAnimation";

src/utils/useHaptic.ts

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import { useCallback, useMemo } from "react";
2+
import * as Haptics from "expo-haptics";
3+
4+
export const hapticOptions = {
5+
enableVibrateFallback: true,
6+
ignoreAndroidSystemSettings: true,
7+
};
8+
9+
export const useHaptic = () => {
10+
const hapticHeavy = useCallback(
11+
() => Haptics.impactAsync(Haptics.ImpactFeedbackStyle.Heavy),
12+
[],
13+
);
14+
const hapticMedium = useCallback(
15+
() => Haptics.impactAsync(Haptics.ImpactFeedbackStyle.Medium),
16+
[],
17+
);
18+
const hapticLight = useCallback(
19+
() => Haptics.impactAsync(Haptics.ImpactFeedbackStyle.Light),
20+
[],
21+
);
22+
const hapticSelection = useCallback(() => Haptics.selectionAsync(), []);
23+
const hapticHandlers = useMemo(() => {
24+
return {
25+
hapticLight,
26+
hapticMedium,
27+
hapticHeavy,
28+
hapticSelection,
29+
};
30+
}, [hapticHeavy, hapticLight, hapticMedium, hapticSelection]);
31+
32+
return hapticHandlers;
33+
};

0 commit comments

Comments
 (0)