Functions & Hooks

glyphPositionAtCoordinate

function glyphPositionAtCoordinate(
   text: string, 
   style: TextStyle, 
   x: number, 
   y: number): GlyphPosition;

The insertion point nearest a coordinate - a caret, or which character a tap landed on. The coordinates are the ones measureText reports, first baseline at y = 0, so subtract the x/y you gave <Text> from the point first.

index is a UTF-8 byte offset, not a JS string index. For ASCII they are the same; for anything else, walk the string counting bytes rather than slicing it - one codepoint is 1 to 4 bytes, and a slice at a byte offset cuts one in half. Every offset the text API reports - here, LineMeasurement.startIndex, and TextBox - is in the same units, so they compose without converting.

Lays the paragraph out on every call, the same as measureText: cheap for a tap, wasteful once a frame.

Parameters

text

string

style

TextStyle

x

number

y

number

Returns

GlyphPosition

On this page