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

Add numberOfLines, lineHeight options; create flatSizes; increase accuracy #37

Open
wants to merge 11 commits into
base: master
Choose a base branch
from

Conversation

hsource
Copy link

@hsource hsource commented Mar 30, 2022

Motivation

We have some Text components that

  • Use the numberOfLines prop to limit lines
  • Use the lineHeight style to change from the default line height
  • Have variable width

We want to measure their height using flatHeights.

This also increases accuracy for both iOS and Android by fixing tiny discrepancies.

Fix

  • Add handling for both Android and iOS for new FontSpecs called numberOfLines and flatHeights. This matches the <Text numberOfLines={...}> prop
  • Add new flatSizes function that behaves the same as flatHeights, but returns both the width and height. We use arrays (instead of objects with width and height) to reduce the amount key data passed over the React Native bridge

Testing

Created Storybook story in our app to test it on both Android and iOS:

iOS Android
image image

@hsource hsource changed the title Add numberOfLines parameter to limit number of lines Add numberOfLines and lineHeight options Mar 30, 2022
ios/RNTextSize.m Outdated Show resolved Hide resolved
ios/RNTextSize.m Outdated Show resolved Hide resolved
@hsource hsource changed the title Add numberOfLines and lineHeight options Add numberOfLines and lineHeight options; create flatSizes May 3, 2022
@hsource hsource changed the title Add numberOfLines and lineHeight options; create flatSizes Add numberOfLines, lineHeight options; create flatSizes; increase accuracy May 3, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants