Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to catch ios device button press in react native?

I need to catch sound volume button press inside my react-native application. Couldn't find anything in docs.

like image 323
Victor L. Avatar asked Sep 06 '16 20:09

Victor L.


2 Answers

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.

like image 125
Luke Rhodes Avatar answered Oct 16 '22 15:10

Luke Rhodes


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 }); }

like image 3
David Avatar answered Oct 16 '22 17:10

David