Skip to content

Commit a384da7

Browse files
committed
docs: enhance docs with new props for 6.2 release
1 parent 62c013a commit a384da7

File tree

5 files changed

+109
-48
lines changed

5 files changed

+109
-48
lines changed

apps/website/blog/2021-06-07-foundry-announcement.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ author: Jules Sam. Randolph
44
author_title: Developer of React Native Render HTML v6
55
author_url: https://github.com/jsamr/
66
author_image_url: https://avatars.githubusercontent.com/u/3646758?v=4
7-
tags: [foundry, announcement]
7+
tags: [foundry, "release notes"]
88
description: A major rewrite of the hackable, full-featured Open Source HTML rendering solution for React Native.
99
image: img/foundry-announcement.png
1010
hide_table_of_contents: false

apps/website/blog/2021-09-27-6-2-updates.mdx

Lines changed: 34 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ author: Jules Sam. Randolph
44
author_title: Developer of React Native Render HTML v6
55
author_url: https://github.com/jsamr/
66
author_image_url: https://avatars.githubusercontent.com/u/3646758?v=4
7-
tags: [foundry, announcement]
7+
tags: [foundry, "release notes"]
88
description: A version focused on accessibility and enhanced model rendering.
99
image: img/foundry-announcement.png
1010
hide_table_of_contents: false
@@ -15,11 +15,12 @@ import APIReference from '@site/src/components/APIReference';
1515
import Reference from '@site/src/components/Reference';
1616

1717
It has been over two months since the first final version of the Foundry
18-
released has been made public. This new release focuses on two areas of
18+
release has been made public. This new version focuses on two areas of
1919
improvements:
2020

21-
1. Accessibility;
22-
2. Richer model-based rendering.
21+
1. Accessibility, and more specifically integration with screen readers;
22+
2. Richer model-based rendering, and the feature to define React Native props from
23+
within those models.
2324

2425
As you will discover through this reading, both are somehow related. Let's find out how!
2526

@@ -34,7 +35,7 @@ However, it was limited to setting user agent styles (<APIReference
3435
name="HTMLElementModel" member="mixedUAStyles" />),
3536
although those styles could be derived from the DOM node element attributes
3637
(the now-deprecated <APIReference name="HTMLElementModel" member="getUADerivedStyleFromAttributes" />).
37-
The below example is a reminder of how those element models can be defined, for instance to
38+
The below example is a reminder on how those element models can be defined, for instance to
3839
register a new `<blue-circle>` tag which renders to a 50 by 50 blue circle!
3940

4041
```js title="An Example of Model-Based Rendering"
@@ -70,10 +71,13 @@ related to specificity for a refresher.
7071
Version 6.2 ships with a bunch of new fields for HTML element models which
7172
should make model-based rendering more popular. Let's take a tour!
7273

73-
### `getMixedUAStyles` Tickles CSS Selectors!
74+
### `getMixedUAStyles`
7475

75-
This field deprecates <APIReference name="HTMLElementModel" member="getUADerivedStyleFromAttributes"/>; it's basically the same
76-
but its signature has changed: it receives the target `tnode` and DOM `element`, which lets us implement CSS-selector-like behaviors:
76+
This field deprecates <APIReference name="HTMLElementModel"
77+
member="getUADerivedStyleFromAttributes"/>; it serves the same purpose but its
78+
signature has changed. It now receives the target `tnode` and DOM `element`,
79+
which lets us implement more fine-grained logic such as CSS-selector-like
80+
behaviors:
7781

7882
```js title="Conditionnaly remove margins of 'ol' direct descendents of 'p' elements."
7983
import RenderHTML, {
@@ -114,9 +118,10 @@ to query the DOM and create your conditional styling rules.
114118

115119
### `reactNativeProps`
116120

117-
This field will set props to the native component during the rendering phase.
118-
It is an object with three optional properties (for reference, the shape of
119-
this object is a <APIReference name="ReactNativePropsDefinitions" />):
121+
This field holds props that will be passed to the native component during the
122+
rendering phase. It is an object with three optional properties (for reference,
123+
the shape of this object is a <APIReference name="ReactNativePropsDefinitions"
124+
/>):
120125

121126
1. `text`, to pass native props to the `Text` component when the renderer is textual;
122127
2. `view`, to pass native props to the `View` component when the renderer is block;
@@ -241,13 +246,6 @@ Nevertheless, those interactive element models are already shipped with the appr
241246
The new Transient Render Engine will from now on
242247
translate both attributes to their React Native counterparts.
243248

244-
:::info Midly relevant
245-
The mapping rules from the `role` HTML attribute to React Native props has
246-
been greatly influenced by those of
247-
[`react-native-web`](https://github.com/necolas/react-native-web/blob/66d01734ce3ffcfea61e05aa1b45015658b3f2af/packages/react-native-web/src/modules/AccessibilityUtil/propsToAriaRole.js),
248-
the other way round!
249-
:::
250-
251249
### Accessible `<a>` Tags
252250

253251
`<a>` tags now receive an `accessibilityRole="link"` prop when their `href`
@@ -333,18 +331,16 @@ any other value to `selectable={true}`.
333331

334332
## Bonus: Version 6.1 Features
335333

336-
337-
### `renderIndex` and `renderLength` Props to Custom Component Renderers
338-
339-
Those props passed to custom component renderers give you positional
340-
information regarding this element in the render tree. `renderIndex` will often
341-
coincide with `tnode.index` but there are subtle differences.
334+
I didn't publish a release notes post for this version; I'm catching up
335+
here! From now on, I will try to write up a post for each minor and major
336+
release.
342337

343338
### `enableExperimentalBRCollapsing` Prop
344339

345340
This **recommended prop** allows consumers to circumvent a bug in the Foundry
346341
release where line breaks (`<br>`) would be printed erroneously, such
347-
as at the end of a paragraph. It will be enabled by default in the next major
342+
as at the end of a paragraph. Its default it yet `false` to avoid introducing
343+
breaking changes but it will be enabled by default in the next major
348344
release.
349345

350346
:::tip learn more
@@ -353,28 +349,31 @@ Read the complete explanation for this prop [in the textual content guide](/docs
353349

354350
### `enableExperimentalGhostLinesPrevention` Prop
355351

356-
This **recommended prop** allows to circumvent [a React Native bug](https://github.com/facebook/react-native/issues/32062) where empty
357-
`Text` elements would be printed as ghost lines of fixed height (around 20 dpi).
352+
This **recommended prop** allows to circumvent [a React Native
353+
bug](https://github.com/facebook/react-native/issues/32062) where empty `Text`
354+
elements would be printed as ghost lines of fixed height (around 20 dpi). Its
355+
default it yet `false` to avoid introducing breaking changes but it will be
356+
enabled by default in the next major release.
358357

359358
:::tip learn more
360359
Read the complete explanation for this prop [in the textual content guide](/docs/content/textual#empty-tags).
361360
:::
362361

363362
### `provideEmbeddedHeaders` Prop
364363

365-
This is a function prop which allows consumer to generate HTTP headers for
366-
remote resources. It currently works with `<img>` and `<iframe>` tags (from the
367-
`@native-html/iframe-plugin` lib).
364+
A function prop which allows to generate HTTP headers for
365+
remote resources. It currently works with `<img>` and `<iframe>` tags (since version 2.6 of the
366+
[`@native-html/iframe-plugin`](https://github.com/native-html/plugins/tree/master/packages/iframe-plugin#readme) library).
368367

369368
:::tip learn more
370369
See for example how it can be used with images [in the image content guide](/docs/content/images#providing-headers).
371370
:::
372371

373372
### `bypassAnonymousTPhrasingNodes` Prop
374373

375-
This prop makes the React rendering layer omit grouping (anonymous) `TPhrasing`
376-
nodes which have only one child. It is best learn by example. For instance, the
377-
following HTML snippet:
374+
This prop, `true` by default, makes the React rendering layer bypass grouping
375+
(anonymous) `TPhrasing` nodes which have only one child. It is best understood by
376+
example. For instance, the following HTML snippet:
378377

379378
```html
380379
<p>A sentence.</p>
@@ -410,7 +409,7 @@ the render tree will be simplified to:
410409
```
411410

412411
This behavior is preferred for many reasons. The most simple one is that it
413-
simplifies the render tree. The less React element there is, the best it is
414-
performance-wise. Moreover, there are a lot of React Native bugs implying
412+
simplifies the render tree. The less React elements there are, the best it is
413+
performance-wise. Moreover, there are a lot of React Native bugs related to
415414
nested `Text` nodes, so this simplification limits the number of occurrences
416415
of those bugs.

doc-tools/doc-pages/src/pages/PageConceptTRE.tsx

Lines changed: 46 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,25 @@ export default function PageConceptTRE() {
7676
To each standard tag is attached an <Bold>element model</Bold>,
7777
instance of the <RefTRE name="HTMLElementModel" /> class. Such model
7878
has multiple fields describing different behaviors related to
79-
translation of those DOM elements:
79+
translation of those DOM elements. There are two ways to instantiate
80+
an element model:
81+
</Paragraph>
82+
<List>
83+
<ListItem>
84+
When changing an existing tag model with the{' '}
85+
<RefTRE name="HTMLElementModel" member="extend" full /> method;
86+
</ListItem>
87+
<ListItem>
88+
When registering a new tag with the{' '}
89+
<RefTRE name="HTMLElementModel" member="fromCustomModel" full />{' '}
90+
static method.
91+
</ListItem>
92+
</List>
93+
<Paragraph>
94+
You will have to register custom and extended models with the{' '}
95+
<RefRenderHtmlProp name="customHTMLElementModels" /> prop. Below is
96+
a list of fields that can be set when defining or extending HTML
97+
element models:
8098
</Paragraph>
8199
<DList>
82100
<DListTitle>
@@ -111,15 +129,35 @@ export default function PageConceptTRE() {
111129
This is how default styles are set for tags.
112130
</DListItem>
113131
<DListTitle>
114-
<RefTRE
115-
name="HTMLElementModel"
116-
member="getUADerivedStyleFromAttributes"
117-
/>
132+
<RefTRE name="HTMLElementModel" member="getMixedUAStyles" />
133+
</DListTitle>
134+
<DListItem>
135+
A function which returns mixed UA styles given a minimal{' '}
136+
<RefTRE name="TNodeDescriptor" /> and a DOM <RefTRE name="Node" />
137+
.
138+
</DListItem>
139+
<DListTitle>
140+
<RefTRE name="HTMLElementModel" member="reactNativeProps" />
141+
</DListTitle>
142+
<DListItem>
143+
An object with three fields, <InlineCode>text</InlineCode>,{' '}
144+
<InlineCode>view</InlineCode> and <InlineCode>native</InlineCode>.
145+
Each field value is a props object that will be passed to the
146+
underlying native component at render time. Respecively, for
147+
<RefRNSymbol name="Text" />, <RefRNSymbol name="View" /> and all
148+
(catch-all).
149+
</DListItem>
150+
<DListTitle>
151+
<RefTRE name="HTMLElementModel" member="getReactNativeProps" />
118152
</DListTitle>
119153
<DListItem>
120-
A function which returns mixed UA styles given the DOM node{' '}
121-
<Bold>attributes</Bold> and <RefTRE name="TNode" />{' '}
122-
<RefTRE name="Markers" />.
154+
Serves the same purpose as{' '}
155+
<InlineCode>reactNativeProps</InlineCode>, but it's a function
156+
taking a <RefTRE name="TNode" /> as first argument, pre-generated
157+
props as second argument (such as{' '}
158+
<InlineCode>accessibilityLabel</InlineCode> derived from{' '}
159+
<RefHtmlAttr name="aria-label" />) and the DOM{' '}
160+
<RefTRE name="Element" /> as a third argument.
123161
</DListItem>
124162
</DList>
125163
</Section>

doc-tools/doc-pages/src/pages/PageFAQ.tsx

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,34 @@ export default function PageFAQ() {
218218
image.
219219
</Paragraph>
220220
</Section>
221+
<Section title="Some anchors (<a>) are not accessible to screen readers">
222+
<Paragraph>
223+
Because of a{' '}
224+
<Hyperlink url="https://github.com/facebook/react-native/issues/32004">
225+
React Native bug
226+
</Hyperlink>
227+
, nested `Text` elements are not accessible, which means that the
228+
screen reader will not be able to identify{' '}
229+
<RefHtmlElement name="a" /> tags as links when grouped with other
230+
textual elements. Below is an example:
231+
</Paragraph>
232+
<SourceDisplay
233+
lang="html"
234+
showLineNumbers={false}
235+
content={`<p>
236+
Unfortunately,
237+
<a href="https://domain.com">this hyperlink is not accessible</a>
238+
</p>`}
239+
/>
240+
<Paragraph>
241+
Luke Walczak from Callstack{' '}
242+
<Hyperlink url="https://callstack.com/blog/react-native-android-accessibility-tips/">
243+
explains how to circumvent this issue in a great post
244+
</Hyperlink>
245+
. Unfortunately, this workaround cannot be genericized and we will
246+
have to wait for a fix in React Native codebase.
247+
</Paragraph>
248+
</Section>
221249
</Chapter>
222250
</Page>
223251
);

doc-tools/doc-pages/src/pages/PageGuideCustomRenderers.tsx

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -299,10 +299,6 @@ export default function PageGuideCustomRenderers() {
299299
</DListTitle>
300300
<DListItem>
301301
The position relative to the parent React element, starting at 0.
302-
Not to be confused with{' '}
303-
<RefRenderHTMLExport name="TNodeShape" member="index" full /> the
304-
position of the <RefRenderHTMLExport name="TNode" /> before
305-
hoisting, which is much closer to the position in the DOM.
306302
</DListItem>
307303
<DListTitle>
308304
<RefRenderHTMLExport

0 commit comments

Comments
 (0)