Command palette

@yasinsensoy/native

React Native · Components

QRCode

Draws text or an address as a QR code.

4 exports

Live example

The preview runs in the browser with the web component; the native component takes the same props and looks the same on iOS and Android.

Preview

Code

import { QRCode } from "@yasinsensoy/native";

<QRCode value="https://github.com/yasinsensoy/ui" size={192} />

Events

  1. Events appear here when you interact with the preview.

Import

import { QRCode } from "@yasinsensoy/native";

QRCode

component

Draws text or an address as a QR code. The encoder is the same as web (@yasinsensoy/core/qr), with no external package; drawing is done with our own native view. The module size is rounded to screen pixels, so no thin lines remain between modules.

QRCode({ value, level, size, margin, shape, color, background, image, imageSize, label, minVersion, style, }: QRCodeProps): JSX.Element

Examples

<QRCode value="https://example.com/menu" size={192} />
<QRCode value={wifi} shape="dots" image={require("./logo.png")} label="Connect to Wi-Fi" />

Error correction level: how much of the code can be damaged and still be read.

  • L: ~7% (densest, smallest code)
  • M: ~15% (general use)
  • Q: ~25%
  • H: ~30% (when a logo goes in the middle)
type QRErrorLevel = "L" | "M" | "Q" | "H"

QRCodeProps

interface

Props of QRCode.

NameTypeDefaultDescription
valuestringText or address to encode.
level?QRErrorLevel"M"`, `"H"` when `image` is givenError correction level.
size?number160Width and height (px).
margin?number2Quiet zone around the code (modules). At least 2–4 is recommended for readers.
shape?QRCodeStyle"square"Module shape: square, rounded, dots.
color?string"#000"`, the theme text color when `background="transparent"Color of the dark modules. With a background the default is black; it is not bound to the theme text color, so the code reads in every theme. On a transparent background, the theme text color.
background?string"#fff"Background color. "transparent" leaves it transparent.
image?string | ImageSourcePropTypeLogo to place in the center: an address or require("./logo.png"). The modules behind it are cleared; the level becomes "H" automatically.
imageSize?number0.22Side length of the logo, as a fraction of the code (0–0.3).
label?stringvalueScreen reader name.
minVersion?EncodeQROptions["minVersion"]Minimum version (1–40); to fix the code's size.
style?StyleProp<ViewStyle>Container style.

Shape of the modules (squares).

  • square: classic squares; the most compatible with every reader.
  • rounded: squares with softened corners, finders with rounded corners.
  • dots: dots and round finders.
type QRCodeStyle = "square" | "rounded" | "dots"