Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[5.x] Added textProps prop #349

Closed
wants to merge 9 commits into from
3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,7 @@ Prop | Description | Type | Required/Default
`emSize` | The default value in pixels for `1em` | `number` | `14`
`ptSize` | The default value in pixels for `1pt` | `number` | `1.3`
`baseFontStyle` | The default style applied to `<Text>` components | `object` | `{ fontSize: 14 }`
`allowFontScaling` | Specifies whether fonts should scale to respect Text Size accessibility settings | `boolean` | `true`
`textSelectable` | Allow all texts to be selected | `boolean` | `false`
`textWrapperProps` | Object with props, that would be applyed to text wrapper. For example `{allowFontScaling: 'false'}` | `object` | `{}`
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

applied

`alterData` | Target some specific texts and change their content, see [altering content](#altering-content) | `function` | Optional
`alterChildren` | Target some specific nested children and change them, see [altering content](#altering-content) | `function` | Optional
`alterNode` | Target a specific node and change it, see [altering content](#altering-content) | `function` | Optional
Expand Down
18 changes: 7 additions & 11 deletions src/HTML.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,8 @@ export default class HTML extends PureComponent {
emSize: PropTypes.number.isRequired,
ptSize: PropTypes.number.isRequired,
baseFontStyle: PropTypes.object.isRequired,
textSelectable: PropTypes.bool,
renderersProps: PropTypes.object,
allowFontScaling: PropTypes.bool
textWrapperProps: PropTypes.object,
}

static defaultProps = {
Expand All @@ -64,8 +63,7 @@ export default class HTML extends PureComponent {
baseFontStyle: { fontSize: 14 },
tagsStyles: {},
classesStyles: {},
textSelectable: false,
allowFontScaling: true
textWrapperProps: {},
}

constructor (props) {
Expand Down Expand Up @@ -388,15 +386,14 @@ export default class HTML extends PureComponent {
*/
renderRNElements (RNElements, parentWrapper = 'root', parentIndex = 0, props = this.props) {
const {
allowFontScaling,
allowedStyles,
baseFontStyle,
classesStyles,
emSize,
ignoredStyles,
ptSize,
tagsStyles,
textSelectable
textWrapperProps,
} = props;

return RNElements && RNElements.length ? RNElements.map((element, index) => {
Expand Down Expand Up @@ -446,7 +443,6 @@ export default class HTML extends PureComponent {
const classStyles = _getElementClassStyles(attribs, classesStyles);
const textElement = data ?
<Text
allowFontScaling={allowFontScaling}
style={computeTextStyles(
element,
{
Expand All @@ -459,6 +455,7 @@ export default class HTML extends PureComponent {
ignoredStyles,
allowedStyles
})}
{ ...textWrapperProps }
>
{ data }
</Text> :
Expand All @@ -474,8 +471,7 @@ export default class HTML extends PureComponent {

const renderersProps = {};
if (Wrapper === Text) {
renderersProps.allowFontScaling = allowFontScaling;
renderersProps.selectable = textSelectable;
renderersProps = textWrapperProps;
}
return (
<Wrapper key={key} style={style} {...renderersProps}>
Expand All @@ -487,7 +483,7 @@ export default class HTML extends PureComponent {
}

render () {
const { allowFontScaling, customWrapper, remoteLoadingView, remoteErrorView } = this.props;
const { textWrapperProps, customWrapper, remoteLoadingView, remoteErrorView } = this.props;
const { RNNodes, loadingRemoteURL, errorLoadingRemoteURL } = this.state;
if (!RNNodes && !loadingRemoteURL && !errorLoadingRemoteURL) {
return null;
Expand All @@ -504,7 +500,7 @@ export default class HTML extends PureComponent {
remoteErrorView(this.props, this.state) :
(
<View style={{ flex: 1, alignItems: 'center' }}>
<Text allowFontScaling={allowFontScaling} style={{ fontStyle: 'italic', fontSize: 16 }}>Could not load { this.props.uri }</Text>
<Text { ...textWrapperProps } style={{ fontStyle: 'italic', fontSize: 16 }}>Could not load { this.props.uri }</Text>
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ibdem

</View>
);
}
Expand Down