fix: properly take padding into consideration for selection events on Android #774
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
📜 Description
Correctly handling padding for selection events, especially when it's different (comparing top/bottom).
💡 Motivation and Context
If you apply different
paddingTop
/paddingBottom
, then you will notice, that selection coordinates are not reporting expected values. It happens because of the fact, that we need to take padding into consideration, when we calculate relative text position inside input.For different gravity we need to use different formulas:
And after that we need to add
lineHeight / 2
(because otherwise caret will be in the middle of the text,To understand the problem try various combinations of
paddingTop=60
/paddingBottom=20
/textAlignVertical="top|center|bottom"
(reverse paddings as well).You'll see, how it produces different values. With this PR in place we always will get the same relative position (blue box will always follow a carret).
📢 Changelog
Android
lineHeight / 2
to final vertical offset.🤔 How Has This Been Tested?
Tested on Medium Phone API 35.
📸 Screenshots (if appropriate):
📝 Checklist