Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/components/BigNumberPad.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ class BigNumberPad extends React.Component {
return (
<Button
key={column}
shouldEnableHapticFeedback
style={[styles.flex1, marginLeft]}
text={column === '<' ? column : this.props.toLocaleDigit(column)}
onLongPress={() => this.handleLongPress(column)}
Expand Down
19 changes: 17 additions & 2 deletions src/components/Button.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import KeyboardShortcut from '../libs/KeyboardShortcut';
import Icon from './Icon';
import CONST from '../CONST';
import * as StyleUtils from '../styles/StyleUtils';
import HapticFeedback from '../libs/HapticFeedback';

const propTypes = {
/** The text for the button label */
Expand Down Expand Up @@ -73,6 +74,9 @@ const propTypes = {

/** Should we remove the left border radius top + bottom? */
shouldRemoveLeftBorderRadius: PropTypes.bool,

/** Should enable the haptic feedback? */
shouldEnableHapticFeedback: PropTypes.bool,
};

const defaultProps = {
Expand All @@ -96,6 +100,7 @@ const defaultProps = {
ContentComponent: undefined,
shouldRemoveRightBorderRadius: false,
shouldRemoveLeftBorderRadius: false,
shouldEnableHapticFeedback: false,
};

class Button extends Component {
Expand Down Expand Up @@ -179,8 +184,18 @@ class Button extends Component {
render() {
return (
<Pressable
onPress={this.props.onPress}
onLongPress={this.props.onLongPress}
onPress={(e) => {
if (this.props.shouldEnableHapticFeedback) {
HapticFeedback.trigger();
}
this.props.onPress(e);
}}
onLongPress={(e) => {
if (this.props.shouldEnableHapticFeedback) {
HapticFeedback.trigger();
}
this.props.onLongPress(e);
}}
onPressIn={this.props.onPressIn}
onPressOut={this.props.onPressOut}
disabled={this.props.isLoading || this.props.isDisabled}
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import _ from 'underscore';
import React, {forwardRef} from 'react';
import ReactNativeHapticFeedback from 'react-native-haptic-feedback';
import {Pressable} from 'react-native';
import * as pressableWithSecondaryInteractionPropTypes from './pressableWithSecondaryInteractionPropTypes';
import Text from '../Text';
import HapticFeedback from '../../libs/HapticFeedback';

/**
* This is a special Pressable that calls onSecondaryInteraction when LongPressed.
Expand All @@ -21,9 +21,7 @@ const PressableWithSecondaryInteraction = (props) => {
onPressIn={props.onPressIn}
onLongPress={(e) => {
e.preventDefault();
ReactNativeHapticFeedback.trigger('selection', {
enableVibrateFallback: true,
});
HapticFeedback.trigger();
props.onSecondaryInteraction(e);
}}
onPressOut={props.onPressOut}
Expand Down
18 changes: 18 additions & 0 deletions src/libs/HapticFeedback/index.android.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import {Platform} from 'react-native';
import ReactNativeHapticFeedback from 'react-native-haptic-feedback';

function trigger() {
// The constant effectHeavyClick is added in API level 29.
// Docs: https://developer.android.com/reference/android/os/VibrationEffect#EFFECT_HEAVY_CLICK
// We use keyboardTap added in API level 8 as a fallback.
// Docs: https://developer.android.com/reference/android/view/HapticFeedbackConstants#KEYBOARD_TAP
if (Platform.Version >= 29) {
ReactNativeHapticFeedback.trigger('effectHeavyClick');
return;
}
ReactNativeHapticFeedback.trigger('keyboardTap');
}

export default {
trigger,
};
12 changes: 12 additions & 0 deletions src/libs/HapticFeedback/index.ios.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@

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

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

export default {
trigger,
};
6 changes: 6 additions & 0 deletions src/libs/HapticFeedback/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
/**
* Web does not support Haptic feedback
*/
export default {
trigger: () => {},
};