aMarCruz / react-native-text-size

Measure text accurately before laying it out and get font information from your App.
BSD 2-Clause "Simplified" License
405 stars 95 forks source link

Introduce line end prop for Android to measure index of line end char #11

Closed tuncaulubilge closed 6 years ago

tuncaulubilge commented 6 years ago

Great library, really saved our lives. Thanks!

We have a specific use case where we need to measure how many words can fit in a certain textbox within a max amount of lines. This is especially useful if you want to simulate inline images and text wraps, where you need to split the text into multiple textboxes around the image.

This PR introduces a new prop to the measure method, called lineEndForLineNo, and returns the number of characters that can fit into those lines. This utilizes Android Layout's getLineVisibleEnd method.

aMarCruz commented 6 years ago

@tuncaulubilge thanks. I will check it. (I want to keep iOS compatibility on this)

tuncaulubilge commented 6 years ago

What's the plans for iOS compatibility? I'm not an expert in iOS but I'm happy to help to ensure compatibility. This looks like a useful approach for iOS: https://developer.apple.com/library/archive/documentation/Cocoa/Conceptual/TextLayout/Tasks/CountLines.html

aMarCruz commented 6 years ago

@tuncaulubilge thanks, I already have the code for iOS but not time to testing yet. I will include bottom and right info for the end line and update the sample app. (I also tried to include ellipsis information, but without rendering the text on Android it is complicated)

Hope publish the new version before this weekend.