Web example demonstrating react-native-view-shot in browsers using html2canvas-pro.
npm install
npm startOpens at http://localhost:3000
- Basic ViewShot: Simple captures with PNG/JPG formats and Base64/Data URI output
- Transparency Test: PNG transparency support (with html2canvas-pro limitations)
- Image Capture: Views with styled elements and colors
- Complex Layouts: Nested views with flexbox, shadows, borders, and gradients
import {captureRef} from "react-native-view-shot";
const viewRef = useRef(null);
const capture = async () => {
const uri = await captureRef(viewRef.current, {
format: "png",
quality: 0.9,
result: "data-uri",
});
console.log("Captured:", uri);
};- React Native Web for cross-platform components
- html2canvas-pro for web screenshot capture
- Webpack for bundling
- TypeScript for type safety
result: 'tmpfile'falls back to 'data-uri' (with warning)snapshotContentContainernot implemented- Transparency edge cases due to html2canvas-pro
- CORS restrictions on external images
npm run build # Production build in dist/
npm run clean # Remove dist/The web example has comprehensive Playwright tests that run in CI:
npm run test:e2e # Run tests headless
npm run test:e2e:headed # Run tests with visible browserTests verify:
- ✅ App loads and navigation works
- ✅ PNG capture functionality
- ✅ JPG capture functionality
- ✅ Base64 output format
- ✅ All screens render correctly
- ✅ Images are actually generated
Tests run automatically in GitHub Actions CI with Chromium.
For local development and debugging:
- Start dev server:
npm start - Open browser:
http://localhost:3000 - Test capture:
- Click "Basic ViewShot"
- Click "📸 PNG (Data URI)"
- Verify image appears
- Try download functionality
See .github/workflows/ci.yml - the test-web-example job runs all Playwright tests in headless Chromium.
CI Artifacts:
web-snapshots-actual: Actual, expected and diff images from failed comparisonsplaywright-report: Full HTML test reportplaywright-test-results: Detailed test results
When snapshots differ:
- The CI will show a clear message in the GitHub Actions summary
- Run
./scripts/update-snapshots-from-ci.sh <RUN_ID>fromexample-web/to import only the actual images fromweb-snapshots-actual - Review every changed reference image and commit only intended visual changes
Note: Committed reference images are generated on Linux. Local non-Linux runs use separate platform-suffixed images; do not replace the Linux references with macOS or Windows output. See snapshot guidance.