Skip to content

Commit 3401890

Browse files
committed
refactor: rename getDynamicReactNativeProps to getReactNativeProps for consistency
BREAKING CHANGE: rename `getDynamicReactNativeProps` to `getReactNativeProps` for consistency
1 parent 9b1b008 commit 3401890

5 files changed

Lines changed: 30 additions & 33 deletions

File tree

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ export default class HTMLElementModel<
9191
* {@link TNode} attributes. For example, if you pass `accessibilityLabel`
9292
* and there is an `aria-label` attribute attached to one node, the
9393
* `aria-label` will be used. If you want to be able to override the
94-
* `aria-label`, use {@link getDynamicReactNativeProps} instead.
94+
* `aria-label`, use {@link getReactNativeProps} instead.
9595
*/
9696
readonly reactNativeProps?: ReactNativePropsDefinitions;
9797
/**
@@ -125,7 +125,7 @@ export default class HTMLElementModel<
125125
* based on attributes (style, aria-* ...) and
126126
* {@link HTMLELementModel.reactNativeProps}.
127127
*/
128-
public readonly getDynamicReactNativeProps: NativeElementModel['getDynamicReactNativeProps'];
128+
public readonly getReactNativeProps: NativeElementModel['getReactNativeProps'];
129129

130130
/**
131131
* Derive markers for one TNode.
@@ -141,7 +141,7 @@ export default class HTMLElementModel<
141141
getUADerivedStyleFromAttributes,
142142
getMixedUAStyles,
143143
setMarkersForTNode,
144-
getDynamicReactNativeProps,
144+
getReactNativeProps,
145145
reactNativeProps
146146
}: HTMLElementModelProperties<T, M>) {
147147
this.tagName = tagName;
@@ -152,7 +152,7 @@ export default class HTMLElementModel<
152152
this.getUADerivedStyleFromAttributes = getUADerivedStyleFromAttributes;
153153
this.getMixedUAStyles = getMixedUAStyles;
154154
this.setMarkersForTNode = setMarkersForTNode;
155-
this.getDynamicReactNativeProps = getDynamicReactNativeProps;
155+
this.getReactNativeProps = getReactNativeProps;
156156
this.reactNativeProps = reactNativeProps;
157157
}
158158

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

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ function headerStyle(
9999
};
100100
}
101101

102-
const getDynamicReactNativePropsForHeading: ElementModelBase<any>['getDynamicReactNativeProps'] =
102+
const getReactNativePropsForHeading: ElementModelBase<any>['getReactNativeProps'] =
103103
({ domNode }) => {
104104
const textLabel = textContent(domNode!);
105105
return {
@@ -111,8 +111,8 @@ const getDynamicReactNativePropsForHeading: ElementModelBase<any>['getDynamicRea
111111
};
112112
};
113113

114-
const getDynamicReactNativePropsWithHref: ElementModelBase<any>['getDynamicReactNativeProps'] =
115-
function getDynamicReactNativePropsWithHref({ attributes }) {
114+
const getReactNativePropsWithHref: ElementModelBase<any>['getReactNativeProps'] =
115+
function getReactNativePropsWithHref({ attributes }) {
116116
if (typeof attributes.href === 'string' && attributes.href.length > 0) {
117117
return {
118118
native: {
@@ -152,37 +152,37 @@ const sectioningModelMap: HTMLModelRecord<
152152
category: 'sectioning',
153153
tagName: 'h1',
154154
mixedUAStyles: headerStyle('2em', '.67em'),
155-
getDynamicReactNativeProps: getDynamicReactNativePropsForHeading
155+
getReactNativeProps: getReactNativePropsForHeading
156156
}),
157157
h2: HTMLElementModel.fromNativeModel({
158158
category: 'sectioning',
159159
tagName: 'h2',
160160
mixedUAStyles: headerStyle('1.5em', '.83em'),
161-
getDynamicReactNativeProps: getDynamicReactNativePropsForHeading
161+
getReactNativeProps: getReactNativePropsForHeading
162162
}),
163163
h3: HTMLElementModel.fromNativeModel({
164164
category: 'sectioning',
165165
tagName: 'h3',
166166
mixedUAStyles: headerStyle('1.17em', '1em'),
167-
getDynamicReactNativeProps: getDynamicReactNativePropsForHeading
167+
getReactNativeProps: getReactNativePropsForHeading
168168
}),
169169
h4: HTMLElementModel.fromNativeModel({
170170
category: 'sectioning',
171171
tagName: 'h4',
172172
mixedUAStyles: headerStyle('1em', '1.33em'),
173-
getDynamicReactNativeProps: getDynamicReactNativePropsForHeading
173+
getReactNativeProps: getReactNativePropsForHeading
174174
}),
175175
h5: HTMLElementModel.fromNativeModel({
176176
category: 'sectioning',
177177
tagName: 'h5',
178178
mixedUAStyles: headerStyle('.83em', '1.67em'),
179-
getDynamicReactNativeProps: getDynamicReactNativePropsForHeading
179+
getReactNativeProps: getReactNativePropsForHeading
180180
}),
181181
h6: HTMLElementModel.fromNativeModel({
182182
category: 'sectioning',
183183
tagName: 'h6',
184184
mixedUAStyles: headerStyle('.67em', '2.33em'),
185-
getDynamicReactNativeProps: getDynamicReactNativePropsForHeading
185+
getReactNativeProps: getReactNativePropsForHeading
186186
}),
187187
header: HTMLElementModel.fromNativeModel({
188188
category: 'sectioning',
@@ -210,7 +210,7 @@ const unsupportedModelMap: HTMLModelRecord<
210210
tagName: 'area',
211211
category: 'untranslatable',
212212
isVoid: true,
213-
getDynamicReactNativeProps: getDynamicReactNativePropsWithHref
213+
getReactNativeProps: getReactNativePropsWithHref
214214
}),
215215
map: HTMLElementModel.fromNativeModel({
216216
tagName: 'map',
@@ -556,7 +556,7 @@ const renderedEmbeddedModelMap: HTMLModelRecord<
556556
tagName: 'img',
557557
category: 'embedded',
558558
isVoid: true,
559-
getDynamicReactNativeProps({ attributes }) {
559+
getReactNativeProps({ attributes }) {
560560
// see https://w3c.github.io/html-aria/#el-img
561561
const label = attributes.alt || attributes['aria-label'];
562562
if (label) {
@@ -627,7 +627,7 @@ const emptyEmbeddedModelMap: HTMLModelRecord<
627627
category: 'embedded',
628628
isVoid: false, // allows svg elems
629629
isOpaque: true,
630-
getDynamicReactNativeProps({ attributes }) {
630+
getReactNativeProps({ attributes }) {
631631
if (attributes['aria-label']) {
632632
return {
633633
native: {
@@ -850,7 +850,7 @@ const defaultHTMLElementModels = {
850850
return anchorStyle;
851851
}
852852
},
853-
getDynamicReactNativeProps: getDynamicReactNativePropsWithHref,
853+
getReactNativeProps: getReactNativePropsWithHref,
854854
setMarkersForTNode(targetMarkers) {
855855
targetMarkers.anchor = true;
856856
}

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ export interface ElementModelBase<T extends string> {
208208
* {@link TNode} attributes. For example, if you pass `accessibilityLabel`
209209
* and there is an `aria-label` attribute attached to one node, the
210210
* `aria-label` will be used. If you want to be able to override the
211-
* `aria-label`, use {@link getDynamicReactNativeProps} instead.
211+
* `aria-label`, use {@link getReactNativeProps} instead.
212212
*/
213213
readonly reactNativeProps?: ReactNativePropsDefinitions;
214214

