-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Fixed Keyboard Scrolling in editors with Center or End VerticalTextAlignment #25827
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
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.
What is zoom scale? Could that be a fraction and thus contributing some increased offset? What happens if you remove the rounding and then diff before and after? I onder if that would be closer indicating it is just the rounding and zoom.
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.
I see this code is entirely gone, so I suppose this question is not relevant. @karthikraja-arumugam ?
jsuarezruiz
left a comment
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.
ba7fb6c to
a752049
Compare
|
/azp run |
|
Azure Pipelines successfully started running 3 pipeline(s). |
…ignment (#25827) * Fixed Keyboard scrolling in editors with Center or end VerticalTextAlignment is off * Modified the code change to consider content offset value * Removed unwanted file changes * Removed test cases * Modified changes * Modified the code changes and included UI test * Removed unwanted code changes * updated changes * optimized changes * updated test case * Added a button for Start * Changes in MauiTextView --------- Co-authored-by: Matthew Leibowitz <[email protected]> Co-authored-by: Dhivya-SF4094 <[email protected]>
…ignment (#25827) * Fixed Keyboard scrolling in editors with Center or end VerticalTextAlignment is off * Modified the code change to consider content offset value * Removed unwanted file changes * Removed test cases * Modified changes * Modified the code changes and included UI test * Removed unwanted code changes * updated changes * optimized changes * updated test case * Added a button for Start * Changes in MauiTextView --------- Co-authored-by: Matthew Leibowitz <[email protected]> Co-authored-by: Dhivya-SF4094 <[email protected]>
…ignment (#25827) * Fixed Keyboard scrolling in editors with Center or end VerticalTextAlignment is off * Modified the code change to consider content offset value * Removed unwanted file changes * Removed test cases * Modified changes * Modified the code changes and included UI test * Removed unwanted code changes * updated changes * optimized changes * updated test case * Added a button for Start * Changes in MauiTextView --------- Co-authored-by: Matthew Leibowitz <[email protected]> Co-authored-by: Dhivya-SF4094 <[email protected]>
…ignment (#25827) * Fixed Keyboard scrolling in editors with Center or end VerticalTextAlignment is off * Modified the code change to consider content offset value * Removed unwanted file changes * Removed test cases * Modified changes * Modified the code changes and included UI test * Removed unwanted code changes * updated changes * optimized changes * updated test case * Added a button for Start * Changes in MauiTextView --------- Co-authored-by: Matthew Leibowitz <[email protected]> Co-authored-by: Dhivya-SF4094 <[email protected]>
…ignment (#25827) * Fixed Keyboard scrolling in editors with Center or end VerticalTextAlignment is off * Modified the code change to consider content offset value * Removed unwanted file changes * Removed test cases * Modified changes * Modified the code changes and included UI test * Removed unwanted code changes * updated changes * optimized changes * updated test case * Added a button for Start * Changes in MauiTextView --------- Co-authored-by: Matthew Leibowitz <[email protected]> Co-authored-by: Dhivya-SF4094 <[email protected]>
…ignment (dotnet#25827) * Fixed Keyboard scrolling in editors with Center or end VerticalTextAlignment is off * Modified the code change to consider content offset value * Removed unwanted file changes * Removed test cases * Modified changes * Modified the code changes and included UI test * Removed unwanted code changes * updated changes * optimized changes * updated test case * Added a button for Start * Changes in MauiTextView --------- Co-authored-by: Matthew Leibowitz <[email protected]> Co-authored-by: Dhivya-SF4094 <[email protected]>
…ignment (#25827) * Fixed Keyboard scrolling in editors with Center or end VerticalTextAlignment is off * Modified the code change to consider content offset value * Removed unwanted file changes * Removed test cases * Modified changes * Modified the code changes and included UI test * Removed unwanted code changes * updated changes * optimized changes * updated test case * Added a button for Start * Changes in MauiTextView --------- Co-authored-by: Matthew Leibowitz <[email protected]> Co-authored-by: Dhivya-SF4094 <[email protected]>
…ignment (#25827) * Fixed Keyboard scrolling in editors with Center or end VerticalTextAlignment is off * Modified the code change to consider content offset value * Removed unwanted file changes * Removed test cases * Modified changes * Modified the code changes and included UI test * Removed unwanted code changes * updated changes * optimized changes * updated test case * Added a button for Start * Changes in MauiTextView --------- Co-authored-by: Matthew Leibowitz <[email protected]> Co-authored-by: Dhivya-SF4094 <[email protected]>
…ignment (#25827) * Fixed Keyboard scrolling in editors with Center or end VerticalTextAlignment is off * Modified the code change to consider content offset value * Removed unwanted file changes * Removed test cases * Modified changes * Modified the code changes and included UI test * Removed unwanted code changes * updated changes * optimized changes * updated test case * Added a button for Start * Changes in MauiTextView --------- Co-authored-by: Matthew Leibowitz <[email protected]> Co-authored-by: Dhivya-SF4094 <[email protected]>
…ignment (#25827) * Fixed Keyboard scrolling in editors with Center or end VerticalTextAlignment is off * Modified the code change to consider content offset value * Removed unwanted file changes * Removed test cases * Modified changes * Modified the code changes and included UI test * Removed unwanted code changes * updated changes * optimized changes * updated test case * Added a button for Start * Changes in MauiTextView --------- Co-authored-by: Matthew Leibowitz <[email protected]> Co-authored-by: Dhivya-SF4094 <[email protected]>





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