1.0.6 • Published 7 months ago

@masumdev/rn-qrcode v1.0.6

Weekly downloads
-
License
MIT
Repository
github
Last release
7 months ago

@masumdev/rn-qrcode

A powerful and easy-to-use QR code scanning and generation library for React Native applications.

Sponsor

Demo

Youtube Tutorial

Features

  • 🎨 Rich QR Code styling with fully customizable:
    • Colors and gradients
    • Patterns and shapes
    • Corner styles and dot designs
    • Background effects
  • 🖼️ Custom logo placement with adjustable size and position
  • 🌈 Beautiful preset templates and themes
  • 🔍 Comprehensive format support for:
    • URLs and deep links
    • Contact information (vCard, meCard)
    • Calendar events
    • Wi-Fi configurations
    • And more!
  • 🎯 Adjustable error correction levels (L, M, Q, H)
  • 📦 Seamless integration with React Native projects
  • 💫 Cross-platform compatibility (iOS & Android)
  • ⚡ High-performance QR code generation
  • 🎭 Multiple design variants and styles

Installation

Prerequisites

Make sure you have these peer dependencies installed in your React Native project:

{
  "react": ">=18.3.1",
  "react-native": ">=0.76.9",
  "react-native-svg": ">=15.8.0"
}

Installing peer dependencies

npm install react-native-svg

or

yarn add react-native-svg

or

bun add react-native-svg

or

pnpm add react-native-svg

Installing @masumdev/rn-qrcode

npm install @masumdev/rn-qrcode

or

yarn add @masumdev/rn-qrcode

or

bun add @masumdev/rn-qrcode

or

pnpm add @masumdev/rn-qrcode

Usage

Basic Usage

import { QRCode } from '@masumdev/rn-qrcode';

const GeneratorComponent = () => {
  return <QRCode variant="BASIC" value="https://github.com/masumrpg" size={300} backgroundColor="white" errorCorrectionLevel="H" includeBackground />;
};

Advanced Usage

import { QRCode } from '@masumdev/rn-qrcode';
import { View } from 'react-native';

export default function App() {
  // Rain Effect
  return (
    <View style={{ flex: 1, alignItems: 'center', justifyContent: 'center' }}>
      <QRCode
        value="Rain Qr Code"
        size={qrSize}
        color="#2074a7"
        version={2}
        eye={{
          topLeft: {
            shape: 'square',
            size: {
              center: 1.2,
              inner: 1.3,
            },
            radius: {
              radiusOuter: 20,
              radiusInner: 13,
              radiusCenter: 10,
            },
          },
          topRight: {
            shape: 'square',
            size: {
              center: 1.2,
              inner: 1.3,
            },
            radius: {
              radiusOuter: 20,
              radiusInner: 13,
              radiusCenter: 10,
            },
          },
          bottomLeft: {
            shape: 'square',
            size: {
              center: 1.2,
              inner: 1.3,
            },
            radius: {
              radiusOuter: 20,
              radiusInner: 13,
              radiusCenter: 10,
            },
          },
        }}
        piece={{
          shape: 'rain',
          size: 1,
        }}
        includeBackground
      />
    </View>
  );
}

API Reference

QRCodeProps

Core properties for customizing the QR code appearance and behavior.

PropTypeDefaultDescription
valuestring-The content to be encoded in the QR code. Can be any text, URL, or data string.
variantQRCodeVariant'BASIC'The design variant of the QR code. Choose from predefined templates.
sizenumber256The size of the QR code in pixels. Determines both width and height.
colorstring'#000'The main color of the QR code elements. Accepts any valid CSS color value.
backgroundColorstring'transparent'The background color behind the QR code. Set to 'transparent' for no background.
gradientQRCodeGradientConfig-Advanced gradient configuration for creating beautiful color transitions.
logoLogoOptions-Options for adding a centered logo image with customizable size and styling.
piecePieceOptions-Customize the shape and style of individual QR code elements.
eyeEyeOptions-Style the three corner finder patterns (eyes) of the QR code.
includeBackgroundbooleanfalseWhen true, adds a wrapper background element behind the QR code.
versionQRCodeVersion-Set a specific QR code version (1-40). Higher versions can store more data.
maxVersionQRCodeVersion-The maximum allowed QR code version. Useful for limiting complexity.
imageClipImageProps-Props for adding an image as a clip mask to the QR code pattern, SVG Props
errorCorrectionLevelQRCodeErrorCorrectionLevel'M'Error correction capability: L (7%), M (15%), Q (25%), or H (30%).

QRCodeVariant

Choose from a range of predefined templates to quickly style your QR code. | Value | Description | Visual Effect | |-------|-------------|---------------| | 'BASIC' | Simple, basic QR code | Minimalistic, clean | | 'TRIANGLE' | Triangle-shaped QR code | Triangular, elegant | | 'HEART' | Heart-shaped QR code | Hearty, romantic | | 'DOT' | Dotted QR code pattern | Modern, minimalist | | 'WITH_LOGO' | QR code with centered logo | Professional, branded | | 'RAIN' | Rainy QR code with falling pieces | Rainy, atmospheric | | 'LINEAR_GRADIENT' | Linear gradient colored QR code | Smooth, colorful | | 'RADIAL_GRADIENT' | Radial gradient colored QR code | Dynamic, radiant | | 'IMAGE_BACKGROUND' | QR code with image background | Creative, unique |

QRCodeGradientConfig

Create beautiful gradient effects for your QR code with these advanced configuration options.

PropTypeDefaultDescription
type'linear' | 'radial''linear'Choose between linear (straight line) or radial (circular) gradient patterns
maskLogobooleanfalseWhen true, prevents the gradient from overlaying the logo area
directionGradientDirection'to-right'Sets the flow direction for linear gradients (see GradientDirection below)
colorsGradientColor[]-Define multiple color stops with position and opacity for smooth transitions
cxstring'50%'Center X position of radial gradient (e.g. '50%' for middle)
cystring'50%'Center Y position of radial gradient (e.g. '50%' for middle)
rstring'50%'Radius of the radial gradient (e.g. '50%' for half of QR code size)
fxstring-Focal point X position for radial gradient (creates elliptical effects)
fystring-Focal point Y position for radial gradient (creates elliptical effects)
x1string'0%'Starting X position for linear gradient (e.g. '0%' for left edge)
y1string'0%'Starting Y position for linear gradient (e.g. '0%' for top edge)
x2string'100%'Ending X position for linear gradient (e.g. '100%' for right edge)
y2string'0%'Ending Y position for linear gradient (e.g. '0%' for top edge)

GradientDirection

Specify the flow direction of linear gradients. This setting creates dynamic and visually appealing QR codes.

ValueDescriptionVisual Effect
'to-right'Gradient flows from left to rightHorizontal transition →
'to-left'Gradient flows from right to leftHorizontal transition ←
'to-bottom'Gradient flows from top to bottomVertical transition ↓
'to-top'Gradient flows from bottom to topVertical transition ↑
'to-bottom-right'Gradient flows diagonally from top-left to bottom-rightDiagonal transition ↘
'to-bottom-left'Gradient flows diagonally from top-right to bottom-leftDiagonal transition ↙
'to-top-right'Gradient flows diagonally from bottom-left to top-rightDiagonal transition ↗
'to-top-left'Gradient flows diagonally from bottom-right to top-leftDiagonal transition ↖

GradientColor

Define smooth color transitions by specifying multiple color stops in your gradient. Each stop controls position, color, and transparency.

PropTypeDescriptionExample
offsetstringPosition of the color stop along the gradient (0-100%)'0%' for start, '50%' for middle, '100%' for end
colorstringAny valid color value (hex, rgb, named colors)'#FF5733', 'rgb(255,87,51)', 'coral'
opacitynumberTransparency level between 0 (invisible) and 1 (solid)0.8 for 80% opacity

LogoOptions

Customize the appearance of a centered logo within your QR code. The logo can be an image from your local assets or a remote URL.

