Skip to content

Commit

Permalink
migrate to 'expo-haptics' (#3418)
Browse files Browse the repository at this point in the history
* migrate to 'expo-haptics'

* run yarn install twice if necessary
  • Loading branch information
haileyok authored Apr 5, 2024
1 parent cddbbc4 commit 4e59914
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 20 deletions.
5 changes: 2 additions & 3 deletions .github/workflows/pull-request-commit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,6 @@ jobs:
node-version-file: .nvmrc
cache: yarn

- name: ⚙️ Install Dependencies
run: yarn install

- name: Ensure tracking relevant branches and checkout base
run: |
git checkout ${{ github.head_ref }}
Expand All @@ -50,6 +47,7 @@ jobs:
git config --global user.email "github-actions[bot]@users.noreply.github.com"
git config --global user.name "github-actions[bot]"
git merge --no-edit ${{ github.head_ref }}
yarn install
- name: 🔦 Generate stats file for PR
run: |
Expand All @@ -72,6 +70,7 @@ jobs:
- name: 🔦 Generate stats file from base commit
if: ${{ !steps.get-base-stats.outputs.cache-hit }}
run: |
yarn install
yarn generate-webpack-stats-file
mv stats.json stats-base.json
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@
"expo-constants": "~15.4.5",
"expo-dev-client": "~3.3.8",
"expo-device": "~5.9.3",
"expo-haptics": "^12.8.1",
"expo-image": "~1.10.6",
"expo-image-manipulator": "^11.8.0",
"expo-image-picker": "~14.7.1",
Expand Down Expand Up @@ -159,7 +160,6 @@
"react-native-fs": "^2.20.0",
"react-native-gesture-handler": "~2.14.0",
"react-native-get-random-values": "~1.11.0",
"react-native-haptic-feedback": "^1.14.0",
"react-native-image-crop-picker": "^0.38.1",
"react-native-ios-context-menu": "^1.15.3",
"react-native-linear-gradient": "^2.6.2",
Expand Down
29 changes: 18 additions & 11 deletions src/lib/haptics.ts
Original file line number Diff line number Diff line change
@@ -1,40 +1,47 @@
import {
impactAsync,
ImpactFeedbackStyle,
notificationAsync,
NotificationFeedbackType,
selectionAsync,
} from 'expo-haptics'

import {isIOS, isWeb} from 'platform/detection'
import ReactNativeHapticFeedback, {
HapticFeedbackTypes,
} from 'react-native-haptic-feedback'

const hapticImpact: HapticFeedbackTypes = isIOS ? 'impactMedium' : 'impactLight' // Users said the medium impact was too strong on Android; see APP-537s
const hapticImpact: ImpactFeedbackStyle = isIOS
? ImpactFeedbackStyle.Medium
: ImpactFeedbackStyle.Light // Users said the medium impact was too strong on Android; see APP-537s

export class Haptics {
static default() {
if (isWeb) {
return
}
ReactNativeHapticFeedback.trigger(hapticImpact)
impactAsync(hapticImpact)
}
static impact(type: HapticFeedbackTypes = hapticImpact) {
static impact(type: ImpactFeedbackStyle = hapticImpact) {
if (isWeb) {
return
}
ReactNativeHapticFeedback.trigger(type)
impactAsync(type)
}
static selection() {
if (isWeb) {
return
}
ReactNativeHapticFeedback.trigger('selection')
selectionAsync()
}
static notification = (type: 'success' | 'warning' | 'error') => {
if (isWeb) {
return
}
switch (type) {
case 'success':
return ReactNativeHapticFeedback.trigger('notificationSuccess')
return notificationAsync(NotificationFeedbackType.Success)
case 'warning':
return ReactNativeHapticFeedback.trigger('notificationWarning')
return notificationAsync(NotificationFeedbackType.Warning)
case 'error':
return ReactNativeHapticFeedback.trigger('notificationError')
return notificationAsync(NotificationFeedbackType.Error)
}
}
}
10 changes: 5 additions & 5 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -11877,6 +11877,11 @@ expo-font@~11.10.3:
dependencies:
fontfaceobserver "^2.1.0"

expo-haptics@^12.8.1:
version "12.8.1"
resolved "https://registry.yarnpkg.com/expo-haptics/-/expo-haptics-12.8.1.tgz#42b996763be33d661bd33bbc3b3958c3f2734b9d"
integrity sha512-ntLsHkfle8K8w9MW8pZEw92ZN3sguaGUSSIxv30fPKNeQFu7Cq/h47Qv3tONv2MO3wU48N9FbKnant6XlfptpA==

expo-image-loader@~4.6.0:
version "4.6.0"
resolved "https://registry.yarnpkg.com/expo-image-loader/-/expo-image-loader-4.6.0.tgz#ca7d4fdf53125bff2091d3a2c34a3155f10df147"
Expand Down Expand Up @@ -18603,11 +18608,6 @@ react-native-get-random-values@~1.11.0:
dependencies:
fast-base64-decode "^1.0.0"

react-native-haptic-feedback@^1.14.0:
version "1.14.0"
resolved "https://registry.yarnpkg.com/react-native-haptic-feedback/-/react-native-haptic-feedback-1.14.0.tgz#b50f49dedda4980b3c37c5780823f753cf3ee717"
integrity sha512-dSXZ6gAzl+W/L7BPjOpnT0bx0cgQiSr0sB3DjyDJbGIdVr4ISaktZC6gC9xYFTv2kMq0+KtbKi+dpd0WtxYZMw==

react-native-image-crop-picker@^0.38.1:
version "0.38.1"
resolved "https://registry.yarnpkg.com/react-native-image-crop-picker/-/react-native-image-crop-picker-0.38.1.tgz#5973b4a8b55835b987e6be2064de411e849ac005"
Expand Down

0 comments on commit 4e59914

Please sign in to comment.