Skip to content

Commit

Permalink
CustomLineHeightSpan: Increase the readability (#42592)
Browse files Browse the repository at this point in the history
Summary:
Increase the readability of `CustomLineHeightSpan` by making the logic less stateful.

This is a minor improvement in the context of my multi-PR work on react-native-community/discussions-and-proposals#695.

## Changelog:

<!-- Help reviewers and the release process by writing your own changelog entry.

Pick one each for the category and type tags:

[ANDROID|GENERAL|IOS|INTERNAL] [BREAKING|ADDED|CHANGED|DEPRECATED|REMOVED|FIXED|SECURITY] - Message

For more details, see:
https://reactnative.dev/contributing/changelogs-in-pull-requests
-->

[INTERNAL] [CHANGED] - Increase the readability of `CustomLineHeightSpan`

Pull Request resolved: #42592

Test Plan:
- Prove the equivalence of the old and the new logic
- Test that the behavior of `lineHeight` doesn't change

Reviewed By: NickGerleman

Differential Revision: D53028467

Pulled By: mdvacca

fbshipit-source-id: d533bb77c8e10c29d8f2acc8cc39565d0013b03b
  • Loading branch information
cubuspl42 authored and facebook-github-bot committed Jan 25, 2024
1 parent a5aed12 commit 0111523
Showing 1 changed file with 7 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,13 @@ public void chooseHeight(

// Round up for the negative values and down for the positive values (arbitrary choice)
// So that bottom - top equals additional even if it's an odd number.
fm.top -= Math.ceil(additional / 2.0f);
fm.bottom += Math.floor(additional / 2.0f);
fm.ascent = fm.top;
fm.descent = fm.bottom;
final int top = (int) (fm.top - Math.ceil(additional / 2.0f));
final int bottom = (int) (fm.bottom + Math.floor(additional / 2.0f));

fm.top = top;
fm.ascent = top;
fm.descent = bottom;
fm.bottom = bottom;
}
}
}

0 comments on commit 0111523

Please sign in to comment.