PropTypeDefaultDescriptionNotes
sourceImageSource-Logo image source (local asset/URL)See ImageSource below for format details
sizenumber20%Logo size as percentage of QR code widthKeep between 10-30% for best scanning
backgroundColorstring'white'Background color behind the logoUse light colors for better contrast
paddingnumber2Space around logo in pixelsHelps logo stand out from QR pattern
borderRadiusnumber0Rounded corners for logo backgroundHigher values create circular shapes

ImageSource

Specify the source of your logo image. The component supports both local project assets and remote image URLs.

TypeDescriptionExampleBest Practices
numberLocal image from project assetsrequire('./assets/logo.png')Use for bundled images
stringRemote image from URL'https://example.com/logo.png'Ensure reliable hosting

Important Guidelines:

  • Local assets: Use require() for images in your project directory
  • Remote URLs: Provide complete HTTPS URLs for security
  • Supported formats: PNG (recommended), JPG, JPEG
  • Optimal size: 50-100 pixels for best balance of clarity and scanning
  • File size: Keep under 50KB to maintain performance

PieceOptions

Customize the appearance of individual QR code elements (the small squares that make up the pattern).

PropTypeDefaultDescriptionVisual Impact
shape'square'|'dot'|'triangle'|'heart'|'rain''square'Shape of each QR code elementChanges overall pattern style
sizenumber1Scale factor for element size (0.5-2.0)Affects density and readability
spacingnumber0Gap between elements in pixelsCreates breathing room in pattern

EyeOptions

Style the three finder patterns (eyes) in the corners of the QR code. These are crucial for scanner orientation.

PropTypeDefaultDescriptionImpact
topLeftEyeShapeConfig{}Style for top-left corner patternAffects scanning reliability
topRightEyeShapeConfig{}Style for top-right corner patternMust remain distinct
bottomLeftEyeShapeConfig{}Style for bottom-left corner patternHelps orientation
EyeShapeConfig

Detailed configuration for each QR code eye (finder pattern).

PropTypeDefaultDescriptionBest Practice
shape'square'|'circle'|'rounded''square'Overall shape of the eye patternKeep distinctive
size{ center: number, inner: number }-Size multiplier for center and inner componentsMaintain proportions
radius{ radiusOuter: number, radiusInner: number, radiusCenter: number }-Corner rounding for each partBalance style with function
colorstring-Main color of the eye patternUse high contrast
innerColorstring-Color of the inner eye componentComplement main color

QRCodeVersion

Control the size and data capacity of your QR code.

TypeDescriptionUse Case
number (1-40)QR code version numberHigher versions = more data, larger size

Version Guide:

  • 1-10: Best for short URLs and text (up to 174 characters)
  • 11-20: Medium content (up to 1,663 characters)
  • 21-40: Large content like vCards or detailed data

ImageProps

Advanced SVG image properties for creating custom QR code patterns. | Prop | Type | Default | Description | Notes | |--------------------|-----------|---------|--------------------------------------------------|--------| | x | number | - | Horizontal position of the image | Position from left | | y | number | - | Vertical position of the image | Position from top | | width | number | - | Width of the image | In pixels or percentage | | height | number | - | Height of the image | In pixels or percentage | | xlinkHref | ImageSource | string | - | Source of the image (legacy attribute) | Use href instead | | href | ImageSource | string | - | Source of the image | Preferred over xlinkHref | | preserveAspectRatio | string | - | How image should scale (e.g., 'xMidYMid meet') | Controls image fitting | | opacity | number | 1 | Transparency of the image (0-1) | 0 = transparent, 1 = solid | | onLoad | function | - | Callback when image loads | Handles load completion |

QRCodeErrorCorrectionLevel

Balance between data redundancy and error correction capability.

LevelError Correction CapacityBest Used For
L~7% damage recoveryClean environments, maximum data capacity
M~15% damage recoveryStandard use, good balance
Q~25% damage recoveryPublic display, some wear expected
H~30% damage recoveryOutdoor use, high reliability needed

License

MIT