react-native-volume-listen
v1.0.1
Published
Volume listen
Downloads
4
Readme
react-native-volume-listen
Getting started
$ yarn add react-native-volume-listen
Mostly automatic installation
$ react-native link react-native-volume-listen
Manual installation
iOS
- In XCode, in the project navigator, right click
Libraries
➜Add Files to [your project's name]
- Go to
node_modules
➜react-native-volume-listen
and addRNVolumeListen.xcodeproj
- In XCode, in the project navigator, select your project. Add
libRNVolumeListen.a
to your project'sBuild Phases
➜Link Binary With Libraries
- Run your project (
Cmd+R
)<
Android
- Open up
android/app/src/main/java/[...]/MainApplication.java
- Add
import com.reactlibrary.RNVolumeListenPackage;
to the imports at the top of the file - Add
new RNVolumeListenPackage()
to the list returned by thegetPackages()
method
Append the following lines to
android/settings.gradle
:include ':react-native-volume-listen' project(':react-native-volume-listen').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-volume-listen/android')
Insert the following lines inside the dependencies block in
android/app/build.gradle
:compile project(':react-native-volume-listen')
Important
- Add
import android.view.KeyEvent;
andimport com.reactlibrary.RNVolumeListenModule;
to the imports at top of the file MainActivity.java - Append the following lines to MainActivity class
@Override public boolean onKeyDown(int keyCode, KeyEvent event) { return RNVolumeListenModule.onKeyDownEvent(keyCode, event); }
- Add
Usage
import React, { Component } from 'react';
import { View } from 'react-native';
import VolumeListen from 'react-native-volume-listen';
// TODO: What to do with the module?
export default class Example extends Component {
onVolumePress = (volume) => {
// return UP or DOWN
console.log('onVolumePress', volume)
}
onChangeVolume = (volume) => {
//return current volume (0 -> 1)
console.log('onChangeVolume', volume)
}
render() {
return (
<View style={{flex: 1}}>
<VolumeListen
onVolumePress={this.onVolumePress}
onChangeVolume={this.onChangeVolume} // Only IOS
/>
</View>
)
}
}