Skip to content

Commit f13c3db

Browse files
author
greweb
committed
ci: introduce examples for windows and web
1 parent 7bcb9d9 commit f13c3db

File tree

77 files changed

+20834
-55
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

77 files changed

+20834
-55
lines changed

.github/workflows/ci.yml

Lines changed: 519 additions & 6 deletions
Large diffs are not rendered by default.

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,9 @@ lib/
5252
*.tgz
5353
*.tar.gz
5454

55+
# Web example build
56+
example-web/dist/
57+
5558
# Runtime data
5659
pids
5760
*.pid

.npmignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
example
2+
example-web
3+
example-windows
24

35
# OSX
46
#

README.md

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -175,32 +175,39 @@ Returns a Promise of the image URI.
175175

176176
- **`options`**: the same options as in `captureRef` method.
177177

178-
### Advanced Examples
178+
## Examples
179179

180-
[Checkout react-native-view-shot-example](example)
180+
### Native Example (iOS & Android)
181+
182+
[Checkout react-native-view-shot-example](example) - Comprehensive example app demonstrating all features on iOS and Android.
183+
184+
### Web Example
185+
186+
[Checkout react-native-view-shot-web-example](example-web) - Web example demonstrating how the library works in browsers using html2canvas.
181187

182188
## Interoperability Table
183189

184190
> Snapshots are not guaranteed to be pixel perfect. It also depends on the platform. Here is some difference we have noticed and how to workaround.
185191
186192
Model tested: iPhone 6 (iOS), Nexus 5 (Android).
187193

188-
| System | iOS | Android | Windows |
189-
| --------------------- | ---------------- | ----------------- | ---------------------- |
190-
| View,Text,Image,.. | YES | YES | YES |
191-
| WebView | YES | YES<sup>1</sup> | YES |
192-
| gl-react v2 | YES | NO<sup>2</sup> | NO<sup>3</sup> |
193-
| react-native-video | NO | NO | NO |
194-
| react-native-maps | YES | NO<sup>4</sup> | NO<sup>3</sup> |
195-
| react-native-svg | YES | YES | maybe? |
196-
| react-native-camera   | NO               | YES               | NO <sup>3</sup>        |
194+
| System | iOS | Android | Windows | Web |
195+
| ------------------- | --- | --------------- | --------------- | ------------------- |
196+
| View,Text,Image,.. | YES | YES | YES | YES |
197+
| WebView | YES | YES<sup>1</sup> | YES | N/A |
198+
| gl-react v2 | YES | NO<sup>2</sup> | NO<sup>3</sup> | NO<sup>3</sup> |
199+
| react-native-video | NO | NO | NO | NO |
200+
| react-native-maps | YES | NO<sup>4</sup> | NO<sup>3</sup> | NO<sup>3</sup> |
201+
| react-native-svg | YES | YES | maybe? | LIMITED<sup>5</sup> |
202+
| react-native-camera | NO | YES | NO <sup>3</sup> | NO<sup>3</sup> |
197203

198204
>
199205
200206
1. Only supported by wrapping a `<View collapsable={false}>` parent and snapshotting it.
201207
2. It returns an empty image (not a failure Promise).
202208
3. Component itself lacks platform support.
203209
4. But you can just use the react-native-maps snapshot function: https://github.com/airbnb/react-native-maps#take-snapshot-of-map
210+
5. Web support via html2canvas has limitations with SVG rendering. Basic SVG works, complex SVG may have issues.
204211

205212
## Performance Optimization
206213

eslint.config.js

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,22 @@ import js from "@eslint/js";
33
import prettier from "eslint-config-prettier";
44

