feat: update

This commit is contained in:
2025-11-06 16:37:01 +08:00
parent c0d54b8513
commit 855f289579
59 changed files with 3398 additions and 572 deletions

113
hooks/useHaptics.ts Normal file
View File

@@ -0,0 +1,113 @@
/**
* 触觉反馈 Hook
* 封装 Expo Haptics 功能
*/
import { useCallback } from 'react';
import * as Haptics from 'expo-haptics';
import { useHapticsEnabled } from '@/stores/settingsStore';
/**
* 触觉反馈 Hook
* 根据用户设置决定是否触发触觉反馈
*/
export function useHaptics() {
const hapticsEnabled = useHapticsEnabled();
/**
* 轻触反馈
*/
const light = useCallback(async () => {
if (hapticsEnabled) {
await Haptics.impactAsync(Haptics.ImpactFeedbackStyle.Light);
}
}, [hapticsEnabled]);
/**
* 中等反馈
*/
const medium = useCallback(async () => {
if (hapticsEnabled) {
await Haptics.impactAsync(Haptics.ImpactFeedbackStyle.Medium);
}
}, [hapticsEnabled]);
/**
* 重触反馈
*/
const heavy = useCallback(async () => {
if (hapticsEnabled) {
await Haptics.impactAsync(Haptics.ImpactFeedbackStyle.Heavy);
}
}, [hapticsEnabled]);
/**
* 成功反馈
*/
const success = useCallback(async () => {
if (hapticsEnabled) {
await Haptics.notificationAsync(Haptics.NotificationFeedbackType.Success);
}
}, [hapticsEnabled]);
/**
* 警告反馈
*/
const warning = useCallback(async () => {
if (hapticsEnabled) {
await Haptics.notificationAsync(Haptics.NotificationFeedbackType.Warning);
}
}, [hapticsEnabled]);
/**
* 错误反馈
*/
const error = useCallback(async () => {
if (hapticsEnabled) {
await Haptics.notificationAsync(Haptics.NotificationFeedbackType.Error);
}
}, [hapticsEnabled]);
/**
* 选择反馈
*/
const selection = useCallback(async () => {
if (hapticsEnabled) {
await Haptics.selectionAsync();
}
}, [hapticsEnabled]);
return {
light,
medium,
heavy,
success,
warning,
error,
selection,
};
}
/**
* 使用示例:
*
* function MyComponent() {
* const haptics = useHaptics();
*
* const handlePress = () => {
* haptics.light();
* // 执行其他操作
* };
*
* const handleSuccess = () => {
* haptics.success();
* // 显示成功消息
* };
*
* return (
* <TouchableOpacity onPress={handlePress}>
* <Text>Press me</Text>
* </TouchableOpacity>
* );
* }
*/