-
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
Merged
PureWeen
merged 12 commits into
dotnet:inflight/current
from
NirmalKumarYuvaraj:fix-24977
Mar 23, 2025
+234
−1
Merged
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
38aa55f
Fixed Keyboard scrolling in editors with Center or end VerticalTextAl…
NirmalKumarYuvaraj 8f85aab
Modified the code change to consider content offset value
NirmalKumarYuvaraj 13cc657
Removed unwanted file changes
NirmalKumarYuvaraj 407cf09
Removed test cases
NirmalKumarYuvaraj cfe48bf
Modified changes
NirmalKumarYuvaraj d7057af
Modified the code changes and included UI test
NirmalKumarYuvaraj 3b44aeb
Removed unwanted code changes
NirmalKumarYuvaraj c6011a2
updated changes
NirmalKumarYuvaraj 223035f
optimized changes
NirmalKumarYuvaraj a6bb549
updated test case
NirmalKumarYuvaraj dae3894
Added a button for Start
mattleibow a752049
Changes in MauiTextView
Dhivya-SF4094 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
146 changes: 146 additions & 0 deletions
146
src/Controls/tests/TestCases.HostApp/Issues/Issue24977.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,146 @@ | ||
| namespace Maui.Controls.Sample.Issues; | ||
|
|
||
| [Issue(IssueTracker.Github, 24977, "Keyboard Scrolling in editors with Center or End VerticalTextAlignment is off", PlatformAffected.iOS)] | ||
| public class Issue24977 : TestNavigationPage | ||
| { | ||
| protected override void Init() | ||
| { | ||
| PushAsync(new ContentPage | ||
| { | ||
| Content = new VerticalStackLayout | ||
| { | ||
| Spacing = 12, | ||
| Padding = new Thickness(12, 24), | ||
| Children = | ||
| { | ||
| CreateButton(TextAlignment.Start), | ||
| CreateButton(TextAlignment.Center), | ||
| CreateButton(TextAlignment.End), | ||
| } | ||
| } | ||
| }); | ||
| } | ||
|
|
||
| Button CreateButton(TextAlignment textAlignment) | ||
| { | ||
| var btn = new Button | ||
| { | ||
| Text = textAlignment.ToString(), | ||
| AutomationId = $"{textAlignment}Button" | ||
| }; | ||
| btn.Clicked += (s, e) => Navigation.PushAsync(new Issue24977_1(textAlignment)); | ||
| return btn; | ||
| } | ||
| } | ||
|
|
||
| public class Issue24977_1 : TestContentPage | ||
| { | ||
| Editor editor; | ||
| Label cursorHeightTracker; | ||
|
|
||
| public Issue24977_1(TextAlignment textAlignment) | ||
| { | ||
| editor.VerticalTextAlignment = textAlignment; | ||
| } | ||
|
|
||
| protected override void Init() | ||
| { | ||
| var rootGrid = new Grid | ||
| { | ||
| RowDefinitions = | ||
| { | ||
| new RowDefinition { Height = 50 }, | ||
| new RowDefinition { Height = 50 }, | ||
| new RowDefinition { Height = new GridLength(1, GridUnitType.Star) }, | ||
| new RowDefinition { Height = 50 } | ||
| }, | ||
| Margin = new Thickness(30) | ||
| }; | ||
|
|
||
| var entry = new Entry | ||
| { | ||
| Text = "Content before", | ||
| AutomationId = "EntryBefore", | ||
| ReturnType = ReturnType.Next, | ||
| BackgroundColor = Colors.Aquamarine, | ||
| }; | ||
|
|
||
| cursorHeightTracker = new Label | ||
| { | ||
| Text = "0", | ||
| AutomationId = "CursorHeightTracker", | ||
| BackgroundColor = Colors.Aquamarine, | ||
| }; | ||
|
|
||
| editor = new Editor | ||
| { | ||
| Text = "Hello World!", | ||
| AutomationId = "IssueEditor", | ||
| BackgroundColor = Colors.Orange, | ||
| }; | ||
| editor.TextChanged += Editor_TextChanged; | ||
|
|
||
| var button = new Button { Text = "Erase" }; | ||
| button.Clicked += (s, e) => editor.Text = string.Empty; | ||
|
|
||
| rootGrid.Add(entry, 0, 0); | ||
| rootGrid.Add(cursorHeightTracker, 0, 1); | ||
| rootGrid.Add(editor, 0, 2); | ||
|
|
||
| rootGrid.Add(button, 0, 3); | ||
|
|
||
| Content = rootGrid; | ||
| } | ||
|
|
||
| private void Editor_TextChanged(object sender, TextChangedEventArgs e) | ||
| { | ||
| if (sender is Editor editor) | ||
| { | ||
| AddCursorHeightToLabel(editor); | ||
| } | ||
| } | ||
|
|
||
| void AddCursorHeightToLabel(Editor editor) | ||
| { | ||
| #if IOS | ||
| var textInput = editor.Handler.PlatformView as UIKit.UITextView; | ||
| var selectedTextRange = textInput?.SelectedTextRange; | ||
| var localCursor = selectedTextRange is not null ? textInput?.GetCaretRectForPosition(selectedTextRange.Start) : null; | ||
|
|
||
| if (localCursor is CoreGraphics.CGRect local && textInput is not null) | ||
| { | ||
| var container = GetContainerView(textInput); | ||
| var cursorInContainer = container.ConvertRectFromView(local, textInput); | ||
| var cursorInWindow = container.ConvertRectToView(cursorInContainer, null); | ||
|
|
||
| cursorHeightTracker.Text = cursorInWindow.Y.ToString(); | ||
| } | ||
|
|
||
| UIKit.UIView GetContainerView(UIKit.UIView startingPoint) | ||
| { | ||
| var rootView = FindResponder<Microsoft.Maui.Platform.ContainerViewController>(startingPoint)?.View; | ||
|
|
||
| if (rootView is not null) | ||
| { | ||
| return rootView; | ||
| } | ||
|
|
||
| return null; | ||
| } | ||
|
|
||
| T FindResponder<T>(UIKit.UIView view) | ||
| where T : UIKit.UIResponder | ||
| { | ||
| var nextResponder = view as UIKit.UIResponder; | ||
| while (nextResponder is not null) | ||
| { | ||
| nextResponder = nextResponder.NextResponder; | ||
|
|
||
| if (nextResponder is T responder) | ||
| return responder; | ||
| } | ||
| return null; | ||
| } | ||
| #endif | ||
| } | ||
| } |
74 changes: 74 additions & 0 deletions
74
src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Issue24977.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,74 @@ | ||
| #if IOS | ||
| using System.Drawing; | ||
| using NUnit.Framework; | ||
| using UITest.Appium; | ||
| using UITest.Core; | ||
| using System.Text; | ||
|
|
||
| namespace Microsoft.Maui.TestCases.Tests.Issues; | ||
| public class Issue24977 : _IssuesUITest | ||
| { | ||
| public Issue24977(TestDevice device) : base(device) { } | ||
|
|
||
| public override string Issue => "Keyboard Scrolling in editors with Center or End VerticalTextAlignment is off"; | ||
|
|
||
| [Test] | ||
| [Category(UITestCategories.Editor)] | ||
| public void KeepEditorCursorAboveKeyboardWithVerticalAlignmentAsCenter() | ||
| { | ||
| TestKeepEditorCursorAboveKeyboard("CenterButton", true); | ||
| } | ||
|
|
||
| [Test] | ||
| [Category(UITestCategories.Editor)] | ||
| public void KeepEditorCursorAboveKeyboardWithVerticalAlignmentAsEnd() | ||
| { | ||
| TestKeepEditorCursorAboveKeyboard("EndButton"); | ||
| } | ||
|
|
||
| void TestKeepEditorCursorAboveKeyboard(string buttonId, bool fromCenter = false) | ||
| { | ||
| App.WaitForElement(buttonId); | ||
| App.Tap(buttonId); | ||
| Thread.Sleep(1000); | ||
|
|
||
| var app = App as AppiumApp; | ||
| if (app == null) | ||
| return; | ||
|
|
||
| var editorRect = app.WaitForElement("IssueEditor").GetRect(); | ||
| app.Click("IssueEditor"); | ||
|
|
||
| var sb = new StringBuilder(); | ||
| for (int i = 1; i <= 20; i++) | ||
| { | ||
| sb.Append($"\n{i}"); | ||
| } | ||
|
|
||
| app.EnterText("IssueEditor", sb.ToString()); | ||
|
|
||
| var keyboardLocation = KeyboardScrolling.FindiOSKeyboardLocation(app.Driver); | ||
|
|
||
| var cursorLabel = app.WaitForElement("CursorHeightTracker").GetText(); | ||
| var cursorHeight1 = Convert.ToDouble(cursorLabel); | ||
| try | ||
| { | ||
| if (keyboardLocation is Point keyboardPoint) | ||
| { | ||
| Assert.That(cursorHeight1 < keyboardPoint.Y); | ||
| } | ||
| else | ||
| { | ||
| Assert.Fail("keyboardLocation is null"); | ||
| } | ||
| } | ||
| finally | ||
| { | ||
| if (fromCenter) | ||
| { | ||
| App.Back(); | ||
| } | ||
| } | ||
| } | ||
| } | ||
| #endif |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.