MCPcopy Create free account
hub / github.com/shoutem/ui / renderElement

Method renderElement

html/Html.js:84–122  ·  view source on GitHub ↗

* Render HTML element as React Native component. * This method is passed to both custom renderElement and * element corresponding component. It is also used to render children * and should be passed down the tree so that children can be rendered. * If Html has style named by element tag

(element)

Source from the content-addressed store, hash-verified

82 * @returns {Component} The element rendered as a React Native component
83 */
84 renderElement(element) {
85 const { renderElement } = this.props;
86
87 const elementStyle = this.getElementStyle(element);
88 let renderedElement;
89
90 if (renderElement) {
91 renderedElement = renderElement(
92 element,
93 elementStyle,
94 this.renderElement,
95 );
96 }
97
98 // Custom renderElement for the specific Html implementation
99 // has advantage over the "global". If custom renderElement rendered
100 // a component that component will be used, otherwise fallback to "global".
101 // Render element must be undefined to fallback to default,
102 // null is a valid RN type to render.
103 if (_.isUndefined(renderedElement)) {
104 const ElementComponent = getElementProperty(element, 'component');
105
106 if (!ElementComponent) {
107 // eslint-disable-next-line no-console
108 console.warn('Can not find component for element: ', element.tag);
109 return null;
110 }
111
112 renderedElement = (
113 <ElementComponent
114 element={element}
115 style={elementStyle}
116 renderElement={this.renderElement}
117 />
118 );
119 }
120
121 return renderedElement;
122 }
123
124 render() {
125 const { style, body } = this.props;

Callers 1

renderMethod · 0.95

Calls 2

getElementStyleMethod · 0.95
getElementPropertyFunction · 0.90

Tested by

no test coverage detected