From 2668c00248066e8a651a749908ba03900c28d9ee Mon Sep 17 00:00:00 2001 From: Thomas Parslow Date: Wed, 12 Apr 2017 17:34:23 +0100 Subject: [PATCH 1/2] Support for React 16. Fix for #20 --- HTMLStyles.js | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/HTMLStyles.js b/HTMLStyles.js index f805d60..33fc35c 100644 --- a/HTMLStyles.js +++ b/HTMLStyles.js @@ -1,6 +1,5 @@ import { StyleSheet } from 'react-native' import React from 'react' -import ReactPropTypeLocations from 'react/lib/ReactPropTypeLocations' // We have to do some munging here as the objects are wrapped import _RNTextStylePropTypes from 'react-native/Libraries/Text/TextStylePropTypes' @@ -171,13 +170,13 @@ class HTMLStyles { const testStyle = {} testStyle[key] = value - if (styleProps[key](testStyle, key, '', ReactPropTypeLocations.prop)) { + if (styleProps[key](testStyle, key, '', 'prop')) { // See if we can convert a 20px to a 20 automagically if (styleProps[key] === React.PropTypes.number) { const numericValue = parseFloat(value.replace('px', '')) if (!isNaN(numericValue)) { testStyle[key] = numericValue - if (!styleProps[key](testStyle, key, '', ReactPropTypeLocations.prop)) { + if (!styleProps[key](testStyle, key, '', 'prop')) { return [key, numericValue] } } From d534ffc8c05d44546f66a471c4aed2475d5f4d0e Mon Sep 17 00:00:00 2001 From: Thomas Parslow Date: Sun, 18 Feb 2018 21:27:28 +0000 Subject: [PATCH 2/2] Use prop-types for compatability with newer react --- HTML.js | 9 +++++---- HTMLElement.js | 19 ++++++++++--------- HTMLStyles.js | 3 ++- HTMLTextNode.js | 3 ++- package.json | 3 ++- 5 files changed, 21 insertions(+), 16 deletions(-) diff --git a/HTML.js b/HTML.js index 5d2cdb3..1ed52b3 100644 --- a/HTML.js +++ b/HTML.js @@ -6,6 +6,7 @@ import HTMLElement from './HTMLElement' import HTMLTextNode from './HTMLTextNode' import HTMLRenderers from './HTMLRenderers' import HTMLStyles from './HTMLStyles' +import PropTypes from 'prop-types'; class HTML extends React.Component { /* ****************************************************************************/ @@ -13,10 +14,10 @@ class HTML extends React.Component { /* ****************************************************************************/ static propTypes = { - html: React.PropTypes.string.isRequired, - htmlStyles: React.PropTypes.object, - onLinkPress: React.PropTypes.func, - renderers: React.PropTypes.object.isRequired + html: PropTypes.string.isRequired, + htmlStyles: PropTypes.object, + onLinkPress: PropTypes.func, + renderers: PropTypes.object.isRequired } static defaultProps = { diff --git a/HTMLElement.js b/HTMLElement.js index 84ffb4a..0df3412 100644 --- a/HTMLElement.js +++ b/HTMLElement.js @@ -2,6 +2,7 @@ import React from 'react' import { Text, View } from 'react-native' import shallowCompare from 'react-addons-shallow-compare' import HTMLStyles from './HTMLStyles' +import PropTypes from 'prop-types'; class HTMLElement extends React.Component { /* ****************************************************************************/ @@ -9,15 +10,15 @@ class HTMLElement extends React.Component { /* ****************************************************************************/ static propTypes = { - tagName: React.PropTypes.string.isRequired, - renderers: React.PropTypes.object.isRequired, - groupInfo: React.PropTypes.object, - parentTagName: React.PropTypes.string, - htmlStyles: React.PropTypes.object, - htmlAttibs: React.PropTypes.object, - onLinkPress: React.PropTypes.func, - children: React.PropTypes.node, - parentIsText: React.PropTypes.bool.isRequired + tagName: PropTypes.string.isRequired, + renderers: PropTypes.object.isRequired, + groupInfo: PropTypes.object, + parentTagName: PropTypes.string, + htmlStyles: PropTypes.object, + htmlAttibs: PropTypes.object, + onLinkPress: PropTypes.func, + children: PropTypes.node, + parentIsText: PropTypes.bool.isRequired } /* ****************************************************************************/ diff --git a/HTMLStyles.js b/HTMLStyles.js index 33fc35c..dc3cdfc 100644 --- a/HTMLStyles.js +++ b/HTMLStyles.js @@ -1,5 +1,6 @@ import { StyleSheet } from 'react-native' import React from 'react' +import PropTypes from 'prop-types'; // We have to do some munging here as the objects are wrapped import _RNTextStylePropTypes from 'react-native/Libraries/Text/TextStylePropTypes' @@ -172,7 +173,7 @@ class HTMLStyles { testStyle[key] = value if (styleProps[key](testStyle, key, '', 'prop')) { // See if we can convert a 20px to a 20 automagically - if (styleProps[key] === React.PropTypes.number) { + if (styleProps[key] === PropTypes.number) { const numericValue = parseFloat(value.replace('px', '')) if (!isNaN(numericValue)) { testStyle[key] = numericValue diff --git a/HTMLTextNode.js b/HTMLTextNode.js index 446b9de..260ec6a 100644 --- a/HTMLTextNode.js +++ b/HTMLTextNode.js @@ -2,6 +2,7 @@ import React from 'react' import { Text } from 'react-native' import shallowCompare from 'react-addons-shallow-compare' import { AllHtmlEntities } from 'html-entities' +import PropTypes from 'prop-types'; const RE = Object.freeze({ MULT_WHITESPACE: new RegExp(/\s+/g), @@ -27,7 +28,7 @@ class HTMLTextNode extends React.Component { /* ****************************************************************************/ static propTypes = { - children: React.PropTypes.string.isRequired + children: PropTypes.string.isRequired } /** diff --git a/package.json b/package.json index da8bd1c..972cfb6 100644 --- a/package.json +++ b/package.json @@ -24,7 +24,8 @@ "peerDependencies": { "react": ">=0.14.8", "react-native": ">=0.24.0", - "react-addons-shallow-compare": ">=0.14.8" + "react-addons-shallow-compare": ">=0.14.8", + "prop-types": "^15.6.0" }, "standard": { "parser": "babel-eslint"