Norberth Csorba
Norberth Csorba

Reputation: 352

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?

Upvotes: 3

Views: 2995

Answers (3)

Nikhil bhatia
Nikhil bhatia

Reputation: 1397

Use Pressable instead of TouchableOpacity and add android_disableSound={true}

<Pressable android_disableSound={true} onPress={() => {}}

Upvotes: 1

YuriS
YuriS

Reputation: 111

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

Upvotes: 8

user1871200
user1871200

Reputation: 83

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()}/>

Upvotes: 3

Related Questions