Understand the Transient Render Tree structure
masterThe library uses an intermediary data structure called a Transient Render Tree to handle CSS whitespace collapsing and React Native constraints before final rendering. This tree is composed of TNode objects, which are categorized into four types:
- TBlock: Represents block-level content. Children can be
TBlock,TPhrasing, orTEmpty. Typically rendered as a React Native<View />(or via custom renderers). - TPhrasing: Represents inline/phrasing content. Children can be
TText,TPhrasing, orTEmpty. Typically rendered as a React Native<Text />node, creating an inline formatting context. - TText: Represents raw text. It cannot have children and contains the actual string
data. - TEmpty: Represents nodes that should not be rendered (e.g.,
<script>,<link>).
interface TNode {
type: 'block' | 'phrasing' | 'text' | 'empty';
attributes: Record<string, string>;
children: TNode[];
isAnchor: boolean;
isCollapsibleLeft(): boolean;
isCollapsibleRight(): boolean;
isWhitespace(): boolean;
isEmpty(): boolean;
trimLeft(): void;
trimRight(): void;
getFirstChild(): TNode | null;
getLastChild(): TNode | null;
}
interface TBlock extends TNode {
type: 'block';
tagName?: string;
}
interface TPhrasing extends TNode {
type: 'phrasing';
tagName?: string;
}
interface TText extends TNode {
type: 'text';
tagName?: string;
data: string;
}
interface TEmpty extends TBlock {
type: 'empty';
tagName?: string;
}