Skip to main content

Quick start

Wrap the content in a ViewShotView and call capture() on its ref:

import { useRef } from 'react'
import { Button, Text, View } from 'nitro-ui-renderer'
import { ViewShotView, type ViewShotViewRef } from 'nitro-view-shot'

export function Card() {
const shot = useRef<ViewShotViewRef>(null)

const save = async () => {
const image = await shot.current?.capture()
const png = await image?.toEncodedImageDataAsync('png')
// png.buffer holds the encoded bytes
}

return (
<View>
<ViewShotView ref={shot} style={{ background: 'white', cornerRadius: 16 }}>
<Text>Captured content</Text>
</ViewShotView>
<Button label="Capture" onPress={save} />
</View>
)
}
  1. ViewShotView renders a NitroUI View; it takes every ViewProps.
  2. shot.current.capture() resolves to a nitro-ui-renderer Image of the view and its children.
  3. toEncodedImageDataAsync('png') encodes it; the bytes are in png.buffer.

Capture a view you already have​

To capture any mounted NitroUI View, pass its ref value to ViewShot.capture:

import { ViewShot } from 'nitro-view-shot'

const image = await ViewShot.capture(view) // view: ViewRef from useRef<ViewRef>(null).current

Show the result​

An Image can go straight into NitroUI's Image component. From the example app:

<Image
image={shot}
resizeMode="contain"
layout={{ width: 300, aspectRatio: shot.width / shot.height }}
/>

Next: what a capture includes.