Skip to content

Commit 0111523

Browse files
cubuspl42facebook-github-bot
authored andcommitted
CustomLineHeightSpan: Increase the readability (#42592)
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
1 parent a5aed12 commit 0111523

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

packages/react-native/ReactAndroid/src/main/java/com/facebook/react/views/text/CustomLineHeightSpan.java

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,10 +54,13 @@ public void chooseHeight(
5454

5555
// Round up for the negative values and down for the positive values (arbitrary choice)
5656
// So that bottom - top equals additional even if it's an odd number.
57-
fm.top -= Math.ceil(additional / 2.0f);
58-
fm.bottom += Math.floor(additional / 2.0f);
59-
fm.ascent = fm.top;
60-
fm.descent = fm.bottom;
57+
final int top = (int) (fm.top - Math.ceil(additional / 2.0f));
58+
final int bottom = (int) (fm.bottom + Math.floor(additional / 2.0f));
59+
60+
fm.top = top;
61+
fm.ascent = top;
62+
fm.descent = bottom;
63+
fm.bottom = bottom;
6164
}
6265
}
6366
}

0 commit comments

Comments
 (0)