Skip to content

Commit a142300

Browse files
committed
feat(Iframe): improve iframe styling, you can now set static dimensions
through the html attributes, the tagsStyles and classesStyles props.
1 parent 94d1233 commit a142300

File tree

1 file changed

+17
-14
lines changed

1 file changed

+17
-14
lines changed

src/HTMLRenderers.js

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import React from 'react';
22
import { TouchableOpacity, Text, View, WebView, Dimensions } from 'react-native';
3-
import { _constructStyles } from './HTMLStyles';
3+
import { _constructStyles, _getElementClassStyles } from './HTMLStyles';
44
import HTMLImage from './HTMLImage';
55

66
export function a (htmlAttribs, children, convertedCSSStyles, passProps) {
@@ -116,24 +116,27 @@ export function iframe (htmlAttribs, children, convertedCSSStyles, passProps) {
116116
if (!htmlAttribs.src) {
117117
return false;
118118
}
119-
const { staticContentMaxWidth } = passProps;
119+
const { staticContentMaxWidth, tagsStyles, classesStyles } = passProps;
120+
121+
const tagStyleHeight = tagsStyles.iframe && tagsStyles.iframe.height;
122+
const tagStyleWidth = tagsStyles.iframe && tagsStyles.iframe.width;
123+
124+
const classStyles = _getElementClassStyles(htmlAttribs, classesStyles);
125+
const classStyleWidth = classStyles.width;
126+
const classStyleHeight = classStyles.height;
127+
128+
const attrHeight = htmlAttribs.height ? parseInt(htmlAttribs.height) : false;
129+
const attrWidth = htmlAttribs.width ? parseInt(htmlAttribs.width) : false;
130+
131+
const height = attrHeight || classStyleHeight || tagStyleHeight || 200;
132+
const width = attrWidth || classStyleWidth || tagStyleWidth || staticContentMaxWidth;
133+
120134
const style = _constructStyles({
121135
tagName: 'iframe',
122136
htmlAttribs,
123137
passProps,
124138
styleSet: 'VIEW',
125-
additionalStyles: [
126-
{
127-
height: htmlAttribs.height ?
128-
parseInt(htmlAttribs.height, 10) :
129-
undefined
130-
},
131-
{
132-
width: staticContentMaxWidth && htmlAttribs.width && htmlAttribs.width <= staticContentMaxWidth ?
133-
parseInt(htmlAttribs.width, 10) :
134-
staticContentMaxWidth
135-
}
136-
]
139+
additionalStyles: [{ height, width }]
137140
});
138141

139142
return (

0 commit comments

Comments
 (0)