Skip to content

Commit

Permalink
Adds a touchSoundDisabled prop to Touchable (#24666)
Browse files Browse the repository at this point in the history
Summary:
Currently, every time a touchable is pressed on Android, a system sound is played. It was added in the PR #17183. There is no way to disable it, except disabling touch on sound on the system level. I am pretty sure there are cases when touches should be silent and there should be an option to disable it.

Related PRs - #17183, #11136

[Android][added] - Added a touchSoundDisabled prop to Touchable. If true, doesn't system sound on touch.
Pull Request resolved: #24666

Differential Revision: D15166582

Pulled By: cpojer

fbshipit-source-id: 48bfe88f03f791e3b9c7cbd0e2eed80a2cfba8ee
  • Loading branch information
yurykorzun authored and facebook-github-bot committed May 1, 2019
1 parent 0c7376c commit 45e77c8
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 2 deletions.
9 changes: 8 additions & 1 deletion Libraries/Components/Button.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,11 @@ type ButtonProps = $ReadOnly<{|
*/
onPress: (event?: PressEvent) => mixed,

/**
* If true, doesn't play system sound on touch (Android Only)
**/
touchSoundDisabled?: ?boolean,

/**
* Color of the text (iOS), or background color of the button (Android)
*/
Expand Down Expand Up @@ -128,6 +133,7 @@ class Button extends React.Component<ButtonProps> {
accessibilityLabel,
color,
onPress,
touchSoundDisabled,
title,
hasTVPreferredFocus,
nextFocusDown,
Expand Down Expand Up @@ -174,7 +180,8 @@ class Button extends React.Component<ButtonProps> {
nextFocusUp={nextFocusUp}
testID={testID}
disabled={disabled}
onPress={onPress}>
onPress={onPress}
touchSoundDisabled={touchSoundDisabled}>
<View style={buttonStyles}>
<Text style={textStyles} disabled={disabled}>
{formattedTitle}
Expand Down
2 changes: 1 addition & 1 deletion Libraries/Components/Touchable/Touchable.js
Original file line number Diff line number Diff line change
Expand Up @@ -872,7 +872,7 @@ const TouchableMixin = {
this._startHighlight(e);
this._endHighlight(e);
}
if (Platform.OS === 'android') {
if (Platform.OS === 'android' && !this.props.touchSoundDisabled) {
this._playTouchSound();
}
this.touchableHandlePress(e);
Expand Down
5 changes: 5 additions & 0 deletions Libraries/Components/Touchable/TouchableWithoutFeedback.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ export type Props = $ReadOnly<{|
disabled?: ?boolean,
hitSlop?: ?EdgeInsetsProp,
nativeID?: ?string,
touchSoundDisabled?: ?boolean,
onBlur?: ?(e: BlurEvent) => void,
onFocus?: ?(e: FocusEvent) => void,
onLayout?: ?(event: LayoutEvent) => mixed,
Expand Down Expand Up @@ -135,6 +136,10 @@ const TouchableWithoutFeedback = ((createReactClass({
* `{nativeEvent: {layout: {x, y, width, height}}}`
*/
onLayout: PropTypes.func,
/**
* If true, doesn't play system sound on touch (Android Only)
**/
touchSoundDisabled: PropTypes.bool,

onLongPress: PropTypes.func,

Expand Down

0 comments on commit 45e77c8

Please sign in to comment.