Skip to content

Commit 68f8681

Browse files
committed
docs(tre): enhance documentation accuracy
1 parent b738c48 commit 68f8681

3 files changed

Lines changed: 64 additions & 20 deletions

File tree

packages/transient-render-engine/src/helper-types.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,15 +47,15 @@ export type StylessReactNativeProps = Omit<ReactNativeProps, 'style'> & {
4747
*/
4848
export type ReactNativePropsDefinitions = {
4949
/**
50-
* Props that will only apply to `Text`-wrapped renderers.
50+
* Props that will only apply to `Text`-backed renderers.
5151
*/
5252
text?: StylessReactNativeTextProps;
5353
/**
54-
* Props that will only apply to `View`-wrapped renderers.
54+
* Props that will only apply to `View`-backed renderers.
5555
*/
5656
view?: StylessReactNativeViewProps;
5757
/**
58-
* Props that will apply to both `View` and `Text`-wrapped renderers.
58+
* Props that will apply to both `View` and `Text`-backed renderers.
5959
*/
6060
native?: StylessReactNativeProps;
6161
};

packages/transient-render-engine/src/model/HTMLElementModel.ts

Lines changed: 60 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -91,21 +91,39 @@ export default class HTMLElementModel<
9191
*/
9292
public readonly mixedUAStyles?: MixedStyleDeclaration;
9393
/**
94-
* Default react Native props to pass to renderers.
94+
* React Native props grouped by native components. Those props
95+
* will be passed to the underlying native component at render time.
9596
*
9697
* @remarks Some props might be overriden by props derived from the
9798
* {@link TNode} attributes. For example, if you pass `accessibilityLabel`
9899
* and there is an `aria-label` attribute attached to one node, the
99100
* `aria-label` will be used. If you want to be able to override the
100-
* `aria-label`, use {@link getReactNativeProps} instead.
101+
* `aria-label`, use {@link HTMLElementModel.getReactNativeProps} instead.
102+
*
103+
* @example
104+
*
105+
* ```ts
106+
* import {HTMLElementModel, HTMLContentModel} from 'react-native-render-html';
107+
*
108+
* const customHTMLElementModels = {
109+
* 'nav-button': HTMLElementModel.fromCustomModel({
110+
* tagName: 'nav-button',
111+
* contentModel: HTMLContentModel.block,
112+
* reactNativeProps: {
113+
* native: {
114+
* onPress() {
115+
* console.info('nav-button pressed');
116+
* },
117+
* },
118+
* },
119+
* }),
120+
*};
121+
* ```
101122
*/
102123
readonly reactNativeProps?: ReactNativePropsDefinitions;
103124
/**
104125
* A function to create conditional "user-agent" styles.
105126
*
106-
* @remarks For example, &lt;a&gt; tags will have underline decoration and be
107-
* colored blue only when `href` is defined.
108-
*
109127
* @deprecated Use {@link HTMLElementModel.getMixedUAStyles} instead.
110128
*/
111129
public readonly getUADerivedStyleFromAttributes: NativeElementModel['getUADerivedStyleFromAttributes'];
@@ -116,20 +134,49 @@ export default class HTMLElementModel<
116134
* colored blue only when `href` is defined.
117135
*/
118136
public readonly getMixedUAStyles: NativeElementModel['getMixedUAStyles'];
119-
120137
/**
121-
* A function to create conditional React Native props for a specific TNode.
138+
* A function to create React Native props from a {@link TNode} grouped by
139+
* native components.
140+
*
122141
* Those props will be deep-merged over the pre-generated props. You can
123142
* preserve some of the pre-generated props since you receive them as second
124143
* argument.
125144
*
126-
* **Merge strategy** (rightmost overrides leftmost): _static props from model_,
127-
* _auto-generated props from attributes_, _props returned by this function_.
145+
* **Merge strategy** (latest overrides former):
146+
*
147+
* 1. props from `reactNativeProps`,
148+
* 2. auto-generated props from attributes
149+
* 3. props returned by this function
150+
*
151+
* @param tnode - The {@link TNode} for which to create React Native props.
152+
* @param preGeneratedProps - The props that were pre-generated for the {@link TNode}
153+
* based on attributes (e.g. aria-label ...) and
154+
* {@link ElementModelBase.reactNativeProps}.
155+
* @returns React Native props grouped by native components (see
156+
* {@link ReactNativePropsDefinitions}). Those props will be passed to the
157+
* underlying native component at render time.
158+
*
159+
* @example
160+
*
161+
* ```ts
162+
* import { defaultHTMLElementModels } from "react-native-render-html";
128163
*
129-
* @param tnode - The TNode for which to create React Native props.
130-
* @param preGeneratedProps - The props that were pre-generated for the TNode
131-
* based on attributes (style, aria-* ...) and
132-
* {@link HTMLELementModel.reactNativeProps}.
164+
* const customHTMLElementModels = {
165+
* a: defaultHTMLElementModels.a.extend({
166+
* getReactNativeProps(tnode) {
167+
* const attributes = tnode.attributes;
168+
* return {
169+
* native: {
170+
* accessibilityHint:
171+
* attributes['data-scope'] === 'internal'
172+
* ? 'Open in a new screen.'
173+
* : 'Open in system web browser.',
174+
* },
175+
* };
176+
* },
177+
* }),
178+
* };
179+
* ```
133180
*/
134181
public readonly getReactNativeProps: NativeElementModel['getReactNativeProps'];
135182

packages/transient-render-engine/src/model/model-types.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ export interface ElementModelBase<T extends string> {
209209
* {@link TNode} attributes. For example, if you pass `accessibilityLabel`
210210
* and there is an `aria-label` attribute attached to one node, the
211211
* `aria-label` will be used. If you want to be able to override the
212-
* `aria-label`, use {@link getReactNativeProps} instead.
212+
* `aria-label`, use {@link ElementModelBase.getReactNativeProps} instead.
213213
*
214214
* @example
215215
*
@@ -252,9 +252,6 @@ export interface ElementModelBase<T extends string> {
252252
/**
253253
* A function to create conditional "user-agent" styles.
254254
*
255-
* @remarks For example, &lt;a&gt; tags will have underline decoration and be
256-
* colored blue only when `href` is defined.
257-
*
258255
* @deprecated Use {@link ElementModelBase.getMixedUAStyles} instead.
259256
*/
260257
getUADerivedStyleFromAttributes?: (

0 commit comments

Comments
 (0)