-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* migrate to 'expo-haptics' * run yarn install twice if necessary
- Loading branch information
Showing
4 changed files
with
26 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters