-
Notifications
You must be signed in to change notification settings - Fork 16
Description
Am I correct that the calculation for truncationIndex doesn't properly account for the default word break mode for React Native's Text? namely, a word will not be cut partially for line wrap - the entire word will be moved to the next line (at least for iOS - I know you can control this behavior with Android).
This severely undercounts the width (really space/pixels) needed to render some given text:
const { width: totalTextWidth } = await reactNativeTextSize.measure({ text, fontSize: scaledFontSize, fontFamily, fontWeight, });
as a line will be filled with empty space if the last word needs to be moved to the next line.
Example of incorrect calculation(s), current v1.3.0 code and behavior I saw using v1.1.0 for a year+:
Expected (and using my fixes):
I have modified SeeMoreUtils.js to instead calculate how each line would be rendered, thus taking into account word break where the word is not broken partially. I can post it here, but
- please let me know if I'm misunderstanding the current behavior and/or am missing some prop/config that will account for this behavior
- or if I should just fork, I can do that as well
Just want to help others, if possible
Basically, my code breaks up the text into lines, accounting for word break moving the last word of a line to the next line if it can't fit, so it better mimics the actual rendering when it does the truncationIndex calculation. Then, I re-assemble the text based on numberOfLines and truncate the last line appropriately to fit the seeMoreText

