Skip to content

Commit 45e77c8

Browse files
Yury Korzunfacebook-github-bot
Yury Korzun
authored andcommitted
Adds a touchSoundDisabled prop to Touchable (#24666)
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
1 parent 0c7376c commit 45e77c8

File tree

3 files changed

+14
-2
lines changed

3 files changed

+14
-2
lines changed

Libraries/Components/Button.js

+8-1
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,11 @@ type ButtonProps = $ReadOnly<{|
3333
*/
3434
onPress: (event?: PressEvent) => mixed,
3535

36+
/**
37+
* If true, doesn't play system sound on touch (Android Only)
38+
**/
39+
touchSoundDisabled?: ?boolean,
40+
3641
/**
3742
* Color of the text (iOS), or background color of the button (Android)
3843
*/
@@ -128,6 +133,7 @@ class Button extends React.Component<ButtonProps> {
128133
accessibilityLabel,
129134
color,
130135
onPress,
136+
touchSoundDisabled,
131137
title,
132138
hasTVPreferredFocus,
133139
nextFocusDown,
@@ -174,7 +180,8 @@ class Button extends React.Component<ButtonProps> {
174180
nextFocusUp={nextFocusUp}
175181
testID={testID}
176182
disabled={disabled}
177-
onPress={onPress}>
183+
onPress={onPress}
184+
touchSoundDisabled={touchSoundDisabled}>
178185
<View style={buttonStyles}>
179186
<Text style={textStyles} disabled={disabled}>
180187
{formattedTitle}

Libraries/Components/Touchable/Touchable.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -872,7 +872,7 @@ const TouchableMixin = {
872872
this._startHighlight(e);
873873
this._endHighlight(e);
874874
}
875-
if (Platform.OS === 'android') {
875+
if (Platform.OS === 'android' && !this.props.touchSoundDisabled) {
876876
this._playTouchSound();
877877
}
878878
this.touchableHandlePress(e);

Libraries/Components/Touchable/TouchableWithoutFeedback.js

+5
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ export type Props = $ReadOnly<{|
6767
disabled?: ?boolean,
6868
hitSlop?: ?EdgeInsetsProp,
6969
nativeID?: ?string,
70+
touchSoundDisabled?: ?boolean,
7071
onBlur?: ?(e: BlurEvent) => void,
7172
onFocus?: ?(e: FocusEvent) => void,
7273
onLayout?: ?(event: LayoutEvent) => mixed,
@@ -135,6 +136,10 @@ const TouchableWithoutFeedback = ((createReactClass({
135136
* `{nativeEvent: {layout: {x, y, width, height}}}`
136137
*/
137138
onLayout: PropTypes.func,
139+
/**
140+
* If true, doesn't play system sound on touch (Android Only)
141+
**/
142+
touchSoundDisabled: PropTypes.bool,
138143

139144
onLongPress: PropTypes.func,
140145

0 commit comments

Comments
 (0)