mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
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 https://github.com/react-native-community/discussions-and-proposals/issues/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: https://github.com/facebook/react-native/pull/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
This commit is contained in:
committed by
Facebook GitHub Bot
parent
a5aed1294f
commit
011152318a
+7
-4
@@ -54,10 +54,13 @@ public class CustomLineHeightSpan implements LineHeightSpan, ReactSpan {
|
||||
|
||||
// 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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user