Skip to content
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

Light up HideSoftInputOnTappedChanged for catalyst #21529

Merged
merged 5 commits into from
Apr 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
#if ANDROID || (IOS && !MACCATALYST)
// This behavior isn't lit up for WinUI because it's never been supported on WinUI, event in Xamarin.Forms
// The primary purpose of this API is for XF migration purposes.
// Ideally users would use behavior that's more accessible forward and consistent with platform expectations.
#if ANDROID || IOS
using System;
using System.Collections.Generic;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ bool FeatureEnabled
}
}

#if !(ANDROID || (IOS && !MACCATALYST))
#if !(ANDROID || IOS)
internal void UpdateFocusForView(InputView iv)
{

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,46 @@ public void HideSoftInputOnTappedPageTest(string control, bool hideOnTapped)
{
this.IgnoreIfPlatforms(new[]
{
TestDevice.Mac, TestDevice.Windows
TestDevice.Windows
});

App.WaitForElement("HideSoftInputOnTappedTrue");

if (this.Device == TestDevice.Mac)
{
HideSoftInputOnTappedPageTestForMac(control, hideOnTapped);
}
else
{
HideSoftInputOnTappedPageTestForAndroidiOS(control, hideOnTapped);
}
}

void HideSoftInputOnTappedPageTestForMac(string control, bool hideOnTapped)
{
try
{
if (hideOnTapped)
App.Click("HideSoftInputOnTappedTrue");
else
App.Click("HideSoftInputOnTappedFalse");

App.WaitForElement(control);
App.Click(control);

Assert.IsTrue(App.IsFocused(control));

App.Click("EmptySpace");
Assert.AreEqual(!hideOnTapped, App.IsFocused(control));
}
finally
{
this.Back();
}
}

void HideSoftInputOnTappedPageTestForAndroidiOS(string control, bool hideOnTapped)
{
try
{
if (App.IsKeyboardShown())
Expand Down Expand Up @@ -52,9 +89,49 @@ public void TogglingHideSoftInputOnTapped()
{
this.IgnoreIfPlatforms(new[]
{
TestDevice.Mac, TestDevice.Windows
TestDevice.Windows
});

App.WaitForElement("HideSoftInputOnTappedFalse");

if (this.Device == TestDevice.Mac)
{
TogglingHideSoftInputOnTappedForMac();
}
else
{
TogglingHideSoftInputOnTappedForAndroidiOS();
}
}

public void TogglingHideSoftInputOnTappedForMac()
{
try
{
App.Click("HideSoftInputOnTappedFalse");

// Switch between enabling/disabling feature
for (int i = 0; i < 2; i++)
{
App.Click("HideKeyboardWhenTappingPage");
Assert.True(App.IsFocused("HideKeyboardWhenTappingPage"));
App.Click("EmptySpace");
Assert.AreEqual(false, App.IsFocused("HideKeyboardWhenTappingPage"));

App.Click("DontHideKeyboardWhenTappingPage");
Assert.True(App.IsFocused("DontHideKeyboardWhenTappingPage"));
App.Click("EmptySpace");
Assert.AreEqual(true, App.IsFocused("DontHideKeyboardWhenTappingPage"));
}
}
finally
{
this.Back();
}
}

public void TogglingHideSoftInputOnTappedForAndroidiOS()
{
try
{
if (App.IsKeyboardShown())
Expand Down
10 changes: 10 additions & 0 deletions src/TestUtils/src/UITest.Appium/HelperExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System.Collections.Immutable;
using System.Diagnostics;
using System.Drawing;
using OpenQA.Selenium.Appium;
using OpenQA.Selenium.Appium.Interfaces;
using UITest.Core;

Expand Down Expand Up @@ -603,6 +604,15 @@ public static bool IsFocused(this IApp app, string id)
var activeElement = aaa.Driver.SwitchTo().ActiveElement();
var element = (AppiumDriverElement)app.WaitForElement(id);

if (app.GetTestDevice() == TestDevice.Mac && activeElement is AppiumElement activeAppiumElement)
{
// For some reason on catalyst the ActiveElement returns an AppiumElement with a different id
// The TagName (AutomationId) and the location all match, so, other than the Id it walks and talks
// like the same element
return element.AppiumElement.TagName.Equals(activeAppiumElement.TagName, StringComparison.OrdinalIgnoreCase) &&
element.AppiumElement.Location.Equals(activeAppiumElement.Location);
}

return element.AppiumElement.Equals(activeElement);
}

Expand Down
Loading