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
Closed

Conversation

Peretz30
Copy link

Warning! Breaking change
Added textProps prop that replace existing textSelectable and allowFontScaling. Now, with this prop you are able to apply any text prop (selectable, textBreakStrategy, etc.) to text wrapper component.

Example usage:

                    <HTML
                        html={
                            newsItem.bodyHtml ||
                            '<div></div>'
                        }
                        imagesMaxWidth={maxWidth}
                        onLinkPress={onLinkPress}
                        tagsStyles={backendStyles.tagsStyles}
                        baseFontStyle={styles.text}
                        textProps={{ textBreakStrategy: "simple" }}
                    />

@lingtran
Copy link

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.

@jjhampton
Copy link

Please review and merge, this is a necessary fix w/ changes that Android Q introduced with text wrapping.

@kuetsch
Copy link

kuetsch commented May 28, 2020

This would really be helpful! Would love to see the next release incorporate this fix.
Btw. I think there is one more location where the fix needs to be applied: Its the textwrapper-Function in HTMLRenderers.js

@kamalpandey
Copy link

Waiting for this one to get review and merged.

Copy link
Collaborator

@jsamr jsamr left a 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!

README.md Outdated Show resolved Hide resolved
src/HTML.js Outdated Show resolved Hide resolved
@Peretz30
Copy link
Author

Peretz30 commented Jul 8, 2020

@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.

@Peretz30 Peretz30 requested a review from jsamr July 8, 2020 22:54
Copy link
Collaborator

@jsamr jsamr left a 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] });
Copy link
Collaborator

@jsamr jsamr Jul 9, 2020

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
Copy link
Collaborator

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 = {};
Copy link
Collaborator

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) => {
Copy link
Collaborator

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
Copy link
Collaborator

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') {
Copy link
Collaborator

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;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Idem

@jsamr jsamr added the pr:breaking Pull Request introducing a breaking change. label Jul 9, 2020
@jsamr jsamr linked an issue Jul 19, 2020 that may be closed by this pull request
@Peretz30
Copy link
Author

hey @jsamr ! Sorry for late response, I was very busy last week. I cleaned up code formatting. Check this out, please.

@Peretz30 Peretz30 requested a review from jsamr July 28, 2020 18:09
Copy link
Collaborator

@jsamr jsamr left a 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` | `{}`
Copy link
Collaborator

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>
Copy link
Collaborator

Choose a reason for hiding this comment

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

Ibdem

@jsamr jsamr changed the title Added textProps prop [5.x] Added textProps prop Nov 27, 2020
@jsamr jsamr closed this in 7264cbe Dec 5, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
is:waiting for feedback Waiting for OP input. pr:breaking Pull Request introducing a breaking change.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Last pragraph sentence of some html text gets cuts off i.e not shown Add support for maxFontSizeMultiplier
6 participants