-
-
Notifications
You must be signed in to change notification settings - Fork 591
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
Conversation
Awesome, thanks for creating this pull request. I totally understand folks may be swamped at the moment. There have been a number of requests for this fix since Android Q made the text change. For our team we aren't able to simply add the textBreakStrategy prop directly. So we've created a fork with this fix. It would be great if this can be reviewed by a few of the maintainers and merged soon. |
Please review and merge, this is a necessary fix w/ changes that Android Q introduced with text wrapping. |
This would really be helpful! Would love to see the next release incorporate this fix. |
Waiting for this one to get review and merged. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you so much for your participation, this is a great idea. I've added a few suggestions!
Because this feature would break current API, it will require a 5.0 release. But that sounds reasonable. We have a lot of pending PR that ought to be merged!
@jsamr thanks for your suggestions. Please, take a look at PR now. Looks like there are still some formatting problems. If it's critical. I can resolve them some later. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See my comments! Sorry about the formatting issues: it would be much better if we enforced a formatting style with a linter and add some guidance for PRs. Will certainly do in the future though.
src/HTML.js
Outdated
|
||
const renderersProps = {}; | ||
if (Wrapper === Text) { | ||
renderersProps.allowFontScaling = allowFontScaling; | ||
renderersProps.selectable = textSelectable; | ||
Object.keys(textWrapperProps).map(propName => { renderersProps[propName] = textWrapperProps[propName] }); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would rather go with:
let renderersProps = {};
if (Wrapper === Text) {
renderersProps = textWrapperProps
}
which I find easier to read
src/HTML.js
Outdated
tagName, | ||
nodeIndex | ||
}; | ||
.filter((parsedNode) => parsedNode !== false && parsedNode !== undefined) // remove useless nodes |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because it is unnecessary formatting, you can reset this hunk to its master state.
To do so, you can do:
git checkout --patch src/HTML.js master
It will prompt you to select the hunks you want to restore to master's state, and those you want to keep ;-)
src/HTML.js
Outdated
if (TextOnlyPropTypes.indexOf(styleKey) !== -1) { | ||
textChildrenInheritedStyles[styleKey] = wrapperStyles[styleKey]; | ||
delete wrapperStyles[styleKey]; | ||
let textChildrenInheritedStyles = {}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Idem
src/HTML.js
Outdated
textChildrenInheritedStyles[styleKey] = wrapperStyles[styleKey]; | ||
delete wrapperStyles[styleKey]; | ||
let textChildrenInheritedStyles = {}; | ||
Object.keys(wrapperStyles).forEach((styleKey) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Idem
src/HTML.js
Outdated
delete wrapperStyles[styleKey]; | ||
let textChildrenInheritedStyles = {}; | ||
Object.keys(wrapperStyles).forEach((styleKey) => { | ||
// Extract text-only styles |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Idem
src/HTML.js
Outdated
...textChildrenInheritedStyles, | ||
...cssStringToObject(child.attribs.style) | ||
}); | ||
if (wrapper === 'Text') { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Idem
src/HTML.js
Outdated
} | ||
return parsedNode; | ||
}); | ||
return parsedNode; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Idem
This reverts commit d2c5175.
This reverts commit ea0488f.
…tive-render-html" This reverts commit 5e23fb9, reversing changes made to 28d57f2.
hey @jsamr ! Sorry for late response, I was very busy last week. I cleaned up code formatting. Check this out, please. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
After you offered this PR the first time, we published guidelines for PRs in which we would require:
- Implementing tests on the new feature.
- Changing the typescript definitions to reflect API changes.
In addition, I will ask you to rebase on master as you will have to resolve some conflicts. After which you can run some tests. There is notably a test about textSelectable
that could fail with your changes, but should be an easy fix.
If you have any question or looking for advise on any of those steps, you're welcome to ping me in our Discord #contributing channel
@@ -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` | `{}` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
applied
@@ -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> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ibdem
Warning! Breaking change
Added
textProps
prop that replace existingtextSelectable
andallowFontScaling
. Now, with this prop you are able to apply any text prop (selectable
,textBreakStrategy
, etc.) to text wrapper component.Example usage: