Textual
Paragraphs
Paragraphs have a default top and bottom margin. If you use enableExperimentalMarginCollapsing prop, margins of adjacents blocks will collapse as per the CSS standard.
- JSX Source
- HTML Snippet
- TRT Snapshot
enableExperimentalMarginCollapsing is considered experimental because the TRE doesn't support display CSS property yet. However, margin collapsing should not apply to flex layouts while this prop will apply margin collapsing indiscriminately.
Whitespace Collapsing
White space collasping occurs in the eponym phase of the Transient Render Engine processing step. Insignificant whitespaces are removed from the tree, as per the algorithm depicted in CSS Text Module Level 3.
The TRE strictly complies with this standard, although only white-space: normal; and white-space: pre; are supported at the moment.
Example: 'white-space: normal'
This is the default behavior, with the exception of a handful of tags such as <pre>.
- JSX Source
- HTML Snippet
- TRT Snapshot
Example: 'white-space: pre'
You can set the white-space CSS property with inline styles or with classes, id and tags styles.
- JSX Source
- HTML Snippet
- TRT Snapshot
Preformatted Content
- JSX Source
- HTML Snippet
- TRT Snapshot
The default font for the <pre> tag is monospace and white-space property is "pre". These default styles are set via the mixedUAStyles associated with this tag element model. See Element Models.
Font Selection
CSS font-family and font properties allow a comma-separated list of fonts, but React Native styles fontFamily allows only one font name. With the TRE, you can instruct which fonts are available in the system (or fonts you have added), and it will pick the first match! The prop to achieve that is systemFonts.
By default, a handful of fonts supported by the current platform are pre-registered (Android, iOS, MacOS and Windows). If you are using expo, just set this prop to Constants.systemFonts. You can also define how generic font names are resolved with the fallbackFonts prop.
Example: Arial Font Selection
- JSX Source
- HTML Snippet
- TRT Snapshot
Example: Courier New Font Selection
- JSX Source
- HTML Snippet
- TRT Snapshot
Example: Space Mono Font Selection
- JSX Source
- HTML Snippet
- TRT Snapshot
Fonts registered in systemFonts should not be surrounded with quotes; however you can surround the font name with quotes in inline and mixed styles, as per CSS standard.
Caveats
Line Breaks
Line breaks work seemlessly with the <br> element. There is a known bug though in the Foundry release, where line breaks closing an inline formatting context will be printed while they should be ignored. Below is an example for illustration purposes:
- JSX Source
- HTML Snippet
- TRT Snapshot
Hopefully, the bug has been identified and since version 6.1.1 there is a workaround. You just need to pass enableExperimentalBRCollapsing prop:
- JSX Source
- HTML Snippet
- TRT Snapshot
Empty Tags
React Native has a weird behavior whereby empty Text elements span vertically on iOS and Android. I called this "ghost lines". For example:
- JSX Source
- HTML Snippet
- TRT Snapshot
Since version 6.1.1, a new prop, enableExperimentalGhostLinesPrevention, prevent this behavior from happening. It will also handle multiple ghost elements:
- JSX Source
- HTML Snippet
- TRT Snapshot