Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to disable Android default "Touchable onPress" sound from react-native code?

I'm developing an app for Android in react-native with expo. I'm using expo's Audio.Sound API in order to play different sounds in my app. What annoys me is that whenever I press a TouchableOpacity component I get both my sound and the default onPress sound from Android (it disappears only if I mute the sound from the hardware buttons of my phone). I'd like to disable the default sound. Is there a way to do this programatically from react-native code?

like image 604
Norberth Csorba Avatar asked Jun 30 '26 14:06

Norberth Csorba


2 Answers

You can actually use touchSoundDisabled={true} which is not covered in TouchableOpacity docs, but is part of a Button component. But it still works for touchables as well

like image 63
YuriS Avatar answered Jul 05 '26 05:07

YuriS


I had the exact same problem using TouchableWithoutFeedback. The touchable events always play the default android button noise when clicked.

The solution I found was to instead use the onStartShouldSetResponder prop of the View component. This basically turns a view into a button and is equivalent to the 'onPress' prop.

<View onStartShouldSetResponder={() => this.onPress()}/>
like image 21
user1871200 Avatar answered Jul 05 '26 06:07

user1871200



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!