25

React Native module for generating QR codes

 5 years ago
source link: https://github.com/gevorg94/rn-qr-generator
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

rn-qr-generator

Getting started

$ npm install rn-qr-generator --save

Mostly automatic installation

$ react-native link rn-qr-generator

Important:

Linking is not needed anymore. [email protected]+ supports dependencies auto linking. For iOS you also need additional step to install auto linked Pods (Cocoapods should be installed):

cd ios && pod install && cd ../

Manual installation

iOS

  1. In XCode, in the project navigator, right click LibrariesAdd Files to [your project's name]
  2. Go to node_modulesrn-qr-generator and add RNQrGenerator.xcodeproj
  3. In XCode, in the project navigator, select your project. Add libRNQrGenerator.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/[...]/MainActivity.java
  • Add import com.gevorg.reactlibrary.RNQrGeneratorPackage; to the imports at the top of the file
  • Add new RNQrGeneratorPackage() to the list returned by the getPackages() method
  1. Append the following lines to android/settings.gradle :
    include ':rn-qr-generator'
    project(':rn-qr-generator').projectDir = new File(rootProject.projectDir, 	'../node_modules/rn-qr-generator/android')
  2. Insert the following lines inside the dependencies block in android/app/build.gradle :
    compile project(':rn-qr-generator')

Usage

import RNQRGenerator from 'rn-qr-generator';

RNQRGenerator.generate({
  value: 'https://github.com/gevorg94/rn-qr-generator', // required
  height: 100,
  width: 100,
  base64: false,            // default 'false'
  backgroundColor: 'black', // default 'white'
  color: 'white',           // default 'black'
})
  .then(response => {
    const { uri, width, height, base64 } = response;
    this.setState({ imageUri: uri });
  })
  .catch(error => console.log('Cannot create QR code', error));

Recommend

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK