Skip to main content

ViewShot

The Nitro HybridObject behind every capture, implemented by HybridViewShot in Swift and Kotlin.

import { ViewShot } from 'nitro-view-shot'
MemberSummary
ViewShot.captureCaptures a mounted View and its descendants.

capture​

static capture(view: View): Promise<Image>

Captures the pixels that view and its descendants draw, at the display's pixel density. Views drawn over it are left out, and parts scrolled or clipped out of sight by an ancestor are included. The image is 8-bit sRGB with alpha, and its width and height are in pixels.

view is the value of a NitroUI ViewRef:

import { useRef } from 'react'
import type { ViewRef } from 'nitro-ui-renderer'
import { ViewShot } from 'nitro-view-shot'

const ref = useRef<ViewRef>(null)
// <View ref={ref}>…</View>

const view = ref.current
if (view != null) {
const image = await ViewShot.capture(view)
}

Rejects with Cannot capture a view with an empty size. when the view has no width or height. See Errors for every rejection.