Replaces the default iOS volume popup by a less-obtrusive indicator. Includes helpers to get access and subscribe to your app's audio volume.
$ npm install react-native-volume-indicator --save
⚠️ Only iOS is supported at the moment.
$ react-native link react-native-volume-indicator
- In XCode, in the project navigator, right click
Libraries
and selectAdd Files to [your project's name]
- Go to
node_modules/react-native-volume-indicator
and addRNVolumeIndicator.xcodeproj
- In XCode, in the project navigator, select your project. Add
libRNVolumeIndicator.a
to your project'sBuild Phases
➜Link Binary With Libraries
- Run your project
⚠️ Please note that you'll only be able to get the actual volume using a physical device.
Component that displays a volume indicator. By default, it looks like a blue slider that fills up from left to right depending on the current volume.
import VolumeIndicator from 'react-native-volume-indicator';
class App extends React.Component {
render() {
<VolumeIndicator />
};
}
Call it whenever you need to get the volume of your app's audio.
import {getVolume} from 'react-native-volume-indicator';
class App extends React.Component {
_getVolume() {
getVolume().then(volume => {
// ...
})
}
}
Use listenToVolumeChange
when you want to start listening to volume change.
Don't forget to remove the listener by calling stopListeningToVolumeChange()
.
Allows you to create your own volume indicator easily.
import {listenToVolumeChange, stopListeningToVolumeChange} from 'react-native-volume-indicator';
class App extends React.Component {
componentDidMount(){
listenToVolumeChange(this._onVolumeChange);
}
componentWillUnmount(){
stopListeningToVolumeChange();
}
_onVolumeChange = (volume) => {
// ...
}
}
If you don't want to make your own, we provide a set of two layouts to choose from.
To use them, set the layout
prop to either default
or dark-vertical
.
<VolumeIndicator layout="default" />
If you want, you can use the style
prop to customize the look
of any volume indicator.
MIT License
See LICENSE