1.4.0 • Published 5 months ago

rn-qr-generator v1.4.0

Weekly downloads
442
License
MIT
Repository
github
Last release
5 months ago

rn-qr-generator

https://www.npmjs.com/package/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. react-native@0.60.0+ 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:

    rootProject.name = 'MyApp'
    include ':app'
    
    + 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:

    dependencies {
    + compile project(':rn-qr-generator')
    }

Usage

import RNQRGenerator from 'rn-qr-generator';

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

// Detect QR code in image
RNQRGenerator.detect({
  uri: PATH_TO_IMAGE
})
  .then(response => {
    const { values } = response; // Array of detected QR code values. Empty if nothing found.
  })
  .catch(error => console.log('Cannot detect QR code in image', error));

generate

input properties

PropertyTypeDescription
valuestringText value to be converted into QR image. (required)
widthnumberWidth of the QR image to be generated. (required)
heightnumberHeight of the QR image to be generated. (required)
backgroundColorstringBackground color of the image. (white by default)
colorstringColor of the image. (black by default)
fileNamestringName of the image file to store in FileSystem. (optional)
correctionLevelstringData restoration rate for total codewords. Available values are 'L', 'M', 'Q' and 'H'. ('H' by default)
base64booleanIf true will return base64 representation of the image. (optional, false by default)
paddingObjectPadding params for the image to be generated: {top: number, left: number, bottom: number, right: number}. (default no padding)

payload

PropertyTypeDescription
uristringPath of the generated image.
widthnumberWidth of the generated image.
heightnumberHeight of the generated image.
base64booleanBase64 encoded string of the image.

detect

input properties

PropertyTypeDescription
uristringLocal path of the image. Can be skipped if base64 is passed.
base64stringBase64 representation of the image to be scanned. If uri is passed this option will be skipped.

payload

PropertyTypeDescription
valuesstring[]Array of detected QR code values. Empty if nothing found.
typestringType of detected code.

The following barcode types are currently supported for decoding:

  • UPC-A and UPC-E
  • EAN-8 and EAN-13
  • Code 39
  • Code 93
  • Code 128
  • ITF
  • Codabar
  • RSS-14 (all variants)
  • QR Code
  • Data Matrix
  • Maxicode
  • Aztec ('beta' quality)
  • PDF 417 ('beta' quality)

example

Example of 2FA QR code with Time Based (TOTP) or Counter Based (HOTP)

RNQRGenerator.generate({
  ...
  value: 'otpauth://totp/Example:google@google.com?secret=HKSWY3RNEHPK3PXP&issuer=Issuer',
})

More information about totp can be found here.

This module uses Zxing library for encoding and decoding codes ( ios, Android).

Note

Some simulators may not generate qr code properly. Use real device if you get an error.

1.4.0

5 months ago

1.3.1

1 year ago

1.3.0

1 year ago

1.2.1

2 years ago

1.2.0

3 years ago

1.1.7

3 years ago

1.1.6

3 years ago

1.1.5

3 years ago

1.1.4

3 years ago

1.1.3

4 years ago

1.1.1

4 years ago

1.1.2

4 years ago

1.1.0

4 years ago

1.0.5

4 years ago

1.0.4

4 years ago

1.0.3

4 years ago

1.0.2

4 years ago

1.0.1

4 years ago

1.0.0

4 years ago