QRCode
A QR code for any text or URL, drawn with plain views: no react-native-svg, no native module. The encoder is written in TypeScript and follows ISO/IEC 18004: byte mode (UTF-8), the four error-correction levels and all 40 versions, picking the smallest that fits.
import { QRCode } from 'patine-ui';
<QRCode value="https://github.com/patine-ui/patine" size={180} accessibilityLabel="Scan to open the Patine repository" />
Try the props
errorCorrectionsizequietZone<QRCode value="https://github.com/patine-ui/patine" />
Example: a concert ticket
A ticket in an events app: the code holds the ticket's ID for the door scanner, sits on a white plate so it scans in dark mode too, and is named for screen readers.
<Box border radius="lg" padding="lg" gap="md" style={{ width: '100%', maxWidth: 340 }}> <VStack gap="xs"> <HStack justify="space-between" align="center"> <Text size="lg" weight="semibold">{TICKET.event}</Text> <Badge variant="success">Valid</Badge> </HStack> <Text color="textSecondary">{TICKET.venue}</Text> <Text color="textSecondary">{TICKET.date}</Text> </VStack> <Separator /> <VStack align="center" gap="sm"> <QRCode value={TICKET.id} size={180} backgroundColor="#FFFFFF" color="#111827" accessibilityLabel={`Ticket code for ${TICKET.event}, ${TICKET.holder}`} /> <Text size="sm" style={{ fontFamily: 'monospace' }}>{TICKET.id}</Text> </VStack> <HStack justify="space-between"> <Text size="sm" color="textSecondary">{TICKET.section}</Text> <Text size="sm" color="textSecondary">{TICKET.holder}</Text> </HStack> <Button variant="outline">Add to wallet</Button> </Box>
Logo
Pass anything as logo: an Image, an emoji, your icon. The modules under it are cleared onto a plate in the background colour, and the level switches to H, which recovers about 30% of the code, so it still scans.
<QRCode value="https://github.com/patine-ui/patine" size={200} logo={<Icon name="rocket" size={36} color="#1E1B4B" strokeWidth={2} />} color="#1E1B4B" />
Colours and dark mode
Scanners expect dark modules on a light ground, so the code stays black on white in dark mode too. Choose any color and backgroundColor with strong contrast; inverted codes (light on dark) fail on many readers.
The matrix
createQRCode(text, options) returns the encoded matrix, for drawing it yourself (an SVG, a canvas, a printed PDF) or testing:
import { createQRCode } from 'patine-ui';
const { version, size, modules } = createQRCode('WIFI:T:WPA;S:Home;P:secret;;', { errorCorrection: 'Q' });
// modules[y][x] is true for a dark module; size is 17 + 4 × version.
It throws a RangeError when the text is longer than version 40 holds (2,953 bytes at L, 1,273 at H); <QRCode> calls onError and draws nothing.
Accessibility
The code is an image named "QR code"; pass an accessibilityLabel that says where it leads, such as "Scan to pay Ana €12".
Props
| Prop | Type | Default | Description |
|---|---|---|---|
value | string | — | Text or URL, encoded as UTF-8. |
size | number | 200 | Width and height, quiet zone included. Modules snap to whole points; the rest widens the quiet zone. |
errorCorrection | 'L' | 'M' | 'Q' | 'H' | 'M', 'H' with a logo | About 7%, 15%, 25% and 30% recovery. |
color | string | '#000000' | Dark modules. |
backgroundColor | string | '#FFFFFF' | Ground and quiet zone. |
quietZone | number | 4 | Margin in modules. |
logo | ReactNode | — | Shown in the centre on a cleared plate. |
logoSize | number | 0.22 | The plate's share of the width, up to 0.3. |
accessibilityLabel | string | 'QR code' | |
onError | (error: Error) => void | — | The value is too long. |
style | StyleProp<ViewStyle> | — | |
theme / design | provider's | Rounds the corners like the design's cards. |