From 9fefcf769b5c6ab84903528697d4ce85a6d431e4 Mon Sep 17 00:00:00 2001 From: EinsLucaaa <74465789+EinsLucaaa@users.noreply.github.com> Date: Fri, 19 Apr 2024 21:58:02 +0200 Subject: [PATCH] switch to expo-haptics for vibration --- calculator/components/Button.js | 17 +++++++++-------- calculator/package-lock.json | 9 +++++++++ calculator/package.json | 3 ++- 3 files changed, 20 insertions(+), 9 deletions(-) diff --git a/calculator/components/Button.js b/calculator/components/Button.js index f9b7d44..6ac6edd 100644 --- a/calculator/components/Button.js +++ b/calculator/components/Button.js @@ -1,5 +1,6 @@ import { Pressable, StyleSheet, Text, View, Image, Vibration, Platform } from 'react-native'; import Icon from 'react-native-vector-icons/dist/FontAwesome'; +import * as Haptics from 'expo-haptics'; export default function Button({ text, pressHandler, type }) { const ONE_SECOND_IN_MS = 1000; @@ -17,24 +18,24 @@ export default function Button({ text, pressHandler, type }) { - if (text == "back") { - return {pressHandler();Vibration.vibrate(10 * ONE_SECOND_IN_MS)}} style={[styles.button, {backgroundColor: "#2F2F39"}]}> + if (text === "back") { + return {pressHandler();Haptics.impactAsync(Haptics.ImpactFeedbackStyle.Light)}} style={[styles.button, {backgroundColor: "#2F2F39"}]}> } - if (type == "t1") { + if (type === "t1") { return ( - {pressHandler();Vibration.vibrate(10 * ONE_SECOND_IN_MS)}} style={[styles.button]}>{text} + {pressHandler();Haptics.impactAsync(Haptics.ImpactFeedbackStyle.Light)}} style={[styles.button]}>{text} ); } - if (type == "t2") { - return {pressHandler();Vibration.vibrate(10 * ONE_SECOND_IN_MS)}} style={[styles.button, {backgroundColor: "#4D5CFB"}]}>{text} + if (type === "t2") { + return {pressHandler();Haptics.impactAsync(Haptics.ImpactFeedbackStyle.Light)}} style={[styles.button, {backgroundColor: "#4D5CFB"}]}>{text} } - if (type == "t3") { + if (type === "t3") { return ( - {pressHandler();Vibration.vibrate(10 * ONE_SECOND_IN_MS)}} style={[styles.button, {backgroundColor: "#2F2F39"}]}>{text} + {pressHandler();Haptics.impactAsync(Haptics.ImpactFeedbackStyle.Light)}} style={[styles.button, {backgroundColor: "#2F2F39"}]}>{text} ); } } diff --git a/calculator/package-lock.json b/calculator/package-lock.json index fcb5e39..afe3fb2 100644 --- a/calculator/package-lock.json +++ b/calculator/package-lock.json @@ -9,6 +9,7 @@ "version": "1.0.0", "dependencies": { "expo": "~50.0.14", + "expo-haptics": "~12.8.1", "expo-status-bar": "~1.11.1", "react": "18.2.0", "react-native": "0.73.6", @@ -7997,6 +7998,14 @@ "expo": "*" } }, + "node_modules/expo-haptics": { + "version": "12.8.1", + "resolved": "https://registry.npmjs.org/expo-haptics/-/expo-haptics-12.8.1.tgz", + "integrity": "sha512-ntLsHkfle8K8w9MW8pZEw92ZN3sguaGUSSIxv30fPKNeQFu7Cq/h47Qv3tONv2MO3wU48N9FbKnant6XlfptpA==", + "peerDependencies": { + "expo": "*" + } + }, "node_modules/expo-keep-awake": { "version": "12.8.2", "resolved": "https://registry.npmjs.org/expo-keep-awake/-/expo-keep-awake-12.8.2.tgz", diff --git a/calculator/package.json b/calculator/package.json index d907a94..bba7962 100644 --- a/calculator/package.json +++ b/calculator/package.json @@ -13,7 +13,8 @@ "expo-status-bar": "~1.11.1", "react": "18.2.0", "react-native": "0.73.6", - "react-native-vector-icons": "^10.0.3" + "react-native-vector-icons": "^10.0.3", + "expo-haptics": "~12.8.1" }, "devDependencies": { "@babel/core": "^7.20.0"