对 React Native 视图进行快照并保存为图像。
将 React Native 视图捕获为图像。
此库从 4.0+ 版本起完全支持 React Native 的新架构(Fabric + TurboModules)。
要求:
新旧架构均受支持,便于无缝迁移。
npm install react-native-view-shot
# or with Yarn
yarn add react-native-view-shot
# In Expo
npx expo install react-native-view-shot自 React Native 0.60+ 起,自动链接 会自动处理链接。 在 iOS 上,安装 CocoaPods 依赖:
npx pod-install…属性:
children:要栅格化的实际内容。options:与 captureRef 方法中相同的选项。captureMode(字符串):capture()。"mount":在挂载时捕获一次视图。不会等待图片加载完成;如有需要,请在 Image#onLoad 之后调用 viewShotRef.current.capture(),而不要使用 captureMode。"continuous" 实验性功能,这会持续捕获大量图片。仅适用于非常特定的用例。"update" 实验性功能,这会在每次 React 重绘(即 did update 时)捕获图片。仅适用于非常特定的用例。onCapture:当定义了 captureMode 时,此回调会以捕获结果作为参数被调用。onCaptureFailure:当定义了 captureMode 时,此回调会在捕获失败时被调用。captureRef(view, options) 低级命令式 API暂无开放 Issues,或尚未同步最近议题。