TgfxViewMethods
Extends
HybridViewMethods
Methods
hitTest()
hitTest(
x: number,
y: number,
precise: boolean): number[];Index paths of the nodes under a canvas-space point, topmost first,
flattened as [depth, i0, i1, ..., depth, j0, ...].
Answered from the same resolved geometry the renderer draws, so it follows animated values rather than the last committed props.
Parameters
x
number
y
number
precise
boolean
Returns
number[]
invalidate()
invalidate(): void;Request a repaint.
Returns
void
save()
save(path: string, options: NativeSnapshotOptions): Promise<void>;The same readback, encoded and written to path natively - the image bytes
never enter JS, which is the entire reason this is not snapshot() plus a
file write.
Parameters
path
string
options
Returns
Promise<void>
setColorSpace()
setColorSpace(colorSpace: string): void;The drawing surface's colour space. 'display-p3' on a P3 screen keeps
wide-gamut image and gradient content instead of clamping it to sRGB.
Parameters
colorSpace
string
Returns
void
setScene()
setScene(
scene: ArrayBuffer,
strings: string[],
awaitValues?: boolean): void;Replace the draw program.
scene is the binary program (the buffer behind a Float64Array).
strings is not the string table - it is a delta against the table this
view already holds. Element 0 is the decimal count of leading entries the
view keeps; elements 1..n replace everything after them. The program indexes
the reconstructed table (path data, text, image sources, shader source), so
a caller driving this directly must encode with packStringTable from
src/compiler/writer.ts and track the table it last sent per view. Passing
a bare table drops entry 0 and misindexes everything after it.
A direct hybrid-object call rather than a view prop: the scene changes on every reconciler commit, and a prop would push the whole program through a React re-render and a Fabric shadow-tree commit before reaching the engine. The buffer is only valid for the duration of the call; the engine copies it.
awaitValues: the program's slot literals are placeholders, so hold it
until the next setValues lands and draw the two together. The driver
pushes one frame later; the frames in between keep the previous program.
Parameters
scene
ArrayBuffer
strings
string[]
awaitValues?
boolean
Returns
void
setStringValues()
setStringValues(indices: number[], values: string[]): void;Update the scene's string slots - live text and path content. Sparse:
indices[i] names the slot values[i] replaces, and only changed slots are
sent, so an idle frame costs nothing here. The engine re-shapes text or
re-parses path data on the render thread; the program is never re-read.
Parameters
indices
number[]
values
string[]
Returns
void
setValues()
setValues(values: number[]): void;Update the scene's { "__s": index } value slots. Called every frame from a
Reanimated worklet, so it runs natively on the UI thread.
Parameters
values
number[]
Returns
void
setViewport()
setViewport(viewport: number[]): void;A root zoom/pan the renderer owns. A pinch tick is one native write and a redraw - no React render, no scene recommit, no wire traffic - because the transform sits above the whole draw program.
zoom is about the scene origin; x/y are canvas points applied after
it, so scale(pixelRatio) * translate(x, y) * scale(zoom) is the matrix.
A focal-point pinch is therefore x = focusX - zoom * sceneX.
viewport is [zoom, x, y]. One array argument rather than three scalars,
matching setValues: a gesture calls this every tick, and an array
the caller owns can be written in place and reused, where scalars would
marshal three fresh values through the bridge each time.
Fewer than three entries is ignored. A non-finite x/y or a non-positive
zoom is rejected as a triple and the last good viewport stays, rather
than collapsing the scene to a point.
Parameters
viewport
number[]
Returns
void
snapshot()
snapshot(options: NativeSnapshotOptions): Promise<NativeSnapshot>;Read the canvas back as pixels.
The readback is issued on the render thread inside the frame it belongs to, so a snapshot forces one fresh frame and never blocks the display link: the GPU→CPU transfer is collected on a later tick, and the encode runs on a worker so the (process-wide, on Android) render thread goes straight back to drawing.
Rejects rather than handing back a black frame when no window is bound, the surface is zero-sized, or the view is unmounted before the frame lands.
Parameters
options
Returns
Promise<NativeSnapshot>