@@ -264,8 +264,8 @@ export interface ElementModelBase<T extends string> {
264264
* @param tnode - The TNode for which to create React Native props.
265265
* @param preGeneratedProps - The props that were pre-generated for the TNode based on attributes (style, aria-* ...) and {@link HTMLELementModel.reactNativeProps}.
266266
*/
267-
getDynamicReactNativeProps?: (
268-
tnode: TNodeShape<TNodeType>,
267+
getReactNativeProps?: (
268+
tnode: ExtractTNodeFromType<TNodeType>,
269269
preGeneratedProps: ReactNativePropsSwitch | null,
270270
element: Element
271271
) => ReactNativePropsDefinitions | null | undefined | void;

packages/transient-render-engine/src/tree/TNodeCtor.ts

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -157,15 +157,12 @@ const prototype: Omit<TNodeImpl, 'displayName' | 'type'> = {
157157

158158
__generateDynamicNativePropsFromModel(autoGeneratedProps) {
159159
const elm = this.elementModel;
160-
if (!elm || !elm.getDynamicReactNativeProps) {
160+
if (!elm || !elm.getReactNativeProps) {
161161
return null;
162162
}
163163
return transformPropsDefinitionsToSwitch(
164-
elm.getDynamicReactNativeProps(
165-
this as any,
166-
autoGeneratedProps,
167-
this.domNode!
168-
) || null
164+
elm.getReactNativeProps(this as any, autoGeneratedProps, this.domNode!) ||
165+
null
169166
);
170167
},
171168

packages/transient-render-engine/src/tree/__tests__/TNode.test.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ describe('TNode class', () => {
8585
});
8686
});
8787
describe('getReactNativeProps', () => {
88-
it("should return null when neither 'reactNativeProps' nor 'getDynamicReactNativeProps' are defined for this element model.", () => {
88+
it("should return null when neither 'reactNativeProps' nor 'getReactNativeProps' are defined for this element model.", () => {
8989
const node = newTNode({
9090
elementModel: HTMLElementModel.fromCustomModel({
9191
tagName: 'foo',
@@ -119,12 +119,12 @@ describe('TNode class', () => {
119119
}
120120
});
121121
});
122-
it("should support 'getDynamicReactNativeProps' returning null from the element model", () => {
122+
it("should support 'getReactNativeProps' returning null from the element model", () => {
123123
const node = newTNode({
124124
elementModel: HTMLElementModel.fromCustomModel({
125125
contentModel: HTMLContentModel.block,
126126
tagName: 'foo',
127-
getDynamicReactNativeProps() {
127+
getReactNativeProps() {
128128
return null;
129129
}
130130
})
@@ -133,15 +133,15 @@ describe('TNode class', () => {
133133
// Test twice to make sure the cache is working
134134
expect(node.getReactNativeProps()).toBeNull();
135135
});
136-
it("should support 'getDynamicReactNativeProps' returning non-null from the element model", () => {
136+
it("should support 'getReactNativeProps' returning non-null from the element model", () => {
137137
const node = newTNode({
138138
domNode: new Element('foo', {
139139
'data-rn-accessibility-label': 'Hello'
140140
}),
141141
elementModel: HTMLElementModel.fromCustomModel({
142142
contentModel: HTMLContentModel.block,
143143
tagName: 'foo',
144-
getDynamicReactNativeProps(tnode) {
144+
getReactNativeProps(tnode) {
145145
if (tnode.attributes['data-rn-accessibility-label']) {
146146
return {
147147
text: {
@@ -160,7 +160,7 @@ describe('TNode class', () => {
160160
view: {}
161161
});
162162
});
163-
it("should merge props from 'reactNativeProps' and 'getDynamicReactNativeProps'", () => {
163+
it("should merge props from 'reactNativeProps' and 'getReactNativeProps'", () => {
164164
const node = newTNode({
165165
domNode: new Element('foo', {
166166
class: 'header'
@@ -176,7 +176,7 @@ describe('TNode class', () => {
176176
testID: 'article-title'
177177
}
178178
},
179-
getDynamicReactNativeProps(tnode) {
179+
getReactNativeProps(tnode) {
180180
if (tnode.hasClass('header')) {
181181
return {
182182
native: {

0 commit comments

Comments
 (0)