-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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
Fixed Keyboard Scrolling in editors with Center or End VerticalTextAlignment #25827
base: main
Are you sure you want to change the base?
Conversation
/azp run |
Azure Pipelines successfully started running 3 pipeline(s). |
/rebase |
36adb36
to
025744d
Compare
/azp run |
Azure Pipelines successfully started running 3 pipeline(s). |
/rebase |
025744d
to
6fea74e
Compare
/azp run |
Azure Pipelines successfully started running 3 pipeline(s). |
/azp run |
Azure Pipelines successfully started running 3 pipeline(s). |
{ | ||
var contentHeight = ContentSize.Height; | ||
var contentHeight = ContentSize.Height - TextContainerInset.Top - TextContainerInset.Bottom; | ||
var availableSpace = Bounds.Height - contentHeight * ZoomScale; | ||
if (availableSpace <= 0) | ||
return; | ||
ContentOffset = VerticalTextAlignment switch | ||
|
||
TextContainerInset = VerticalTextAlignment switch | ||
{ | ||
Maui.TextAlignment.Center => new CGPoint(0, -Math.Max(1, availableSpace / 2)), | ||
Maui.TextAlignment.End => new CGPoint(0, -Math.Max(1, availableSpace)), | ||
_ => ContentOffset, | ||
Maui.TextAlignment.Center => new UIEdgeInsets((nfloat)Math.Max(1, availableSpace / 2), TextContainerInset.Left, TextContainerInset.Bottom, TextContainerInset.Right), | ||
Maui.TextAlignment.End => new UIEdgeInsets((nfloat)Math.Max(1, availableSpace), TextContainerInset.Left, TextContainerInset.Bottom, TextContainerInset.Right), | ||
_ => TextContainerInset, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So it looks like the failing tests aren't just from the placeholder, but the spacing is just not correct and not accounting for the bottom of the TextContainerInset correctly. The following gets us closer and seems like the middle adjustment is a rounding issue perhaps. Can you look into this?
void ShouldCenterVertically()
{
// ContentSize.Height rounds to the nearest whole number so to keep the measurements consistent we round the adjustment as well
var contentHeight = ContentSize.Height - Math.Round(TextContainerInset.Top, MidpointRounding.AwayFromZero);;
var availableSpace = Bounds.Height - contentHeight * ZoomScale;
if (availableSpace <= 0)
return;
TextContainerInset = VerticalTextAlignment switch
{
Maui.TextAlignment.Center => new UIEdgeInsets((nfloat)Math.Max(1, availableSpace / 2), TextContainerInset.Left, TextContainerInset.Bottom, TextContainerInset.Right),
Maui.TextAlignment.End => new UIEdgeInsets((nfloat)Math.Max(1, availableSpace), TextContainerInset.Left, TextContainerInset.Bottom, TextContainerInset.Right),
_ => TextContainerInset,
};
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@jsuarezruiz , EditorPlaceholderPosition is the test case related to this PR. The other test cases are unrelated, as this PR contains code changes for UITextView, and the remaining test cases do not involve an editor in their scenarios. To confirm, I ran both test cases locally, and they passed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@tj-devel709 , The rounding approach for middle alignment does not resolve the issue. I attempted to recalculate the position when the text alignment is set to center. Using this approach, we obtained the correct value, which is 66.25. This value is required for the test case to pass; however, the test still fails, even though the top inset value is set to 66.25.
void ShouldCenterVertically()
{
// ContentSize.Height rounds to the nearest whole number so to keep the measurements consistent we round the adjustment as well
var contentHeight = ContentSize.Height - Math.Round(TextContainerInset.Top, MidpointRounding.AwayFromZero);
var availableSpace = Bounds.Height - contentHeight * ZoomScale;
if (availableSpace <= 0)
return;
TextContainerInset = VerticalTextAlignment switch
{
Maui.TextAlignment.Center => new UIEdgeInsets((nfloat)Math.Max(1,(Bounds.Height - (ContentSize.Height - (TextContainerInset.Top + TextContainerInset.Bottom)) * ZoomScale) / 2), TextContainerInset.Left, TextContainerInset.Bottom, TextContainerInset.Right),
Maui.TextAlignment.End => new UIEdgeInsets((nfloat)Math.Max(1, availableSpace), TextContainerInset.Left, TextContainerInset.Bottom, TextContainerInset.Right),
_ => TextContainerInset,
};
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Huh.. that looks pretty close so I'm not sure what is off here. It looks like maybe its just off by a fraction of a pixel or something like that. @PureWeen, what do you think? Good enough?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@PureWeen, can you please share your thoughts on this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/rebase |
9393e16
to
ffa07cc
Compare
/azp run |
Azure Pipelines successfully started running 3 pipeline(s). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thoughts on this difference?
If I comment out the code setting the TextContainerInset
you get the typical iOS bounce when scrolling
Commenting out code that sets TextContainerInset
WithBounce.mov
This PR
Wobbly.mov
Yeah that is a weird behavior... Not sure what to immediately make of it other than the first behavior seems like the expected |
Issue Details
Sometimes, the editor cursor moves below the keyboard frame, causing it to render incorrectly. Once the editor content exceeds the editor's size, the cursor aligns properly above the keyboard frame.
Root Cause
The content offset of UITextView is set without consideration of keyboard frame. Causing the content to remain center even when the keyboard is open. As a result, the cursor goes below the keyboard frame.
Description of Change
The content offset of UITextView should be recalculated based on the keyboard frame value . We should check if the cursor's bottom position goes below the keyboard; we have to update the y position of the content offset based on the difference between the cursor's bottom position and the keyboard frame's top position.
Validated the behaviour in the following platforms
Issues Fixed
Fixes #24977
Output
Before.mov
After.mov