1.0.4 • Published 9 months ago

rn-barcode-renderer v1.0.4

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

rn-barcode-renderer

A Barcode and Qr Code renderer for React Native based on @shopify/react-native-skia.

Features

  • Barcode render
  • Qr code render
  • Add gradient
  • Optional logotype for qr code

Installation

Start by installing the peer dependency of rn-barcode-renderer:

yarn add @shopify/react-native-skia

Then install rn-barcode-renderer:

yarn add rn-barcode-renderer

Usage

Barcode

import { BarcodeView } from "rn-barcode-renderer";

// Simple usage

return <BarcodeView format="CODE128" value="123456" />;

// Add background, bars color, border raidus, background blur effect, padding...

return (
  <BarcodeView
    format="CODE128"
    value="123456"
    padding={10}
    borderRadius={10}
    color="blue"
    bgColor="lightgray"
    bgBlur={5}
  />
);

Barcode Props

Prop NameTypeDescription
valuestring (required)The value of the barcode.
formatFormat (required)The format of the barcode.
barWidthnumberThe width of each bar in the barcode. Default is 2.
heightnumberThe height of the barcode. Default is 100.
colorstringThe color of the barcode lines. Default is "#000000".
bgColorstringThe background color of the barcode. Default is "#ffffff".
onError() => voidCallback function to handle errors during barcode encoding. Should be wrapped in useCallback.
maxWidthnumberThe maximum width of the barcode. If specified, the barcode will be scaled down to fit within this width.
paddingnumberThe padding around the barcode. Default is 0.
borderRadiusnumberThe border radius of the wrapper rectangle around the barcode. Default is 0.
bgBlurnumberThe blur radius for the background of the barcode. Default is 0.

Qr Code

import { QrCode } from "rn-barcode-renderer";

// Simple usage

return <QrCode value="Hello World!" />;

// Add background, color, border raidus, background blur effect, padding, change size...

return (
  <QrCode
    value="Hello World!"
    color="blue"
    bgColor="lightgray"
    padding={10}
    borderRadius={8}
    size={150}
  />
);

Render QR Code with logo

import { QrCode, QrLogo } from "rn-barcode-renderer";

return (
  <QrCode
    value="Hello World!"
    renderLogo={(defaultProps) => (
      <QrLogo
        src={require("./assets/favicon.png")}
        padding={2}
        borderRadius={9999}
        bgColor="white"
        {...defaultProps}
      />
    )}
  />
);

Qr Code props

Prop nameTypeDescription
valuestring (required)The value of the QR code.
sizenumberThe size of the QR code. Default value: 100.
colorstringThe color of the QR code. Default value: "black".
bgColorstringThe background color of the QR code. Default value: "white".
borderRadiusnumberThe border radius of the QR code. Default value: 0.
bgBlurnumberThe blur of the background of the QR code. Default value: 0.
paddingnumberThe padding of the QR code. Default value: 0.
eclErrorCorrectionLevelThe error correction level of the QR code. Default value: "M".
onError() => voidCallback function to handle errors. Should be wrapped in useCallback.
renderLogo(defaultProps: { qrSize: number }) => React.ReactNodeFunction to render a logo on the QR code. Receives the default props: { qrSize: number }.

Methods (BarcodeView and QrCode)

MethodDescription
getBytes(format?: ImageFormat, quality?: number)Returns the barcode image as a Uint8Array.
getBase64(format?: ImageFormat, quality?: number)Returns the barcode image as a base64-encoded string.
getImageInfo()Returns information about the barcode image.

Contributing

  1. Fork and clone the repository
  2. Install the project dependencies by running yarn install.
  3. To develop the library in unison with the example app you can run yarn dev
  4. Implement your changes, as well as any documentation.
  5. Create a changeset for your changes by running yarn changeset.
  6. Open a pull request with your changes and changeset.

License

MIT

1.0.4

9 months ago

1.0.3

1 year ago

1.0.2

1 year ago

1.0.1

1 year ago

1.0.0

1 year ago