Skip to content

PartitionPixel/react-native-volume-listener

 
 

Repository files navigation

react-native-volume-listener

Getting started

$ yarn add react-native-volume-listener

Mostly automatic installation

$ react-native link react-native-volume-listener

Manual installation

iOS

  1. In XCode, in the project navigator, right click LibrariesAdd Files to [your project's name]
  2. Go to node_modulesreact-native-volume-listener and add RNVolumeListen.xcodeproj
  3. In XCode, in the project navigator, select your project. Add libRNVolumeListen.a to your project's Build PhasesLink Binary With Libraries
  4. Run your project (Cmd+R)<

Android

  1. Open up android/app/src/main/java/[...]/MainApplication.java
  • Add import com.nghinv.volumelisten.RNVolumeListenPackage; to the imports at the top of the file
  • Add new RNVolumeListenPackage() to the list returned by the getPackages() method
  1. Append the following lines to android/settings.gradle:

    include ':react-native-volume-listener'
    project(':react-native-volume-listener').projectDir = new File(rootProject.projectDir, 	'../node_modules/react-native-volume-listener/android')
    
  2. Insert the following lines inside the dependencies block in android/app/build.gradle:

      compile project(':react-native-volume-listener')
    
  3. Important

  • Add import android.view.KeyEvent; and import com.nghinv.volumelisten.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);
    }
    

Usage

import React, { Component } from 'react';
import { View } from 'react-native';
import VolumeListen from 'react-native-volume-listener';

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

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Objective-C 41.7%
  • Java 30.9%
  • JavaScript 21.0%
  • Ruby 6.4%