react-native-system-setting
react-native-system-setting copied to clipboard
`addVolumeListener` is fired twice when press volume key
I just tested android device only.
There is a problem that the addVolumeListener is called twice when the sound mode is "music".
my code snipppet is here
componentDidMount = () => {
this.volumeListener = SystemSetting.addVolumeListener(this.setVolume);
};
componentWillUnmount = () => {
SystemSetting.removeVolumeListener(this.volumeListener);
};
setVolume = currentVolume => {
console.log("call setvolume");
this.setState({ currentVolume: currentVolume.value });
};
Thanks for your feedback!
I reproduce it in my android phone. If I block keyup event for volume button in onKeyUp(), it'll be called once only. So I think twice calling is for keydown and keyup. I am not sure if this is a feature of android.
@c19354837 ping any news on this please ?
hello @MaximeBrl
I recommend you to use shouldComponentUpdate or implementing React.PureComponent to block unnecessary re-rendering
Thank you, I'll test it tomorrow !
This solution does not work for my problem. I start the camera, thanks to a button, a self-timer starts, then after the recording starts.
The problem with shouldComponentUpdate is that I don't care about the rendering of the component. Thanks to the VolumeListener, I want to be able to start recording with the volume button. With a multiple call from the listener, it prevents me from doing what I want and the shouldComponentUpdate() doesn't work because it only concerns rendering.
Sorry I'm French and I must have made some mistakes.
Edit : I have found a solution but it's not a good solution
Hi. Did anyone solve this issue?