Skip to content

Commit 3f0c9ad

Browse files
authored
Merge pull request meliorence#226 from archriss/4.1.1
v4.1.1
2 parents 40b0e59 + 9c014b5 commit 3f0c9ad

File tree

6 files changed

+44
-131
lines changed

6 files changed

+44
-131
lines changed

Demo/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
"dependencies": {
1010
"react": "^16.6.3",
1111
"react-native": "^0.58.3",
12-
"react-native-render-html": "4.1.0"
12+
"react-native-render-html": "4.1.1"
1313
},
1414
"devDependencies": {
1515
"babel-core": "^7.0.0-bridge.0",

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "react-native-render-html",
3-
"version": "4.1.0",
3+
"version": "4.1.1",
44
"author": "Archriss",
55
"license": "BSD-2-Clause",
66
"repository": "https://github.com/archriss/react-native-render-html",

src/HTML.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -350,7 +350,7 @@ export default class HTML extends PureComponent {
350350
let textChildrenInheritedStyles = {};
351351
Object.keys(wrapperStyles).forEach((styleKey) => {
352352
// Extract text-only styles
353-
if (TextOnlyPropTypes[styleKey]) {
353+
if (TextOnlyPropTypes.indexOf(styleKey) !== -1) {
354354
textChildrenInheritedStyles[styleKey] = wrapperStyles[styleKey];
355355
delete wrapperStyles[styleKey];
356356
}

src/HTMLStyles.js

Lines changed: 28 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import { PERC_SUPPORTED_STYLES, STYLESETS, ABSOLUTE_FONT_SIZE, stylePropTypes } from './HTMLUtils';
22
import { generateDefaultBlockStyles, generateDefaultTextStyles } from './HTMLDefaultStyles';
3-
import checkPropTypes from './checkPropTypes';
43

54
/**
65
* Converts a html style string to an object
@@ -174,48 +173,41 @@ function cssToRNStyle (css, styleset, { emSize, ptSize, ignoredStyles, allowedSt
174173
.split('-')
175174
.map((item, index) => index === 0 ? item : item[0].toUpperCase() + item.substr(1))
176175
.join(''),
177-
value];
176+
value
177+
];
178178
})
179179
.map(([key, value]) => {
180-
if (!styleProps[key]) {
180+
if (styleProps.indexOf(key) === -1) {
181181
return undefined;
182182
}
183183

184-
const testStyle = {};
185-
testStyle[key] = value;
186-
const styleProp = {};
187-
styleProp[key] = styleProps[key];
188-
if (checkPropTypes(styleProp, testStyle, key, 'react-native-render-html') == null) {
189-
if (typeof value === 'string') {
190-
if (value.search('inherit') !== -1) {
191-
return undefined;
192-
}
193-
value = value.replace('!important', '');
194-
// See if we can use the percentage directly
195-
if (value.search('%') !== -1 && PERC_SUPPORTED_STYLES.indexOf(key) !== -1) {
196-
return [key, value];
197-
}
198-
if (value.search('em') !== -1) {
199-
const pxSize = parseFloat(value.replace('em', '')) * emSize;
200-
return [key, pxSize];
201-
}
202-
if (value.search('pt') !== -1) {
203-
const pxSize = parseFloat(value.replace('pt', '')) * ptSize;
204-
return [key, pxSize];
205-
}
206-
// See if we can convert a 20px to a 20 automagically
207-
const numericValue = parseFloat(value.replace('px', ''));
208-
if (key !== 'fontWeight' && !isNaN(numericValue)) {
209-
testStyle[key] = numericValue;
210-
if (checkPropTypes(styleProp, testStyle, key, 'react-native-render-html') == null) {
211-
return [key, numericValue];
212-
}
213-
}
214-
if (key === 'fontSize') {
215-
return mapAbsoluteFontSize(key, value);
184+
if (typeof value === 'string') {
185+
if (value.search('inherit') !== -1 || value.search('calc') !== -1 || value.search('normal') !== -1) {
186+
return undefined;
187+
}
188+
value = value.replace('!important', '');
189+
// See if we can use the percentage directly
190+
if (value.search('%') !== -1 && PERC_SUPPORTED_STYLES.indexOf(key) !== -1) {
191+
return [key, value];
192+
}
193+
if (value.search('em') !== -1) {
194+
const pxSize = parseFloat(value.replace('em', '')) * emSize;
195+
return [key, pxSize];
196+
}
197+
if (value.search('pt') !== -1) {
198+
const pxSize = parseFloat(value.replace('pt', '')) * ptSize;
199+
return [key, pxSize];
200+
}
201+
// See if we can convert a 20px to a 20 automagically
202+
const numericValue = parseFloat(value.replace('px', ''));
203+
if (key !== 'fontWeight' && !isNaN(numericValue)) {
204+
if (styleProps.indexOf(key) !== -1) {
205+
return [key, numericValue];
216206
}
217207
}
218-
return [key, value];
208+
if (key === 'fontSize') {
209+
return mapAbsoluteFontSize(key, value);
210+
}
219211
}
220212
return [key, value];
221213
})

src/HTMLUtils.js

Lines changed: 13 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,11 @@
1-
import TextStylesPropTypes from 'react-native/Libraries/Text/TextStylePropTypes';
2-
import DeprecatedViewStylePropTypes from 'react-native/Libraries/DeprecatedPropTypes/DeprecatedViewStylePropTypes';
3-
import DeprecatedImageStylesPropTypes from 'react-native/Libraries/DeprecatedPropTypes/DeprecatedImageStylePropTypes';
1+
// PropTypes have been deprecated since 0.58. This is why these array are now hardcoded. This lets us preserve
2+
// a style checking at runtime while keeping the module compatible with all react-native versions.
3+
const ImageStylePropTypes = ['display', 'width', 'height', 'start', 'end', 'top', 'left', 'right', 'bottom', 'minWidth', 'maxWidth', 'minHeight', 'maxHeight', 'margin', 'marginVertical', 'marginHorizontal', 'marginTop', 'marginBottom', 'marginLeft', 'marginRight', 'marginStart', 'marginEnd', 'padding', 'paddingVertical', 'paddingHorizontal', 'paddingTop', 'paddingBottom', 'paddingLeft', 'paddingRight', 'paddingStart', 'paddingEnd', 'borderWidth', 'borderTopWidth', 'borderStartWidth', 'borderEndWidth', 'borderRightWidth', 'borderBottomWidth', 'borderLeftWidth', 'position', 'flexDirection', 'flexWrap', 'justifyContent', 'alignItems', 'alignSelf', 'alignContent', 'overflow', 'flex', 'flexGrow', 'flexShrink', 'flexBasis', 'aspectRatio', 'zIndex', 'direction', 'shadowColor', 'shadowOffset', 'shadowOpacity', 'shadowRadius', 'transform', 'transformMatrix', 'decomposedMatrix', 'scaleX', 'scaleY', 'rotation', 'translateX', 'translateY', 'resizeMode', 'backfaceVisibility', 'backgroundColor', 'borderColor', 'borderRadius', 'tintColor', 'opacity', 'overlayColor', 'borderTopLeftRadius', 'borderTopRightRadius', 'borderBottomLeftRadius', 'borderBottomRightRadius'];
4+
const ViewStylePropTypes = ['display', 'width', 'height', 'start', 'end', 'top', 'left', 'right', 'bottom', 'minWidth', 'maxWidth', 'minHeight', 'maxHeight', 'margin', 'marginVertical', 'marginHorizontal', 'marginTop', 'marginBottom', 'marginLeft', 'marginRight', 'marginStart', 'marginEnd', 'padding', 'paddingVertical', 'paddingHorizontal', 'paddingTop', 'paddingBottom', 'paddingLeft', 'paddingRight', 'paddingStart', 'paddingEnd', 'borderWidth', 'borderTopWidth', 'borderStartWidth', 'borderEndWidth', 'borderRightWidth', 'borderBottomWidth', 'borderLeftWidth', 'position', 'flexDirection', 'flexWrap', 'justifyContent', 'alignItems', 'alignSelf', 'alignContent', 'overflow', 'flex', 'flexGrow', 'flexShrink', 'flexBasis', 'aspectRatio', 'zIndex', 'direction', 'shadowColor', 'shadowOffset', 'shadowOpacity', 'shadowRadius', 'transform', 'transformMatrix', 'decomposedMatrix', 'scaleX', 'scaleY', 'rotation', 'translateX', 'translateY', 'backfaceVisibility', 'backgroundColor', 'borderColor', 'borderTopColor', 'borderRightColor', 'borderBottomColor', 'borderLeftColor', 'borderStartColor', 'borderEndColor', 'borderRadius', 'borderTopLeftRadius', 'borderTopRightRadius', 'borderTopStartRadius', 'borderTopEndRadius', 'borderBottomLeftRadius', 'borderBottomRightRadius', 'borderBottomStartRadius', 'borderBottomEndRadius', 'borderStyle', 'opacity', 'elevation'];
5+
const TextStylePropTypes = ['display', 'width', 'height', 'start', 'end', 'top', 'left', 'right', 'bottom', 'minWidth', 'maxWidth', 'minHeight', 'maxHeight', 'margin', 'marginVertical', 'marginHorizontal', 'marginTop', 'marginBottom', 'marginLeft', 'marginRight', 'marginStart', 'marginEnd', 'padding', 'paddingVertical', 'paddingHorizontal', 'paddingTop', 'paddingBottom', 'paddingLeft', 'paddingRight', 'paddingStart', 'paddingEnd', 'borderWidth', 'borderTopWidth', 'borderStartWidth', 'borderEndWidth', 'borderRightWidth', 'borderBottomWidth', 'borderLeftWidth', 'position', 'flexDirection', 'flexWrap', 'justifyContent', 'alignItems', 'alignSelf', 'alignContent', 'overflow', 'flex', 'flexGrow', 'flexShrink', 'flexBasis', 'aspectRatio', 'zIndex', 'direction', 'shadowColor', 'shadowOffset', 'shadowOpacity', 'shadowRadius', 'transform', 'transformMatrix', 'decomposedMatrix', 'scaleX', 'scaleY', 'rotation', 'translateX', 'translateY', 'backfaceVisibility', 'backgroundColor', 'borderColor', 'borderTopColor', 'borderRightColor', 'borderBottomColor', 'borderLeftColor', 'borderStartColor', 'borderEndColor', 'borderRadius', 'borderTopLeftRadius', 'borderTopRightRadius', 'borderTopStartRadius', 'borderTopEndRadius', 'borderBottomLeftRadius', 'borderBottomRightRadius', 'borderBottomStartRadius', 'borderBottomEndRadius', 'borderStyle', 'opacity', 'elevation', 'color', 'fontFamily', 'fontSize', 'fontStyle', 'fontWeight', 'fontVariant', 'textShadowOffset', 'textShadowRadius', 'textShadowColor', 'letterSpacing', 'lineHeight', 'textAlign', 'textAlignVertical', 'includeFontPadding', 'textDecorationLine', 'textDecorationStyle', 'textDecorationColor', 'textTransform', 'writingDirection']
46

57
// Filter prop-types that are only applicable to <Text> and not <View>
6-
export let TextOnlyPropTypes = {};
7-
Object.keys(TextStylesPropTypes).forEach((prop) => {
8-
if (!DeprecatedViewStylePropTypes[prop]) {
9-
TextOnlyPropTypes[prop] = TextStylesPropTypes[prop];
10-
}
11-
});
8+
export const TextOnlyPropTypes = TextStylePropTypes.filter((prop) => ViewStylePropTypes.indexOf(prop) === -1);
129

1310
// These tags should ALWAYS be mapped to View wrappers
1411
export const BLOCK_TAGS = ['address', 'article', 'aside', 'footer', 'hgroup', 'nav', 'section', 'blockquote', 'dd',
@@ -41,7 +38,8 @@ export const ABSOLUTE_FONT_SIZE = {
4138
'larger': 16,
4239
'length': null,
4340
'initial': null,
44-
'inherit': null
41+
'inherit': null,
42+
'unset': null
4543
};
4644

4745
export const IGNORED_TAGS = ['head', 'scripts', 'audio', 'video', 'track', 'embed', 'object', 'param', 'source', 'canvas', 'noscript',
@@ -57,20 +55,12 @@ export const PERC_SUPPORTED_STYLES = [
5755
'padding', 'paddingBottom', 'paddingTop', 'paddingLeft', 'paddingRight', 'paddingHorizontal', 'paddingVertical'
5856
];
5957

60-
// We have to do some munging here as the objects are wrapped
61-
const RNTextStylePropTypes = Object.keys(TextStylesPropTypes)
62-
.reduce((acc, k) => { acc[k] = TextStylesPropTypes[k]; return acc; }, {});
63-
const RNViewStylePropTypes = Object.keys(DeprecatedViewStylePropTypes)
64-
.reduce((acc, k) => { acc[k] = DeprecatedViewStylePropTypes[k]; return acc; }, {});
65-
const RNImageStylePropTypes = Object.keys(DeprecatedImageStylesPropTypes)
66-
.reduce((acc, k) => { acc[k] = DeprecatedImageStylesPropTypes[k]; return acc; }, {});
67-
6858
export const STYLESETS = Object.freeze({ VIEW: 'view', TEXT: 'text', IMAGE: 'image' });
69-
70-
export const stylePropTypes = {};
71-
stylePropTypes[STYLESETS.VIEW] = Object.assign({}, RNViewStylePropTypes);
72-
stylePropTypes[STYLESETS.TEXT] = Object.assign({}, RNViewStylePropTypes, RNTextStylePropTypes);
73-
stylePropTypes[STYLESETS.IMAGE] = Object.assign({}, RNViewStylePropTypes, RNImageStylePropTypes);
59+
export const stylePropTypes = {
60+
[STYLESETS.VIEW]: ViewStylePropTypes,
61+
[STYLESETS.TEXT]: TextStylePropTypes,
62+
[STYLESETS.IMAGE]: ImageStylePropTypes
63+
};
7464

7565
/**
7666
* Returns an array with the tagname of every parent of a node.

src/checkPropTypes.js

Lines changed: 0 additions & 69 deletions
This file was deleted.

0 commit comments

Comments
 (0)