@umituz/react-native-haptics 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +22 -0
- package/README.md +122 -0
- package/lib/domain/entities/Haptic.d.ts +41 -0
- package/lib/domain/entities/Haptic.d.ts.map +1 -0
- package/lib/domain/entities/Haptic.js +31 -0
- package/lib/domain/entities/Haptic.js.map +1 -0
- package/lib/index.d.ts +157 -0
- package/lib/index.d.ts.map +1 -0
- package/lib/index.js +162 -0
- package/lib/index.js.map +1 -0
- package/lib/infrastructure/services/HapticService.d.ts +43 -0
- package/lib/infrastructure/services/HapticService.d.ts.map +1 -0
- package/lib/infrastructure/services/HapticService.js +101 -0
- package/lib/infrastructure/services/HapticService.js.map +1 -0
- package/lib/presentation/hooks/useHaptics.d.ts +57 -0
- package/lib/presentation/hooks/useHaptics.d.ts.map +1 -0
- package/lib/presentation/hooks/useHaptics.js +113 -0
- package/lib/presentation/hooks/useHaptics.js.map +1 -0
- package/package.json +54 -0
- package/src/domain/entities/Haptic.ts +51 -0
- package/src/index.ts +179 -0
- package/src/infrastructure/services/HapticService.ts +117 -0
- package/src/presentation/hooks/useHaptics.ts +128 -0
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Haptics Domain - useHaptics Hook
|
|
3
|
+
*
|
|
4
|
+
* React hook for haptic feedback.
|
|
5
|
+
* Provides vibration patterns for common interactions.
|
|
6
|
+
*
|
|
7
|
+
* @domain haptics
|
|
8
|
+
* @layer presentation/hooks
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
import { useCallback } from 'react';
|
|
12
|
+
import { HapticService } from '../../infrastructure/services/HapticService';
|
|
13
|
+
import type { ImpactStyle, NotificationType, HapticPattern } from '../../domain/entities/Haptic';
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* useHaptics hook for haptic feedback
|
|
17
|
+
*
|
|
18
|
+
* USAGE:
|
|
19
|
+
* ```typescript
|
|
20
|
+
* const haptics = useHaptics();
|
|
21
|
+
*
|
|
22
|
+
* // Common patterns (convenience methods)
|
|
23
|
+
* <TouchableOpacity onPress={() => haptics.buttonPress()}>
|
|
24
|
+
* <Text>Click Me</Text>
|
|
25
|
+
* </TouchableOpacity>
|
|
26
|
+
*
|
|
27
|
+
* // Success feedback
|
|
28
|
+
* const handleSuccess = async () => {
|
|
29
|
+
* await saveData();
|
|
30
|
+
* haptics.success();
|
|
31
|
+
* };
|
|
32
|
+
*
|
|
33
|
+
* // Error feedback
|
|
34
|
+
* const handleError = () => {
|
|
35
|
+
* haptics.error();
|
|
36
|
+
* };
|
|
37
|
+
*
|
|
38
|
+
* // Selection change (sliders, pickers)
|
|
39
|
+
* <Slider onValueChange={() => haptics.selectionChange()} />
|
|
40
|
+
*
|
|
41
|
+
* // Custom patterns
|
|
42
|
+
* haptics.pattern('long_press');
|
|
43
|
+
* haptics.impact('heavy');
|
|
44
|
+
* haptics.notification('warning');
|
|
45
|
+
* ```
|
|
46
|
+
*/
|
|
47
|
+
export const useHaptics = () => {
|
|
48
|
+
/**
|
|
49
|
+
* Trigger impact feedback (light, medium, heavy)
|
|
50
|
+
*/
|
|
51
|
+
const impact = useCallback(async (style: ImpactStyle = 'Light') => {
|
|
52
|
+
await HapticService.impact(style);
|
|
53
|
+
}, []);
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* Trigger notification feedback (success, warning, error)
|
|
57
|
+
*/
|
|
58
|
+
const notification = useCallback(async (type: NotificationType) => {
|
|
59
|
+
await HapticService.notification(type);
|
|
60
|
+
}, []);
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* Trigger selection feedback (for pickers, sliders)
|
|
64
|
+
*/
|
|
65
|
+
const selection = useCallback(async () => {
|
|
66
|
+
await HapticService.selection();
|
|
67
|
+
}, []);
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* Trigger custom haptic pattern
|
|
71
|
+
*/
|
|
72
|
+
const pattern = useCallback(async (patternType: HapticPattern) => {
|
|
73
|
+
await HapticService.pattern(patternType);
|
|
74
|
+
}, []);
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* Common haptic patterns (convenience methods)
|
|
78
|
+
*/
|
|
79
|
+
const buttonPress = useCallback(async () => {
|
|
80
|
+
await HapticService.buttonPress();
|
|
81
|
+
}, []);
|
|
82
|
+
|
|
83
|
+
const success = useCallback(async () => {
|
|
84
|
+
await HapticService.success();
|
|
85
|
+
}, []);
|
|
86
|
+
|
|
87
|
+
const error = useCallback(async () => {
|
|
88
|
+
await HapticService.error();
|
|
89
|
+
}, []);
|
|
90
|
+
|
|
91
|
+
const warning = useCallback(async () => {
|
|
92
|
+
await HapticService.warning();
|
|
93
|
+
}, []);
|
|
94
|
+
|
|
95
|
+
const deleteItem = useCallback(async () => {
|
|
96
|
+
await HapticService.delete();
|
|
97
|
+
}, []);
|
|
98
|
+
|
|
99
|
+
const refresh = useCallback(async () => {
|
|
100
|
+
await HapticService.refresh();
|
|
101
|
+
}, []);
|
|
102
|
+
|
|
103
|
+
const selectionChange = useCallback(async () => {
|
|
104
|
+
await HapticService.selectionChange();
|
|
105
|
+
}, []);
|
|
106
|
+
|
|
107
|
+
const longPress = useCallback(async () => {
|
|
108
|
+
await HapticService.longPress();
|
|
109
|
+
}, []);
|
|
110
|
+
|
|
111
|
+
return {
|
|
112
|
+
// Generic methods
|
|
113
|
+
impact,
|
|
114
|
+
notification,
|
|
115
|
+
selection,
|
|
116
|
+
pattern,
|
|
117
|
+
|
|
118
|
+
// Common patterns (convenience methods)
|
|
119
|
+
buttonPress,
|
|
120
|
+
success,
|
|
121
|
+
error,
|
|
122
|
+
warning,
|
|
123
|
+
delete: deleteItem,
|
|
124
|
+
refresh,
|
|
125
|
+
selectionChange,
|
|
126
|
+
longPress,
|
|
127
|
+
};
|
|
128
|
+
};
|