Skip to content

Commit

Permalink
switch to expo-haptics for vibration
Browse files Browse the repository at this point in the history
  • Loading branch information
EinsLucaaa committed Apr 19, 2024
1 parent d26d041 commit 9fefcf7
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 9 deletions.
17 changes: 9 additions & 8 deletions calculator/components/Button.js
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -17,24 +18,24 @@ export default function Button({ text, pressHandler, type }) {



if (text == "back") {
return <Pressable onPress={() => {pressHandler();Vibration.vibrate(10 * ONE_SECOND_IN_MS)}} style={[styles.button, {backgroundColor: "#2F2F39"}]}><Image source={require("../assets/delete-left-white.png")} style={[{width: 30, height: 30, color: "#fff"}]} /></Pressable>
if (text === "back") {
return <Pressable onPress={() => {pressHandler();Haptics.impactAsync(Haptics.ImpactFeedbackStyle.Light)}} style={[styles.button, {backgroundColor: "#2F2F39"}]}><Image source={require("../assets/delete-left-white.png")} style={[{width: 30, height: 30, color: "#fff"}]} /></Pressable>
}


if (type == "t1") {
if (type === "t1") {
return (
<Pressable onPress={() => {pressHandler();Vibration.vibrate(10 * ONE_SECOND_IN_MS)}} style={[styles.button]}><Text style={[styles.text]}>{text}</Text></Pressable>
<Pressable onPress={() => {pressHandler();Haptics.impactAsync(Haptics.ImpactFeedbackStyle.Light)}} style={[styles.button]}><Text style={[styles.text]}>{text}</Text></Pressable>
);
}

if (type == "t2") {
return <Pressable onPress={() => {pressHandler();Vibration.vibrate(10 * ONE_SECOND_IN_MS)}} style={[styles.button, {backgroundColor: "#4D5CFB"}]}><Text style={[styles.text]}>{text}</Text></Pressable>
if (type === "t2") {
return <Pressable onPress={() => {pressHandler();Haptics.impactAsync(Haptics.ImpactFeedbackStyle.Light)}} style={[styles.button, {backgroundColor: "#4D5CFB"}]}><Text style={[styles.text]}>{text}</Text></Pressable>
}

if (type == "t3") {
if (type === "t3") {
return (
<Pressable onPress={() => {pressHandler();Vibration.vibrate(10 * ONE_SECOND_IN_MS)}} style={[styles.button, {backgroundColor: "#2F2F39"}]}><Text style={[styles.text]}>{text}</Text></Pressable>
<Pressable onPress={() => {pressHandler();Haptics.impactAsync(Haptics.ImpactFeedbackStyle.Light)}} style={[styles.button, {backgroundColor: "#2F2F39"}]}><Text style={[styles.text]}>{text}</Text></Pressable>
);
}
}
Expand Down
9 changes: 9 additions & 0 deletions calculator/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion calculator/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

0 comments on commit 9fefcf7

Please sign in to comment.