### Install and Start Development Server Source: https://github.com/gre/react-native-view-shot/blob/master/example-web/README.md Install project dependencies and start the local development server. ```bash npm install npm start ``` -------------------------------- ### Web Example App Commands for react-native-view-shot Source: https://github.com/gre/react-native-view-shot/blob/master/CLAUDE.md Commands for starting the webpack development server and building a production version of the web example app. ```bash cd example-web npm start # webpack dev server on port 3000 npm run build # Production build → dist/ ``` -------------------------------- ### Example App Commands for react-native-view-shot Source: https://github.com/gre/react-native-view-shot/blob/master/CLAUDE.md Commands for running the example app on iOS and Android, starting the bundler, and managing E2E tests with Detox. ```bash npm run ios # Run on iOS simulator npm run android # Run on Android emulator npm run start # Start Metro bundler # E2E tests (Detox) npm run build:e2e:ios npm run test:e2e:ios UPDATE_SNAPSHOTS=true npm run test:e2e:ios # Regenerate reference snapshots npm run build:e2e:android npm run test:e2e:android UPDATE_SNAPSHOTS=true npm run test:e2e:android ``` -------------------------------- ### Install and Run Windows Demo Source: https://github.com/gre/react-native-view-shot/blob/master/example-windows/README.md Installs dependencies and runs the Windows demo application. Use `--no-launch --no-deploy --no-packager` to only build the app. ```bash cd example-windows npm install --legacy-peer-deps npx react-native autolink-windows npx react-native run-windows --arch x64 ``` -------------------------------- ### Install react-native-view-shot Source: https://github.com/gre/react-native-view-shot/blob/master/README.md Install the library using npm, Yarn, or Expo CLI. For iOS, ensure CocoaPods dependencies are installed. ```bash npm install react-native-view-shot # or with Yarn yarn add react-native-view-shot # In Expo npx expo install react-native-view-shot ``` ```bash npx pod-install ``` -------------------------------- ### Start Metro Bundler Source: https://github.com/gre/react-native-view-shot/blob/master/example/README.md Run this command from the root of your React Native project to start the Metro dev server. This is essential for the development workflow. ```sh # Using npm npm start # OR using Yarn yarn start ``` -------------------------------- ### Install CocoaPods Dependencies Source: https://github.com/gre/react-native-view-shot/blob/master/example/README.md Before running the iOS app, install CocoaPods dependencies. Run 'bundle install' once to install the bundler, and 'bundle exec pod install' subsequently or after updating native dependencies. ```sh bundle install bundle exec pod install ``` -------------------------------- ### Run E2E Tests for Android Source: https://github.com/gre/react-native-view-shot/blob/master/example/e2e/tests/README.md Execute the end-to-end tests for the Android platform. Ensure dependencies are installed and the project is built if necessary. ```bash npm run test:e2e:android ``` -------------------------------- ### Run iOS E2E Tests Source: https://github.com/gre/react-native-view-shot/blob/master/example/e2e/README.md Execute the end-to-end tests for the iOS platform. Navigate to the example directory and run the specified npm script. ```bash cd example npm run test:e2e:ios ``` -------------------------------- ### Run E2E Tests for iOS Source: https://github.com/gre/react-native-view-shot/blob/master/example/e2e/tests/README.md Execute the end-to-end tests for the iOS platform. Ensure dependencies are installed and the project is built if necessary. ```bash npm run test:e2e:ios ``` -------------------------------- ### Run Android E2E Tests Source: https://github.com/gre/react-native-view-shot/blob/master/example/e2e/README.md Execute the end-to-end tests for the Android platform. Navigate to the example directory and run the specified npm script. Note that Android tests may have intermittent issues. ```bash cd example npm run test:e2e:android ``` -------------------------------- ### Write New Feature Test Source: https://github.com/gre/react-native-view-shot/blob/master/example/e2e/tests/README.md Example of a new end-to-end test case. It includes navigation, scrolling, screenshot capture, validation, and cleanup steps. ```javascript it('should test new feature', async () => { // 1. Navigate to screen await navigateToScreen('Feature Name', '🎯 Feature Screen'); // 2. Scroll to ensure content is visible await scrollToBottom(); // 3. Perform action await captureScreenshot('📸 Capture Feature', 'Success!'); // 4. Wait for result await device.sleep(1000); await scrollToBottom(); // 5. Validate snapshot const result = await snapshotMatcher.captureAndValidate( 'feature_name_after_capture', null, UPDATE_REFERENCES, ); if (!UPDATE_REFERENCES && result.matched !== null) { expect(result.matched).toBe(true); } // 6. Cleanup await dismissAlert(); await goHome(); }); ``` -------------------------------- ### Update Snapshots from CI Source: https://github.com/gre/react-native-view-shot/blob/master/example-web/scripts/README.md Use this script to integrate new snapshots generated by CI into your project. Ensure you have the GitHub CLI installed and authenticated. ```bash ./scripts/update-snapshots-from-ci.sh ``` ```bash cd example-web ./scripts/update-snapshots-from-ci.sh 18528005182 ``` -------------------------------- ### Installing required packages for zip-base64 and RAW format Source: https://github.com/gre/react-native-view-shot/blob/master/README.md These are the npm packages required to use the zip-base64 and RAW format features for image processing. ```bash npm install pngjs zlib ``` -------------------------------- ### Working with zip-base64 and RAW format Source: https://github.com/gre/react-native-view-shot/blob/master/README.md This snippet demonstrates how to capture a view using zip-base64 and RAW format, process the data, and save it as a PNG file. It handles platform differences for format and result types. Ensure 'pngjs' and 'zlib' are installed. ```javascript const fs = require("fs"); const zlib = require("zlib"); const PNG = require("pngjs").PNG; const Buffer = require("buffer").Buffer; const format = Platform.OS === "android" ? "raw" : "png"; const result = Platform.OS === "android" ? "zip-base64" : "base64"; captureRef(this.ref, {result, format}).then(data => { // expected pattern 'width:height|', example: '1080:1731|' const resolution = /^(\d+):(\d+)\|/g.exec(data); const width = (resolution || ["", 0, 0])[1]; const height = (resolution || ["", 0, 0])[2]; const base64 = data.substr((resolution || [""])[0].length || 0); // convert from base64 to Buffer const buffer = Buffer.from(base64, "base64"); // un-compress data const inflated = zlib.inflateSync(buffer); // compose PNG const png = new PNG({width, height}); png.data = inflated; const pngData = PNG.sync.write(png); // save composed PNG fs.writeFileSync(output, pngData); }); ``` -------------------------------- ### Basic ViewShot Capture Example Source: https://github.com/gre/react-native-view-shot/blob/master/example-web/README.md Capture a view using captureRef with specified format, quality, and result type. The 'result' parameter defaults to 'data-uri' in web environments. ```typescript 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); }; ``` -------------------------------- ### Update iOS Snapshots Source: https://github.com/gre/react-native-view-shot/blob/master/example/e2e/README.md Command to regenerate reference images for iOS. Ensure you are in the 'example' directory and set the UPDATE_SNAPSHOTS environment variable to true. ```bash # iOS cd example UPDATE_SNAPSHOTS=true npm run test:e2e:ios ``` -------------------------------- ### Build and Run iOS App Source: https://github.com/gre/react-native-view-shot/blob/master/example/README.md After installing CocoaPods dependencies, use this command to build and run your React Native application on an iOS simulator or device. Ensure Metro is running. ```sh # Using npm npm run ios # OR using Yarn yarn ios ``` -------------------------------- ### Update Android E2E Snapshots Source: https://github.com/gre/react-native-view-shot/blob/master/example/e2e/README.md Update the reference snapshots for Android end-to-end tests. Navigate to the example directory and use the provided command with the UPDATE_SNAPSHOTS flag. Be aware of potential intermittent issues. ```bash cd example UPDATE_SNAPSHOTS=true npm run test:e2e:android ``` -------------------------------- ### Update iOS E2E Snapshots Source: https://github.com/gre/react-native-view-shot/blob/master/example/e2e/README.md Update the reference snapshots for iOS end-to-end tests. Ensure you are in the example directory and use the provided command with the UPDATE_SNAPSHOTS flag. ```bash cd example UPDATE_SNAPSHOTS=true npm run test:e2e:ios ``` -------------------------------- ### Update Android Snapshots Source: https://github.com/gre/react-native-view-shot/blob/master/example/e2e/README.md Command to regenerate reference images for Android. Ensure you are in the 'example' directory and set the UPDATE_SNAPSHOTS environment variable to true. Note: This command is marked as 'when working'. ```bash # Android (when working) UPDATE_SNAPSHOTS=true npm run test:e2e:android ``` -------------------------------- ### Build and Clean Project Source: https://github.com/gre/react-native-view-shot/blob/master/example-web/README.md Build the project for production or clean the build artifacts. ```bash npm run build # Production build in dist/ npm run clean # Remove dist/ ``` -------------------------------- ### Snapshot Directory Structure Source: https://github.com/gre/react-native-view-shot/blob/master/example-web/e2e/snapshots/README.md Illustrates the directory layout for storing reference and output snapshots used in visual regression testing. ```bash snapshots/ ├── reference/ │ └── .ts-snapshots/ # Golden snapshots (committed) │ └── -chromium.png └── output/ # Test results (git-ignored) ``` -------------------------------- ### Build and Lint Commands for react-native-view-shot Source: https://github.com/gre/react-native-view-shot/blob/master/CLAUDE.md Commands for building the library, checking types, and running ESLint for code quality. ```bash npm run build # Compile TypeScript → lib/ npm run type-check # Type-check without emitting npm run lint # ESLint npm run lint:ci # ESLint (zero warnings allowed) npm run format # Prettier format npm run format:check # Check formatting ``` -------------------------------- ### Create Reference Snapshots for Android Source: https://github.com/gre/react-native-view-shot/blob/master/example/e2e/tests/README.md Run Android end-to-end tests with the UPDATE_SNAPSHOTS=true environment variable to generate or update reference snapshots. ```bash UPDATE_SNAPSHOTS=true npm run test:e2e:android ``` -------------------------------- ### Create Reference Snapshots for iOS Source: https://github.com/gre/react-native-view-shot/blob/master/example/e2e/tests/README.md Run iOS end-to-end tests with the UPDATE_SNAPSHOTS=true environment variable to generate or update reference snapshots. ```bash UPDATE_SNAPSHOTS=true npm run test:e2e:ios ``` -------------------------------- ### iOS Snapshot Reference Directory Structure Source: https://github.com/gre/react-native-view-shot/blob/master/example/e2e/README.md Illustrates the directory structure for iOS reference images used in end-to-end testing. These images are crucial for comparing test outputs against expected rendering. ```directory snapshots/ ├── reference/ │ ├── ios/ # iOS reference images │ │ ├── basic_viewshot.png │ │ ├── fullscreen_viewshot.png │ │ └── ... │ └── android/ # Android reference images │ ├── basic_viewshot.png │ └── ... └── output/ # Test outputs (gitignored) ├── ios/ └── android/ ``` -------------------------------- ### Build E2E Project for Android Source: https://github.com/gre/react-native-view-shot/blob/master/example/e2e/tests/README.md Build the end-to-end test project for Android. This may be required before running tests. ```bash npm run build:e2e:android ``` -------------------------------- ### Capture View on Mount (Simpler API) Source: https://github.com/gre/react-native-view-shot/blob/master/README.md Automatically captures a view when the component mounts using the 'mount' capture mode. The capture result is passed to the onCapture callback. ```javascript import ViewShot from "react-native-view-shot"; function ExampleCaptureOnMountSimpler { const ref = useRef(); const onCapture = useCallback(uri => { console.log("do something with ", uri); }, []); return ( ...Something to rasterize... ); } ``` -------------------------------- ### captureScreen() Source: https://github.com/gre/react-native-view-shot/blob/master/README.md Captures the entire currently displayed screen as a native hardware screenshot. This method does not require a view reference and captures only the visible portions of scrollable content. It returns a Promise that resolves with the URI of the captured image. ```APIDOC ## `captureScreen()` ### Description Captures the entire currently displayed screen as a native hardware screenshot. This method does not require a view reference and captures only the visible portions of scrollable content. It returns a Promise that resolves with the URI of the captured image. ### Method Imperative API call ### Parameters - **`options`** (object) - Optional - Configuration options for the capture. These are the same options available for the `captureRef` method (e.g., `format`, `quality`, `result`). ### Response - **Promise** - Resolves with the URI of the captured image. ``` -------------------------------- ### Build E2E Project for iOS Source: https://github.com/gre/react-native-view-shot/blob/master/example/e2e/tests/README.md Build the end-to-end test project for iOS. This may be required before running tests. ```bash npm run build:e2e:ios ``` -------------------------------- ### Capture Screenshot and Scroll to See Preview Source: https://github.com/gre/react-native-view-shot/blob/master/example/e2e/tests/README.md Captures a screenshot, waits for it to render, and then scrolls down to view the captured preview. ```javascript await captureScreenshot('📸 Capture Screenshot', 'Success!'); await device.sleep(1000); // Wait for preview to render await scrollToBottom(); // Scroll to see it ``` -------------------------------- ### Capture the entire screen Source: https://github.com/gre/react-native-view-shot/blob/master/README.md Use `captureScreen` to take a native hardware screenshot of the entire device screen. It accepts the same options as `captureRef` but does not require a view reference. ```javascript import {captureScreen} from "react-native-view-shot"; captureScreen({ format: "jpg", quality: 0.8, }).then( uri => console.log("Image saved to", uri), error => console.error("Oops, snapshot failed", error), ); ``` -------------------------------- ### Capture View on Mount (Manual Ref) Source: https://github.com/gre/react-native-view-shot/blob/master/README.md Capture a React Native view to an image URI when the component mounts. Requires manual invocation of the capture method using a ref. ```javascript import ViewShot from "react-native-view-shot"; function ExampleCaptureOnMountManually { const ref = useRef(); useEffect(() => { // on mount ref.current.capture().then(uri => { console.log("do something with ", uri); }); }, []); return ( ...Something to rasterize... ); } ``` -------------------------------- ### Build and Run Android App Source: https://github.com/gre/react-native-view-shot/blob/master/example/README.md Execute this command in a new terminal window to build and run your React Native application on an Android device or emulator. Ensure Metro is running. ```sh # Using npm npm run android # OR using Yarn yarn android ``` -------------------------------- ### Cleanup Old Snapshots Source: https://github.com/gre/react-native-view-shot/blob/master/example/e2e/tests/README.md This JavaScript snippet demonstrates using the snapshotMatcher to keep a specified number of recent snapshots, automatically cleaning up older ones. ```javascript // Keep last 10 snapshots per test snapshotMatcher.cleanup(10); ``` -------------------------------- ### Navigate to Screen and Find Element Source: https://github.com/gre/react-native-view-shot/blob/master/example/e2e/tests/README.md This JavaScript snippet demonstrates navigating to a specific screen and finding an element, likely involving automatic scrolling. ```javascript // This will scroll until the button is found await navigateToScreen('Basic ViewShot', '📸 Basic ViewShot Test'); ``` -------------------------------- ### Run End-to-End Tests Source: https://github.com/gre/react-native-view-shot/blob/master/example-web/README.md Execute automated end-to-end tests using Playwright, either headlessly or with a visible browser. ```bash npm run test:e2e # Run tests headless npm run test:e2e:headed # Run tests with visible browser ``` -------------------------------- ### Share Captured Image with Expo Sharing Source: https://github.com/gre/react-native-view-shot/blob/master/README.md Prepend 'file://' to the captured URI before sharing with `expo-sharing`. This ensures the sharing function can correctly access the temporary file. ```javascript captureRef(viewRef) .then((uri) => Sharing.shareAsync(`file://${uri}`, options) ``` -------------------------------- ### Update Reference Snapshots Source: https://github.com/gre/react-native-view-shot/blob/master/example/e2e/tests/README.md Command to update reference snapshots for iOS tests. This is typically done after legitimate UI changes. ```bash # Update reference snapshots UPDATE_SNAPSHOTS=true npm run test:e2e:ios ``` -------------------------------- ### Capture and Validate Snapshot Source: https://github.com/gre/react-native-view-shot/blob/master/example/e2e/tests/README.md Captures a screenshot and validates it against a reference snapshot. It checks for matches only when not updating references. ```javascript // Capture and validate against reference const result = await snapshotMatcher.captureAndValidate( 'test_name', null, UPDATE_REFERENCES, ); if (!UPDATE_REFERENCES && result.matched !== null) { expect(result.matched).toBe(true); } ``` -------------------------------- ### Android Build Fix for libfbjni.so Source: https://github.com/gre/react-native-view-shot/blob/master/example/e2e/README.md This Gradle script snippet resolves duplicate libfbjni.so files by deleting them from the react-native-gesture-handler library before the merge step, enabling successful test APK builds. ```gradle afterEvaluate { tasks.matching { it.name.contains('mergeDebugAndroidTest') && it.name.contains('JniLibFolders') }.configureEach { doFirst { def gestureHandlerDir = file("${projectDir}/../../node_modules/react-native-gesture-handler/android/build/intermediates/library_jni/debug") if (gestureHandlerDir.exists()) { gestureHandlerDir.eachFileRecurse { file -> if (file.name == 'libfbjni.so') { file.delete() } } } } } } ``` -------------------------------- ### Remove All Output Snapshots Source: https://github.com/gre/react-native-view-shot/blob/master/example/e2e/tests/README.md Command to manually remove all generated output snapshots from the e2e/snapshots/output directory. ```bash # Remove all output snapshots rm -rf e2e/snapshots/output/* ``` -------------------------------- ### Scroll to Bottom and Capture Screenshot Source: https://github.com/gre/react-native-view-shot/blob/master/example/e2e/tests/README.md This JavaScript snippet demonstrates scrolling to the bottom of the view to ensure elements are visible before capturing a screenshot. ```javascript // Scroll to bottom to see capture button await scrollToBottom(); // Capture screenshot await captureScreenshot('📸 Capture Screenshot', 'Success!'); // Scroll to see the captured preview await scrollToBottom(); await device.sleep(500); ``` -------------------------------- ### Capture GL Views on Android Source: https://github.com/gre/react-native-view-shot/blob/master/README.md Set `handleGLSurfaceViewOnAndroid` to true to capture GL Surface Views on Android. This prop defaults to false due to potential performance impacts. ```javascript /** * if true and when view is a SurfaceView or have it in the view tree, view will be captured. * False by default, because it can have signoficant performance impact */ handleGLSurfaceViewOnAndroid?: boolean; ``` -------------------------------- ### captureRef(view, options) Source: https://github.com/gre/react-native-view-shot/blob/master/README.md Captures a specific React Native component referenced by `view`. It returns a Promise that resolves with the URI of the captured image. Various options can be provided to control the output format, quality, and saving method. ```APIDOC ## `captureRef(view, options)` ### Description Captures a specific React Native component referenced by `view`. It returns a Promise that resolves with the URI of the captured image. Various options can be provided to control the output format, quality, and saving method. ### Method Imperative API call ### Parameters - **`view`** (reference) - Required - A reference to a React Native component. - **`options`** (object) - Optional - Configuration options for the capture. - **`fileName`** (string) - Optional (Android only) - The file name of the file. Must be at least 3 characters long. - **`width`** (number) - Optional - The width of the final image. If not provided, the original pixel size is used. - **`height`** (number) - Optional - The height of the final image. If not provided, the original pixel size is used. - **`format`** (string) - Optional - The image format. Can be `png`, `jpg`, or `webm` (Android). Defaults to `png`. - **`quality`** (number) - Optional - The compression quality for lossy formats (e.g., jpg). Ranges from 0.0 to 1.0. Defaults to 1.0. - **`result`** (string) - Optional - The method to use for saving the snapshot. Options include `tmpfile` (default), `base64`, and `data-uri`. - **`snapshotContentContainer`** (boolean) - Optional - If true and the ref is a `ScrollView`, captures the entire scrollable content instead of just the visible viewport. (Android caveat: only vertical ScrollView supported. Windows: not supported). - **`useRenderInContext`** (boolean) - Optional (iOS only) - Changes the iOS snapshot strategy to use `renderInContext` instead of `drawViewHierarchyInRect`. ### Response - **Promise** - Resolves with the URI of the captured image. ``` -------------------------------- ### Remove Reference Snapshots Source: https://github.com/gre/react-native-view-shot/blob/master/example/e2e/tests/README.md Command to remove all reference snapshots. Use with caution. ```bash rm -rf e2e/snapshots/reference/* ``` -------------------------------- ### Scroll and Capture Screenshot Source: https://github.com/gre/react-native-view-shot/blob/master/example/e2e/tests/README.md Ensures the capture button is visible by scrolling to the bottom before capturing a screenshot. ```javascript await scrollToBottom(); await captureScreenshot('📸 Capture Screenshot', 'Success!'); ``` -------------------------------- ### Capture View After Image Load Source: https://github.com/gre/react-native-view-shot/blob/master/README.md Captures a view after an image within it has finished loading. This ensures the captured image includes all rendered elements. ```javascript import ViewShot from "react-native-view-shot"; function ExampleWaitingCapture { const ref = useRef(); const onImageLoad = useCallback(() => { ref.current.capture().then(uri => { console.log("do something with ", uri); }) }, []); return ( ...Something to rasterize... ); } ``` -------------------------------- ### Capture a specific view reference Source: https://github.com/gre/react-native-view-shot/blob/master/README.md Use `captureRef` to capture a specific React Native component. Options can specify format, quality, and how the result is saved. ```javascript import {captureRef} from "react-native-view-shot"; captureRef(viewRef, { format: "jpg", quality: 0.8, }).then( uri => console.log("Image saved to", uri), error => console.error("Oops, snapshot failed", error), ); ``` -------------------------------- ### Adjust Scroll Distance in Tests Source: https://github.com/gre/react-native-view-shot/blob/master/example/e2e/tests/README.md This JavaScript snippet shows how to adjust the scroll distance in test helpers, increasing it to 800 pixels. ```javascript // Increase scroll distance await scrollToBottom(null, 800); // Scroll 800px instead of default 500px ``` -------------------------------- ### releaseCapture(uri) Source: https://github.com/gre/react-native-view-shot/blob/master/README.md Releases a previously captured URI. This is primarily useful for cleaning up temporary files created by the `tmpfile` result type. For other result types, it has no effect. ```APIDOC ## `releaseCapture(uri)` ### Description Releases a previously captured URI. This is primarily useful for cleaning up temporary files created by the `tmpfile` result type. For other result types, it has no effect. ### Method Imperative API call ### Parameters - **`uri`** (string) - Required - The URI of the captured image to release. ### Notes Temporary file captures are automatically cleaned out when the app closes. This method is useful for manual cleanup or when capturing multiple times continuously to avoid file leaks. ``` -------------------------------- ### Capture ScrollView Content Source: https://github.com/gre/react-native-view-shot/blob/master/README.md Captures the content of a ScrollView. For complex scenarios or when needing to target the scrollable content specifically, an imperative approach with a ref might be necessary. ```javascript import ViewShot from "react-native-view-shot"; function ExampleCaptureOnMountSimpler { const ref = useRef(); const onCapture = useCallback(uri => { console.log("do something with ", uri); }, []); return ( ...The Scroll View Content Goes Here... ); } ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.