一、背景:
项目中有长按按钮开始录音功能,需要在长按开始时添加一次震动反馈以提高用户体验。由于项目使用expo开发,所以找到了 Expo Haptics
库。
二、使用过程:
1. 安装:
npx expo install expo-haptics
2. 引入并使用:
import * as Haptics from "expo-haptics";
const startRecord = () => {
Haptics.selectionAsync();
// 其它操作
...
}
...
<Pressable onPress={() => startRecord()}>
<Image
source={require("../assets/chat/startRecord.png")}
style={styles.startIcon}
></Image>
</Pressable>
...
其它配置和功能可以查看官方文档。