55
export default [
6+
// Global ignores
7+
{
8+
ignores: [
9+
"**/node_modules/**",
10+
"**/dist/**",
11+
"**/build/**",
12+
"**/lib/**",
13+
"**/.expo/**",
14+
"**/android/build/**",
15+
"**/android/app/build/**",
16+
"**/ios/build/**",
17+
"**/ios/Pods/**",
18+
"**/example-web/dist/**",
19+
"**/*.min.js",
20+
],
21+
},
622
js.configs.recommended,
723
prettier,
824
{
@@ -52,7 +68,12 @@ export default [
5268
},
5369
// Node.js files (metro.config.js, etc.)
5470
{
55-
files: ["**/metro.config.js", "**/babel.config.js", "**/.detoxrc.js"],
71+
files: [
72+
"**/metro.config.js",
73+
"**/babel.config.js",
74+
"**/webpack.config.js",
75+
"**/.detoxrc.js",
76+
],
5677
languageOptions: {
5778
globals: {
5879
__dirname: "readonly",

example-web/.gitignore

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# Dependencies
2+
node_modules/
3+
4+
# Build output
5+
dist/
6+
build/
7+
8+
# Playwright
9+
playwright-report/
10+
test-results/
11+
e2e/snapshots/output/
12+
13+
# Logs
14+
*.log
15+
npm-debug.log*
16+
yarn-debug.log*
17+
yarn-error.log*
18+
19+
# Editor
20+
.vscode/
21+
.idea/
22+
*.swp
23+
*.swo
24+
*~
25+
26+
# OS
27+
.DS_Store
28+
Thumbs.db
29+
30+
# Misc
31+
.env
32+
.env.local
33+

example-web/.npmrc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Use legacy peer deps to avoid conflicts with react-native-web
2+
legacy-peer-deps=true
3+

example-web/README.md

Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
# React Native View Shot - Web Example
2+
3+
Web example demonstrating `react-native-view-shot` in browsers using `html2canvas`.
4+
5+
## Quick Start
6+
7+
```bash
8+
npm install
9+
npm start
10+
```
11+
12+
Opens at `http://localhost:3000`
13+
14+
## What's Included
15+
16+
- **Basic ViewShot**: Simple captures with PNG/JPG formats and Base64/Data URI output
17+
- **Transparency Test**: PNG transparency support (with html2canvas limitations)
18+
- **Image Capture**: Views with styled elements and colors
19+
- **Complex Layouts**: Nested views with flexbox, shadows, borders, and gradients
20+
21+
## Usage Example
22+
23+
```typescript
24+
import {captureRef} from "react-native-view-shot";
25+
26+
const viewRef = useRef(null);
27+
28+
const capture = async () => {
29+
const uri = await captureRef(viewRef.current, {
30+
format: "png",
31+
quality: 0.9,
32+
result: "data-uri",
33+
});
34+
console.log("Captured:", uri);
35+
};
36+
```
37+
38+
## Tech Stack
39+
40+
- React Native Web for cross-platform components
41+
- html2canvas for web screenshot capture
42+
- Webpack for bundling
43+
- TypeScript for type safety
44+
45+
## Web Limitations
46+
47+
- `result: 'tmpfile'` falls back to 'data-uri' (with warning)
48+
- `snapshotContentContainer` not implemented
49+
- Transparency edge cases due to html2canvas
50+
- CORS restrictions on external images
51+
52+
## Build
53+
54+
```bash
55+
npm run build # Production build in dist/
56+
npm run clean # Remove dist/
57+
```
58+
59+
## Testing
60+
61+
### Automated E2E Tests (Playwright)
62+
63+
The web example has comprehensive Playwright tests that run in CI:
64+
65+
```bash
66+
npm run test:e2e # Run tests headless
67+
npm run test:e2e:headed # Run tests with visible browser
68+
```
69+
70+
**Tests verify:**
71+
72+
- ✅ App loads and navigation works
73+
- ✅ PNG capture functionality
74+
- ✅ JPG capture functionality
75+
- ✅ Base64 output format
76+
- ✅ All screens render correctly
77+
- ✅ Images are actually generated
78+
79+
Tests run automatically in GitHub Actions CI with Chromium.
80+
81+
### Manual Testing
82+
83+
For local development and debugging:
84+
85+
1. **Start dev server:** `npm start`
86+
2. **Open browser:** `http://localhost:3000`
87+
3. **Test capture:**
88+
- Click "Basic ViewShot"
89+
- Click "📸 PNG (Data URI)"
90+
- Verify image appears
91+
- Try download functionality
92+
93+
### CI Pipeline
94+
95+
See `.github/workflows/ci.yml` - the `test-web-example` job runs all Playwright tests in headless Chromium.
96+
97+
**CI Artifacts:**
98+
99+
- `web-snapshots-reference`: Current reference snapshots (download to update local snapshots)
100+
- `web-snapshots-diff`: Visual diffs when tests fail (actual vs expected)
101+
- `playwright-report`: Full HTML test report
102+
- `playwright-test-results`: Detailed test results
103+
104+
**When snapshots differ:**
105+
106+
- The CI will show a clear message in the GitHub Actions summary
107+
- Download the `web-snapshots-reference` artifact
108+
- Replace `example-web/e2e/snapshots/reference/` with the downloaded files
109+
- Commit the updated snapshots
110+
111+
**Note:** Snapshots are platform-specific (Linux vs macOS). The CI runs on Linux, so you may need to update snapshots when running locally on macOS.
112+
113+
## Related
114+
115+
- [Main Library](../)
116+
- [Native Example](../example/)
117+
- [html2canvas](https://html2canvas.hertzen.com/)

example-web/babel.config.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
module.exports = {
2+
presets: [
3+
["@babel/preset-env", {targets: {node: "current"}}],
4+
"@babel/preset-react",
5+
"@babel/preset-typescript",
6+
],
7+
};

example-web/e2e/snapshots/.gitkeep

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# Playwright snapshots directory
2+
# reference/ contains golden snapshots
3+
# output/ contains test results (git ignored)
4+

0 commit comments

Comments
 (0)