1
1
import React , { PureComponent } from 'react' ;
2
2
import PropTypes from 'prop-types' ;
3
3
import { View , Text , ViewPropTypes , ActivityIndicator , Dimensions } from 'react-native' ;
4
- import { BLOCK_TAGS , TEXT_TAGS , MIXED_TAGS , IGNORED_TAGS , TEXT_TAGS_IGNORING_ASSOCIATION , STYLESETS , TextOnlyPropTypes } from './HTMLUtils' ;
5
- import { cssStringToRNStyle , _getElementClassStyles , cssStringToObject , cssObjectToString } from './HTMLStyles' ;
4
+ import { cssStringToRNStyle , _getElementClassStyles , cssStringToObject , cssObjectToString , computeTextStyles } from './HTMLStyles' ;
5
+ import {
6
+ BLOCK_TAGS ,
7
+ TEXT_TAGS ,
8
+ MIXED_TAGS ,
9
+ IGNORED_TAGS ,
10
+ TEXT_TAGS_IGNORING_ASSOCIATION ,
11
+ STYLESETS ,
12
+ TextOnlyPropTypes
13
+ } from './HTMLUtils' ;
6
14
import { generateDefaultBlockStyles , generateDefaultTextStyles } from './HTMLDefaultStyles' ;
7
15
import htmlparser2 from 'htmlparser2' ;
8
16
import * as HTMLRenderers from './HTMLRenderers' ;
@@ -149,36 +157,6 @@ export default class HTML extends PureComponent {
149
157
this . defaultTextStyles = generateDefaultTextStyles ( baseFontStyle . fontSize || 14 ) ;
150
158
}
151
159
152
- filterBaseFontStyles ( element , classStyles , props = this . props ) {
153
- const { tagsStyles, baseFontStyle } = props ;
154
- const { tagName, parentTag, parent, attribs } = element ;
155
- const styles = Object . keys ( baseFontStyle ) ;
156
- let appliedStyles = { } ;
157
-
158
- for ( let i = 0 ; i < styles . length ; i ++ ) {
159
- const styleAttribute = styles [ i ] ;
160
- const tagToCheck = tagName === 'rawtext' ? parentTag : tagName ;
161
- const styleAttributeWithCSSDashes = styleAttribute . replace ( / [ A - Z ] / , ( match ) => { return `-${ match . toLowerCase ( ) } ` ; } ) ;
162
- const overridenFromStyle = attribs && attribs . style && attribs . style . search ( styleAttributeWithCSSDashes ) !== - 1 ;
163
- const overridenFromParentStyle = parent && parent . attribs && parent . attribs . style && parent . attribs . style . search ( styleAttributeWithCSSDashes ) !== - 1 ;
164
-
165
- const overridenFromTagStyle = tagToCheck && tagsStyles [ tagToCheck ] && tagsStyles [ tagToCheck ] [ styleAttribute ] ;
166
- const overridenFromParentTagStyle = parentTag && tagsStyles [ parentTag ] && tagsStyles [ parentTag ] [ styleAttribute ] ;
167
-
168
- const overridenFromClassStyles = classStyles && classStyles [ styleAttribute ] ;
169
- const overridenFromDefaultStyles = this . defaultTextStyles [ tagToCheck ] && this . defaultTextStyles [ tagToCheck ] [ styleAttribute ] ;
170
-
171
- const notOverriden = ! overridenFromStyle && ! overridenFromParentStyle &&
172
- ! overridenFromTagStyle && ! overridenFromParentTagStyle &&
173
- ! overridenFromClassStyles && ! overridenFromDefaultStyles ;
174
-
175
- if ( notOverriden ) {
176
- appliedStyles [ styleAttribute ] = baseFontStyle [ styleAttribute ] ;
177
- }
178
- }
179
- return appliedStyles ;
180
- }
181
-
182
160
/**
183
161
* Loop on children and return whether if their parent needs to be a <View>
184
162
* @param {any } children
@@ -403,7 +381,7 @@ export default class HTML extends PureComponent {
403
381
* @memberof HTML
404
382
*/
405
383
renderRNElements ( RNElements , parentWrapper = 'root' , parentIndex = 0 , props = this . props ) {
406
- const { tagsStyles, classesStyles, emSize, ptSize, ignoredStyles, allowedStyles } = props ;
384
+ const { tagsStyles, classesStyles, emSize, ptSize, ignoredStyles, allowedStyles, baseFontStyle } = props ;
407
385
return RNElements && RNElements . length ? RNElements . map ( ( element , index ) => {
408
386
const { attribs, data, tagName, parentTag, children, nodeIndex, wrapper } = element ;
409
387
const Wrapper = wrapper === 'Text' ? Text : View ;
@@ -449,9 +427,23 @@ export default class HTML extends PureComponent {
449
427
}
450
428
451
429
const classStyles = _getElementClassStyles ( attribs , classesStyles ) ;
452
- const textElementStyles = this . filterBaseFontStyles ( element , classStyles , props ) ;
453
430
const textElement = data ?
454
- < Text style = { textElementStyles } > { data } </ Text > :
431
+ < Text
432
+ style = { computeTextStyles (
433
+ element ,
434
+ {
435
+ defaultTextStyles : this . defaultTextStyles ,
436
+ tagsStyles,
437
+ classesStyles,
438
+ baseFontStyle,
439
+ emSize,
440
+ ptSize,
441
+ ignoredStyles,
442
+ allowedStyles
443
+ } ) }
444
+ >
445
+ { data }
446
+ </ Text > :
455
447
false ;
456
448
457
449
const style = [
@@ -463,7 +455,9 @@ export default class HTML extends PureComponent {
463
455
. filter ( ( s ) => s !== undefined ) ;
464
456
465
457
const extraProps = { } ;
466
- if ( Wrapper === Text ) extraProps . selectable = this . props . textSelectable ;
458
+ if ( Wrapper === Text ) {
459
+ extraProps . selectable = this . props . textSelectable ;
460
+ }
467
461
return (
468
462
< Wrapper key = { key } style = { style } { ...extraProps } >
469
463
{ textElement }
0 commit comments