Skip to content

Commit 76c4068

Browse files
AirshipAlexExilz
authored andcommitted
Add allowFontScaling prop
1 parent dea5f60 commit 76c4068

File tree

2 files changed

+32
-11
lines changed

2 files changed

+32
-11
lines changed

src/HTML.js

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,8 @@ export default class HTML extends PureComponent {
4646
ptSize: PropTypes.number.isRequired,
4747
baseFontStyle: PropTypes.object.isRequired,
4848
textSelectable: PropTypes.bool,
49-
renderersProps: PropTypes.object
49+
renderersProps: PropTypes.object,
50+
allowFontScaling: PropTypes.bool
5051
}
5152

5253
static defaultProps = {
@@ -62,7 +63,8 @@ export default class HTML extends PureComponent {
6263
baseFontStyle: { fontSize: 14 },
6364
tagsStyles: {},
6465
classesStyles: {},
65-
textSelectable: false
66+
textSelectable: false,
67+
allowFontScaling: true
6668
}
6769

6870
constructor (props) {
@@ -382,7 +384,18 @@ export default class HTML extends PureComponent {
382384
* @memberof HTML
383385
*/
384386
renderRNElements (RNElements, parentWrapper = 'root', parentIndex = 0, props = this.props) {
385-
const { tagsStyles, classesStyles, emSize, ptSize, ignoredStyles, allowedStyles, baseFontStyle } = props;
387+
const {
388+
allowFontScaling,
389+
allowedStyles,
390+
baseFontStyle,
391+
classesStyles,
392+
emSize,
393+
ignoredStyles,
394+
ptSize,
395+
tagsStyles,
396+
textSelectable
397+
} = props;
398+
386399
return RNElements && RNElements.length ? RNElements.map((element, index) => {
387400
const { attribs, data, tagName, parentTag, children, nodeIndex, wrapper } = element;
388401
const Wrapper = wrapper === 'Text' ? Text : View;
@@ -430,6 +443,7 @@ export default class HTML extends PureComponent {
430443
const classStyles = _getElementClassStyles(attribs, classesStyles);
431444
const textElement = data ?
432445
<Text
446+
allowFontScaling={allowFontScaling}
433447
style={computeTextStyles(
434448
element,
435449
{
@@ -457,7 +471,8 @@ export default class HTML extends PureComponent {
457471

458472
const renderersProps = {};
459473
if (Wrapper === Text) {
460-
renderersProps.selectable = this.props.textSelectable;
474+
renderersProps.allowFontScaling = allowFontScaling;
475+
renderersProps.selectable = textSelectable;
461476
}
462477
return (
463478
<Wrapper key={key} style={style} {...renderersProps}>
@@ -469,7 +484,7 @@ export default class HTML extends PureComponent {
469484
}
470485

471486
render () {
472-
const { customWrapper, remoteLoadingView, remoteErrorView } = this.props;
487+
const { allowFontScaling, customWrapper, remoteLoadingView, remoteErrorView } = this.props;
473488
const { RNNodes, loadingRemoteURL, errorLoadingRemoteURL } = this.state;
474489
if (!RNNodes && !loadingRemoteURL) {
475490
return false;
@@ -486,7 +501,7 @@ export default class HTML extends PureComponent {
486501
remoteErrorView(this.props, this.state) :
487502
(
488503
<View style={{ flex: 1, alignItems: 'center' }}>
489-
<Text style={{ fontStyle: 'italic', fontSize: 16 }}>Could not load { this.props.uri }</Text>
504+
<Text allowFontScaling={allowFontScaling} style={{ fontStyle: 'italic', fontSize: 16 }}>Could not load { this.props.uri }</Text>
490505
</View>
491506
);
492507
}

src/HTMLRenderers.js

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ export function ul (htmlAttribs, children, convertedCSSStyles, passProps = {}) {
6363
passProps,
6464
styleSet: 'VIEW'
6565
});
66-
const { rawChildren, nodeIndex, key, baseFontStyle, listsPrefixesRenderers } = passProps;
66+
const { allowFontScaling, rawChildren, nodeIndex, key, baseFontStyle, listsPrefixesRenderers } = passProps;
6767
const baseFontSize = baseFontStyle.fontSize || 14;
6868

6969
children = children && children.map((child, index) => {
@@ -93,7 +93,7 @@ export function ul (htmlAttribs, children, convertedCSSStyles, passProps = {}) {
9393
);
9494
} else if (rawChild.parentTag === 'ol') {
9595
prefix = listsPrefixesRenderers && listsPrefixesRenderers.ol ? listsPrefixesRenderers.ol(...rendererArgs) : (
96-
<Text style={{ marginRight: 5, fontSize: baseFontSize }}>{ index + 1 })</Text>
96+
<Text allowFontScaling={allowFontScaling} style={{ marginRight: 5, fontSize: baseFontSize }}>{ index + 1 })</Text>
9797
);
9898
}
9999
}
@@ -146,12 +146,18 @@ export function iframe (htmlAttribs, children, convertedCSSStyles, passProps) {
146146

147147
export function br (htlmAttribs, children, convertedCSSStyles, passProps) {
148148
return (
149-
<Text style={{ height: 1.2 * passProps.emSize, flex: 1 }} key={passProps.key}>{"\n"}</Text>
149+
<Text
150+
allowFontScaling={passProps.allowFontScaling}
151+
style={{ height: 1.2 * passProps.emSize, flex: 1 }}
152+
key={passProps.key}
153+
>
154+
{"\n"}
155+
</Text>
150156
);
151157
}
152158

153-
export function textwrapper (htmlAttribs, children, convertedCSSStyles, { key }) {
159+
export function textwrapper (htmlAttribs, children, convertedCSSStyles, { allowFontScaling, key }) {
154160
return (
155-
<Text key={key} style={convertedCSSStyles}>{ children }</Text>
161+
<Text allowFontScaling={allowFontScaling} key={key} style={convertedCSSStyles}>{ children }</Text>
156162
);
157163
}

0 commit comments

Comments
 (0)