Reputation: 645
I need to catch sound volume button press inside my react-native application. Couldn't find anything in docs.
Upvotes: 7
Views: 2335
Reputation: 1601
You can use react-native-system-setting
package with addVolumeListener
listener. Something like this
componentDidMount() {
// listen the volume changing
this.volumeListener = SystemSetting.addVolumeListener(data => {
// your action here
});
}
Upvotes: 3
Reputation: 323
You could create a native module as per FuzzyTree's comment however if you want something that's ready out of the box you could use https://github.com/IFours/react-native-volume-slider and make it hidden. The onValueChange callback is called upon the iOS device volume controls being changed.
Another idea could be to look into the aforementioned module and just take out what you need to form a new module and publish it for the benefit of everyone.
Upvotes: 2