-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Modified the code changes and included UI test
- Loading branch information
1 parent
6fea74e
commit 181f706
Showing
4 changed files
with
148 additions
and
16 deletions.
There are no files selected for viewing
14 changes: 14 additions & 0 deletions
14
src/Controls/tests/TestCases.HostApp/Issues/Issue24977.xaml
This file contains 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,14 @@ | ||
<?xml version="1.0" encoding="utf-8" ?> | ||
<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui" | ||
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" | ||
x:Class="Maui.Controls.Sample.Issues.Issue24977" | ||
Title="Issue 24977"> | ||
|
||
<Grid RowDefinitions="50, 50, *, 50" Margin="30"> | ||
<Entry Text="Content before" AutomationId="EntryBefore" FontSize="Large" ReturnType="Next" BackgroundColor="Aquamarine" Grid.Row="0" /> | ||
<Label x:Name="CursorHeightTracker" Text="0" AutomationId="CursorHeightTracker" FontSize="Large" BackgroundColor="Aquamarine" Grid.Row="1" /> | ||
<Editor x:Name="editor" Text="Hello World!" AutomationId="IssueEditor" FontSize="Large" BackgroundColor="Orange" Grid.Row="2" VerticalTextAlignment="Center" TextChanged="Editor_TextChanged" /> | ||
<Button Text="Erase" Clicked="Button_Clicked" Grid.Row="3"/> | ||
</Grid> | ||
|
||
</ContentPage> |
71 changes: 71 additions & 0 deletions
71
src/Controls/tests/TestCases.HostApp/Issues/Issue24977.xaml.cs
This file contains 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,71 @@ | ||
using Microsoft.Maui.Platform; | ||
|
||
namespace Maui.Controls.Sample.Issues; | ||
|
||
[XamlCompilation(XamlCompilationOptions.Compile)] | ||
[Issue(IssueTracker.Github, 24977, "Keyboard Scrolling in editors with Center or End VerticalTextAlignment is off", PlatformAffected.iOS)] | ||
public partial class Issue24977 : ContentPage | ||
{ | ||
public Issue24977() | ||
{ | ||
InitializeComponent(); | ||
} | ||
|
||
private void Button_Clicked(object sender, EventArgs e) | ||
{ | ||
editor.Text = string.Empty; | ||
} | ||
|
||
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 | ||
} | ||
} |
57 changes: 57 additions & 0 deletions
57
src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Issue24977.cs
This file contains 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,57 @@ | ||
#if IOS | ||
using System.Drawing; | ||
using NUnit.Framework; | ||
using NUnit.Framework.Legacy; | ||
using OpenQA.Selenium.Appium.Interactions; | ||
using OpenQA.Selenium.Appium.MultiTouch; | ||
using OpenQA.Selenium.Interactions; | ||
using UITest.Appium; | ||
using UITest.Core; | ||
using System.Text; | ||
using OpenQA.Selenium; | ||
|
||
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() | ||
{ | ||
var app = App as AppiumApp; | ||
if (app is null) | ||
{ | ||
return; | ||
} | ||
|
||
var editorRect = app.WaitForElement("IssueEditor").GetRect(); | ||
app.Click("IssueEditor"); | ||
|
||
var sb = new StringBuilder(); | ||
for (int i = 1; i <= 15; 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); | ||
|
||
if (keyboardLocation is Point keyboardPoint) | ||
{ | ||
Assert.That(cursorHeight1 < keyboardPoint.Y); | ||
} | ||
else | ||
{ | ||
Assert.Fail("keyboardLocation is null"); | ||
} | ||
} | ||
} | ||
#endif |
This file contains 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