-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Text anchoring is not calculated correctly if the line contains multiple TSpans #1205
Comments
Interesting, have you tried running this code on the web? https://codesandbox.io/s/pypn6mn3y7 |
@msand yeah looks good with react-native-web (https://codesandbox.io/s/react-native-svg-test-0467e), and the code in my repro I converted to proper SVG and it worked fine in Google Chrome. I haven't done any testing with iOS but I can do that this evening. |
Does #1206 look like a reasonable approach to solving this? I was hoping there would be a way without rebuilding all the FontData for every span but I couldn't get that working. |
I think it should be possible to achieve without that, i think that implementation is N^2 or even N^N in deeply nested situations, in the number of text children, rather than 2*N, not sure why this isn't working correctly to begin with, as I remember it, I made the getSubtreeTextChunksTotalAdvance specifically to be able to handle this use-case correctly. But, it's some time ago and haven't had time to look deeper into this again. |
I guess getting the font from I agree my method is inefficient though, maybe it's just a case of calculating and adding an mFontData property to the TSpanView class so that it's cached. |
We should probably make it a two pass algorithm, one to calculate the fonts and other text properties, glyph positions, advance etc. which can be cached, and then another pass to actually render based on that data. This way it wouldn't process a text node more than once. At least the advance should be calculated in what is essentially a layout step, and then use that for text alignment etc. |
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. You may also mark this issue as a "discussion" and I will leave this open. |
Not stale but I don't have time to look at this at the moment. If anyone is interested in developing a more efficient fix for this please feel free! |
Bug
If a line of text with
textAnchor="middle"
comprises multiple<TSpan>
s, each span is centred on itself (from the position it would have been in withtextAnchor="start"
), rather than as a whole line of text.Probably easier to explain with a screenshot:
I'll push up a PR in a minute that solves this particular issue, however not being much of a Native Android/Java developer it's likely there's a better way to do this, and I can't be sure this hasn't broken something else.
Environment info
React native info output:
Library version: 9.13.3
Steps To Reproduce
<Text textAnchor="middle">
element containing multiple<TSpan>
sDescribe what you expected to happen:
Reproducible sample code
https://github.com/mjmasn/TSpanIssue
The text was updated successfully, but these errors were encountered: