Skip to content

Commit

Permalink
Merge pull request #17095 from RobertKozik/haptics-extend-implementation
Browse files Browse the repository at this point in the history
Extend implementation of Haptic Feedback
  • Loading branch information
arosiclair authored Apr 10, 2023
2 parents f6d8c43 + ff0b335 commit c31a259
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 34 deletions.
4 changes: 2 additions & 2 deletions src/components/Button.js
Original file line number Diff line number Diff line change
Expand Up @@ -241,13 +241,13 @@ class Button extends Component {
}

if (this.props.shouldEnableHapticFeedback) {
HapticFeedback.trigger();
HapticFeedback.press();
}
this.props.onPress(e);
}}
onLongPress={(e) => {
if (this.props.shouldEnableHapticFeedback) {
HapticFeedback.trigger();
HapticFeedback.longPress();
}
this.props.onLongPress(e);
}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ const PressableWithSecondaryInteraction = (props) => {
onPress={props.onPress}
onLongPress={(e) => {
e.preventDefault();
HapticFeedback.trigger();
HapticFeedback.longPress();
props.onSecondaryInteraction(e);
}}
onPressIn={props.onPressIn}
Expand Down
18 changes: 0 additions & 18 deletions src/libs/HapticFeedback/index.android.js

This file was deleted.

12 changes: 0 additions & 12 deletions src/libs/HapticFeedback/index.ios.js

This file was deleted.

5 changes: 4 additions & 1 deletion src/libs/HapticFeedback/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,8 @@
* Web does not support Haptic feedback
*/
export default {
trigger: () => {},
press: () => {},
longPress: () => {},
success: () => {},
error: () => {},
};
33 changes: 33 additions & 0 deletions src/libs/HapticFeedback/index.native.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@

import ReactNativeHapticFeedback from 'react-native-haptic-feedback';

function press() {
ReactNativeHapticFeedback.trigger('impactLight', {
enableVibrateFallback: true,
});
}

function longPress() {
ReactNativeHapticFeedback.trigger('impactHeavy', {
enableVibrateFallback: true,
});
}

function success() {
ReactNativeHapticFeedback.trigger('notificationSuccess', {
enableVibrateFallback: true,
});
}

function error() {
ReactNativeHapticFeedback.trigger('notificationError', {
enableVibrateFallback: true,
});
}

export default {
press,
longPress,
success,
error,
};

0 comments on commit c31a259

Please sign in to comment.