Haptic Feedback — tactile responses using expo-haptics or react-native-haptic-feedback.
Using expo-haptics:
1import * as Haptics from "expo-haptics";23// Light impact4Haptics.impactAsync(Haptics.ImpactFeedbackStyle.Light);56// Medium impact7Haptics.impactAsync(Haptics.ImpactFeedbackStyle.Medium);89// Heavy impact10Haptics.impactAsync(Haptics.ImpactFeedbackStyle.Heavy);1112// Selection feedback13Haptics.selectionAsync();1415// Notification feedback16Haptics.notificationAsync(17 Haptics.NotificationFeedbackType.Success18);19Haptics.notificationAsync(20 Haptics.NotificationFeedbackType.Warning21);22Haptics.notificationAsync(23 Haptics.NotificationFeedbackType.Error24);
Custom hook:
1import { useCallback } from "react";2import * as Haptics from "expo-haptics";34function useHaptics() {5 const impact = useCallback(6 (style: Haptics.ImpactFeedbackStyle = "Medium") => {7 Haptics.impactAsync(style).catch(() => {});8 },9 []10 );1112 const notify = useCallback(13 (type: Haptics.NotificationFeedbackType = "Success") => {14 Haptics.notificationAsync(type).catch(() => {});15 },16 []17 );1819 const select = useCallback(() => {20 Haptics.selectionAsync().catch(() => {});21 }, []);2223 return { impact, notify, select };24}2526// Usage27function LikeButton() {28 const { impact } = useHaptics();2930 return (31 <Pressable32 onPress={() => {33 impact("Heavy");34 onLike();35 }}36 >37 <Text>Like</Text>38 </Pressable>39 );40}
Use cases: