[Android] Fix for Entry SelectionLength (#24064)

* fix-18443-SelectionLength Property Not Applied to Entry at Runtime

* Added UI test for 18443

* Modified the test case

* Modified test file

* Modified TestCases.Shared.Tests/Tests/Issues/Issue18443.cs

* Modified test file

* Modified test case

* Added image for Entry test
This commit is contained in:
NirmalKumarYuvaraj 2024-08-23 21:04:11 +05:30 коммит произвёл GitHub
Родитель 2aca52006a
Коммит ebf760463b
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: B5690EEEBB952194
5 изменённых файлов: 64 добавлений и 1 удалений

Двоичный файл не отображается.

После

Ширина:  |  Высота:  |  Размер: 86 KiB

Просмотреть файл

@ -0,0 +1,8 @@
<?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.Issue18443">
<Entry AutomationId="entry" x:Name="MauiEntry" Text="Microsoft Maui Entry" SelectionLength="5" HeightRequest="75"></Entry>
</ContentPage>

Просмотреть файл

@ -0,0 +1,21 @@
namespace Maui.Controls.Sample.Issues
{
[XamlCompilation(XamlCompilationOptions.Compile)]
[Issue(IssueTracker.Github, 18443, "SelectionLength Property Not Applied to Entry at Runtime", PlatformAffected.Android)]
public partial class Issue18443 : ContentPage
{
public Issue18443()
{
InitializeComponent();
}
protected override async void OnAppearing()
{
base.OnAppearing();
await Task.Delay(1000);
MauiEntry.Focus();
}
}
}

Просмотреть файл

@ -0,0 +1,23 @@
#if ANDROID
using NUnit.Framework;
using UITest.Appium;
using UITest.Core;
namespace Microsoft.Maui.TestCases.Tests.Issues
{
public class Issue18443 : _IssuesUITest
{
public Issue18443(TestDevice device) : base(device) { }
public override string Issue => "SelectionLength Property Not Applied to Entry at Runtime";
[Test]
[Category(UITestCategories.Entry)]
public void EntrySelectionLengthRuntimeUpdate()
{
App.WaitForElement("entry");
VerifyScreenshot();
}
}
}
#endif

Просмотреть файл

@ -42,6 +42,7 @@ namespace Microsoft.Maui.Handlers
// TODO: NET8 issoto - Change the return type to MauiAppCompatEditText
protected override void ConnectHandler(AppCompatEditText platformView)
{
platformView.ViewAttachedToWindow += OnPlatformViewAttachedToWindow;
platformView.TextChanged += OnTextChanged;
platformView.FocusChange += OnFocusedChange;
platformView.Touch += OnTouch;
@ -52,7 +53,7 @@ namespace Microsoft.Maui.Handlers
protected override void DisconnectHandler(AppCompatEditText platformView)
{
_clearButtonDrawable = null;
platformView.ViewAttachedToWindow -= OnPlatformViewAttachedToWindow;
platformView.TextChanged -= OnTextChanged;
platformView.FocusChange -= OnFocusedChange;
platformView.Touch -= OnTouch;
@ -146,6 +147,16 @@ namespace Microsoft.Maui.Handlers
handler.PlatformView.Focus(request);
}
void OnPlatformViewAttachedToWindow(object? sender, ViewAttachedToWindowEventArgs e)
{
if (PlatformView.IsAlive() && PlatformView.Enabled)
{
// https://issuetracker.google.com/issues/37095917
PlatformView.Enabled = false;
PlatformView.Enabled = true;
}
}
void OnTextChanged(object? sender, TextChangedEventArgs e)
{
if (VirtualView == null)