Is it possible to add sound and refresh button in React Native Apps?

Moderator: Reach-Native-gp

Post Reply
Anisha Sharma
Posts: 11
Joined: Fri May 08, 2020 12:30 pm

Is it possible to add sound and refresh button in React Native Apps?

Post by Anisha Sharma »

Yes, it is very much possible to add the sound effects in an app made in React Native, along with a 'pull to refresh' button in it. The button will be very much similar to Twitter and Facebook.

There is a library called the react-native-sound which we can use to play sound clips in both iOS and Android.

To run and install the library, follow the given steps:
  • On the command prompt, run the install command npm install react-native-sound --save
  • Now to link it to your existing project, run react-native link react-native-sound
How to use the library?

To use the library you will have to create a helper file such as audio.js. This will import the library react-native-sound and you can export any method from the library to use different sound. The same library can be used to implement the 'pull to refresh' button in the app.

Note: For iOS development, make sure that you have added the Sound.setCategory('Ambient', true);. This is because, in iOS, the app will by default stop playing your sound if in case there is music playing in the background. If you add the given line of code, it will make sure that sound will play despite music playing.

Post Reply