Repository navigation
feat: React Native support - #671
Merged
Merged
Conversation
…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
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
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
This branch was successfully deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Requested by Greg · project thread
Adds React Native support, as asked for in discussion #670. The same
ReactQRCodecomponent now renders in React Native 0.82+ and Expo SDK 55+ throughreact-native-svg.How it works
src/platform/primitives.ts, which provides DOM tags. The native build swaps inprimitives.native.ts, which provides react-native-svg elements.shapeRendering,crossOrigin, finder pattern rotation and label fitting.vite.native.config.ts) emitsdist/index.native.jsanddist/native/*.d.ts.react-nativeexport condition. A top-levelreact-nativefield covers Metro configs that have package exports turned off.browseris listed first, so Expo web keeps the DOM build.react-native(>=0.82) andreact-native-svg(>=15) are optional peer dependencies, so web installs are unchanged.API changes
toDataURL({ size }), which resolves with a PNG data URL that issizepixels wide. On the web it shares the canvas code withdownload().svg(the react-native-svgSvginstance) andtoDataURL(), but nodownload().imageSettings.srcalso acceptsrequire('./logo.png'), andsvgPropsare react-native-svgSvgProps.imageSettings.height,opacityandcrossOrigin, and centred the logo whenxorywas0.Native specifics
textLength, so long frame labels are squeezed with a horizontal scale transform instead.scale(1/k)group, because otherwise Android spaces the glyphs unevenly.toDataURLpasses the size in pixels on Android and in points on iOS, since iOS multiplies by the screen scale. Both give a PNGsizepixels wide.Example and CI
examples/nativeis 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.pnpm install && pnpm example:nativefrom the root. The tooling is cross-platform and was checked on Windows (Git Bash).Docs
/react-nativepage: install, usage, PNG export, logos, differences from the web, Expo web and Jest setup.toDataURLis documented on/ref-api.llms.txtandllms-full.txt.ignorelist.Testing
main: 13 prop configurations were rendered withreact-dom/serveragainst main's build, with no differences. Earlier, 65 style cases were compared pixel for pixel.pnpm devkeeps watching the library.toDataURLsizing comes from reading react-native-svg's source.Known limitations
require()logo or native-onlysvgProps. The docs cover this.ReactQRCodeRefnow requirestoDataURL, so hand-typed mocks of the ref need it added.sizeprop. A code shown or exported much larger thansizecan show the old uneven spacing again.mainand not touched here:.d.tsfiles use extensionless imports, which fail undermoduleResolution: node16, and there is no CJS entry.