Launch Week Day 2: Introducing Reports: An Extensible Reporting Framework for Socket Data.Learn More
Socket
Book a DemoSign in
Socket

rn-qr-generator

Package Overview
Dependencies
Maintainers
1
Versions
26
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

rn-qr-generator

React native QR Code generator / reader

latest
Source
npmnpm
Version
2.0.0
Version published
Weekly downloads
23K
-2.51%
Maintainers
1
Weekly downloads
 
Created
Source

rn-qr-generator

https://www.npmjs.com/package/rn-qr-generator

React Native QR Code generator and reader library supporting both the New Architecture (TurboModules/Fabric) and the legacy architecture.

Version Compatibility

VersionReact NativeArchitecture Support
2.x.x>= 0.71.0New Architecture (TurboModules) + Legacy
1.x.x>= 0.55.0Legacy Architecture only

Note: If you're using React Native < 0.71.0 or need to stay on the legacy architecture, use version 1.4.5:

npm install rn-qr-generator@1.4.5

Getting started

npm install rn-qr-generator --save
# or
yarn add rn-qr-generator

iOS Installation

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

New Architecture (React Native 0.71+)

This library automatically supports the New Architecture when enabled in your project. No additional configuration is required.

For iOS: Make sure you have RCT_NEW_ARCH_ENABLED=1 in your Podfile or environment.

For Android: Make sure you have newArchEnabled=true in your gradle.properties.

Manual installation (Legacy)

iOS

  • In XCode, in the project navigator, right click LibrariesAdd Files to [your project's name]
  • Go to node_modulesrn-qr-generator and add RNQrGenerator.xcodeproj
  • In XCode, in the project navigator, select your project. Add libRNQrGenerator.a to your project's Build PhasesLink Binary With Libraries
  • Run your project (Cmd+R)

Android

  • 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
  • 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')
    
  • Insert the following lines inside the dependencies block in android/app/build.gradle:
    dependencies {
    + implementation project(':rn-qr-generator')
    }
    

Usage

import RNQRGenerator from 'rn-qr-generator';

// Generate QR Code
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));

TypeScript Support

This library includes TypeScript definitions out of the box:

import RNQRGenerator, { 
  QRCodeGenerateOptions, 
  QRCodeGenerateResult,
  QRCodeDetectOptions,
  QRCodeScanResult 
} from 'rn-qr-generator';

const options: QRCodeGenerateOptions = {
  value: 'Hello World',
  width: 200,
  height: 200,
  correctionLevel: 'H',
};

const result: QRCodeGenerateResult = await RNQRGenerator.generate(options);

API Reference

generate

Generates a QR code image from the provided value.

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)

Response

PropertyTypeDescription
uristringPath of the generated image.
widthnumberWidth of the generated image.
heightnumberHeight of the generated image.
base64stringBase64 encoded string of the image (if requested).

detect

Detects QR codes in an image.

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.

Response

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

Supported Barcode Types

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

2FA QR Code 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.

Migration from 1.x to 2.x

Version 2.0.0 adds support for React Native's New Architecture (TurboModules). The JavaScript API remains the same, so migration should be seamless:

  • Update the package:

    npm install rn-qr-generator@latest
    # or
    yarn upgrade rn-qr-generator
    
  • For iOS, run:

    cd ios && pod install && cd ../
    
  • For Android, rebuild your app.

Breaking Changes:

  • Minimum React Native version is now 0.71.0
  • Minimum iOS version is now 13.0
  • Minimum Android SDK version is now 21

Dependencies

This module uses ZXing library for encoding and decoding codes:

Troubleshooting

Simulator Issues

Some simulators may not generate QR codes properly. Use a real device if you get an error.

New Architecture Issues

If you encounter issues with the New Architecture:

  • Make sure your React Native version is 0.71.0 or higher
  • Verify that the New Architecture is properly enabled in your project
  • Clean and rebuild your project:
    # iOS
    cd ios && pod install && cd ..
    npx react-native run-ios
    
    # Android
    cd android && ./gradlew clean && cd ..
    npx react-native run-android
    

License

MIT

Keywords

react-native

FAQs

Package last updated on 28 Jan 2026

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts