Skip to content

feat: React Native support - #671

Merged
LGLabGreg merged 10 commits into
mainfrom
claude/project-thread-0mdvxy
Nov 14, 2026
Merged

LGLabGreg merged 10 commits into
mainfrom
claude/project-thread-0mdvxy

Conversation

@LGLabGreg

@LGLabGreg LGLabGreg commented Nov 14, 2026 •

Copy link
Copy Markdown
Owner

Requested by Greg · project thread

Adds React Native support, as asked for in discussion #670. The same ReactQRCode component now renders in React Native 0.82+ and Expo SDK 55+ through react-native-svg.

How it works

  • Components import their SVG elements from src/platform/primitives.ts, which provides DOM tags. The native build swaps in primitives.native.ts, which provides react-native-svg elements.
  • The few attributes that differ go through small helpers in the same module: test ids, text baseline, shapeRendering, crossOrigin, finder pattern rotation and label fitting.
  • A second Vite build (vite.native.config.ts) emits dist/index.native.js and dist/native/*.d.ts.
  • Metro picks the native build through a new react-native export condition. A top-level react-native field covers Metro configs that have package exports turned off. browser is listed first, so Expo web keeps the DOM build.
  • react-native (>=0.82) and react-native-svg (>=15) are optional peer dependencies, so web installs are unchanged.

API changes

  • Both refs gain toDataURL({ size }), which resolves with a PNG data URL that is size pixels wide. On the web it shares the canvas code with download().
  • The native ref has svg (the react-native-svg Svg instance) and toDataURL(), but no download().
  • On native, imageSettings.src also accepts require('./logo.png'), and svgProps are react-native-svg SvgProps.
  • Fix: PNG and JPEG exports now draw the logo from the calculated image settings. Before this, they ignored imageSettings.height, opacity and crossOrigin, and centred the logo when x or y was 0.

Native specifics

  • Long labels: react-native-svg ignores textLength, so long frame labels are squeezed with a horizontal scale transform instead.
  • Label spacing: labels are laid out at pixel size inside a scale(1/k) group, because otherwise Android spaces the glyphs unevenly.
  • Snapshot size: toDataURL passes the size in pixels on Android and in points on iOS, since iOS multiplies by the screen scale. Both give a PNG size pixels wide.
  • Snapshot output: a failed snapshot rejects, and the line breaks iOS adds to the base64 are stripped.

Example and CI

  • examples/native is an Expo SDK 58 app in the pnpm workspace. It uses the library as an injected dependency, so it gets its own React 19.3.0.
  • To run it, use pnpm install && pnpm example:native from the root. The tooling is cross-platform and was checked on Windows (Git Bash).
  • A jest-expo suite of 72 tests renders every style, frame, gradient and logo combination through react-native-svg. CI runs its type check and tests.

Docs

  • New /react-native page: install, usage, PNG export, logos, differences from the web, Expo web and Jest setup.
  • toDataURL is documented on /ref-api.
  • React Native sections in both READMEs, llms.txt and llms-full.txt.
  • A minor changeset. The private example is in the changesets ignore list.

Testing

  • The web markup is identical to main: 13 prop configurations were rendered with react-dom/server against main's build, with no differences. Earlier, 65 style cases were compared pixel for pixel.
  • All of these pass: 198 vitest tests, the smoke test, 72 native tests, the docs type check and the docs build.
  • pnpm dev keeps watching the library.
  • Tested on a real Android phone in Expo Go.
  • iOS has not been run on a device or simulator. It is covered only by the Jest suite and a Metro bundle for iOS. The iOS toDataURL sizing comes from reading react-native-svg's source.

Known limitations

  • Expo projects resolve the React Native types, so on Expo web TypeScript won't flag a require() logo or native-only svgProps. The docs cover this.
  • ReactQRCodeRef now requires toDataURL, so hand-typed mocks of the ref need it added.
  • The native label layout scale comes from the size prop. A code shown or exported much larger than size can show the old uneven spacing again.
  • Already on main and not touched here: .d.ts files use extensionless imports, which fail under moduleResolution: node16, and there is no CJS entry.

LGLabGreg and others added 7 commits November 13, 2026 19:39
…dition

Components now render through a small primitives module. On the web it maps
to plain DOM tags; the React Native build resolves `*.native.ts(x)` files and
maps the same names onto react-native-svg. QR encoding, path generation and
frame layout are shared unchanged.

- Rotations use an SVG `transform="rotate(deg cx cy)"` attribute instead of
  CSS `transform-box`, which react-native-svg does not support. Web output is
  pixel identical.
- The native ref exposes `toDataURL()` instead of `download()`.
- `dist/index.native.js` and `dist/native/*.d.ts` are built next to the web
  bundle and selected by the `react-native` export condition.
- react-native and react-native-svg are optional peer dependencies.
- `examples/native` is a standalone Expo app for trying it on a device.

Prototype only: not verified on a device or simulator, no changeset.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Qm5gMyMoFmUXywNNAcaYhT
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Qm5gMyMoFmUXywNNAcaYhT
Expo's web target needs react-dom and react-native-web, so pressing w in
`expo start` failed to bundle. On web Expo loads the DOM build, whose ref has
download() rather than toDataURL(), so the export button now branches on
Platform.OS.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Qm5gMyMoFmUXywNNAcaYhT
The example installed a packed tarball with npm, which broke on Windows (the
scripts spawned `tsc` and `pnpm` without a shell) and failed when run with
pnpm. It is now a workspace package that depends on the library with
`injected: true`, so it gets its own copy resolving React 19.3.0 from the
example, and `syncInjectedDepsAfterScripts` refreshes that copy on every
library build. `pnpm install && pnpm example:native` from the root is the
whole setup.

The native declaration step now runs the TypeScript CLI through node, so it
works on Windows too.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Qm5gMyMoFmUXywNNAcaYhT
react-native-svg lays text out at its font size in viewBox units (about 4
units for a frame label) and then scales it up with the viewBox, roughly 7x at
300px. Small errors in the glyph advances get magnified into visibly uneven
letter spacing on Android. On native the label is now laid out at its rendered
pixel size inside a group scaled back down. Web output is unchanged.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Qm5gMyMoFmUXywNNAcaYhT
…ld in CI

Both refs now expose toDataURL({ size }), resolving with a PNG data URL.
The web version shares the canvas rendering with download(). The native
example gains a Jest suite (jest-expo) that renders every style through
react-native-svg, and CI runs its type check and tests.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Qm5gMyMoFmUXywNNAcaYhT
Adds a React Native page to the docs site (install, usage, PNG export,
logos, differences from the web), documents toDataURL on the ref API
page, the READMEs and llms.txt, and adds a minor changeset. Also fixes
the native example's type check, which needs jest, node and
react-test-renderer types under TypeScript 6.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Qm5gMyMoFmUXywNNAcaYhT
@vercel

vercel Bot commented Nov 14, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
reactqrcode-com Ready Ready Preview Nov 14, 2026 1:18pm UTC

Request Review

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Qm5gMyMoFmUXywNNAcaYhT
- Keep the web markup identical to main: finder pattern rotations use the
  CSS form on the web again, and the transform attribute only on native.
- Draw the PNG/JPEG logo from the calculated image settings, so height,
  opacity, crossOrigin and an x or y of 0 match the SVG.
- Native toDataURL: size the snapshot in pixels on both platforms (iOS
  multiplies by the screen scale), round the height, reject failed
  snapshots and strip the line breaks iOS adds to the base64.
- Restore the library watch in `pnpm dev`, drop the duplicate native type
  check, and add a top-level react-native field for Metro configs with
  package exports turned off.
- Docs: fix the sample frame style, document Expo web and Jest setup, and
  the native font default. Leave the private example out of changesets.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Qm5gMyMoFmUXywNNAcaYhT
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Qm5gMyMoFmUXywNNAcaYhT
@LGLabGreg
LGLabGreg merged commit 305ba32 into main Nov 14, 2026
3 checks passed
@LGLabGreg
LGLabGreg deleted the claude/project-thread-0mdvxy branch November 14, 2026 13:34

This branch was successfully deployed

1 active deployment
Preview — 3279b227 Deployed Nov 14, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant