diff --git a/src/Controls/src/Core/Compatibility/Handlers/Shell/iOS/SearchHandlerAppearanceTracker.cs b/src/Controls/src/Core/Compatibility/Handlers/Shell/iOS/SearchHandlerAppearanceTracker.cs index 3096d9eab8f4..827e03642f2e 100644 --- a/src/Controls/src/Core/Compatibility/Handlers/Shell/iOS/SearchHandlerAppearanceTracker.cs +++ b/src/Controls/src/Core/Compatibility/Handlers/Shell/iOS/SearchHandlerAppearanceTracker.cs @@ -40,7 +40,6 @@ public SearchHandlerAppearanceTracker(UISearchBar searchBar, SearchHandler searc _uiSearchBar.OnEditingStarted += OnEditingStarted; _uiSearchBar.OnEditingStopped += OnEditingEnded; _uiSearchBar.TextChanged += OnTextChanged; - _uiSearchBar.ShowsCancelButton = false; GetDefaultSearchBarColors(_uiSearchBar); var uiTextField = searchBar.FindDescendantView(); UpdateSearchBarColors(); diff --git a/src/Controls/tests/TestCases.Android.Tests/snapshots/android/ShouldAppearFlyoutIconAndContentPageTitle.png b/src/Controls/tests/TestCases.Android.Tests/snapshots/android/ShouldAppearFlyoutIconAndContentPageTitle.png new file mode 100644 index 000000000000..87613b9370f6 Binary files /dev/null and b/src/Controls/tests/TestCases.Android.Tests/snapshots/android/ShouldAppearFlyoutIconAndContentPageTitle.png differ diff --git a/src/Controls/tests/TestCases.HostApp/Issues/Issue22060.cs b/src/Controls/tests/TestCases.HostApp/Issues/Issue22060.cs new file mode 100644 index 000000000000..1395598b0f43 --- /dev/null +++ b/src/Controls/tests/TestCases.HostApp/Issues/Issue22060.cs @@ -0,0 +1,33 @@ +namespace Maui.Controls.Sample.Issues; + +[Issue(IssueTracker.Github, 22060, "Flyout icon and content page title disappeared after focusing on the search handler", PlatformAffected.iOS)] +public class Issue22060Shell : Shell +{ + public Issue22060Shell() + { + this.FlyoutBehavior = FlyoutBehavior.Flyout; + + var shellContent = new ShellContent + { + Title = "Home", + Route = "MainPage", + Content = new Issue22060() { Title = "Home" } + }; + + Items.Add(shellContent); + } + + class Issue22060 : ContentPage + { + public Issue22060() + { + Shell.SetSearchHandler(this, new SearchHandler + { + AutomationId = "searchHandler", + Placeholder = "SearchHandler", + }); + + this.SetBinding(TitleProperty, new Binding("Title", source: Shell.Current)); + } + } +} \ No newline at end of file diff --git a/src/Controls/tests/TestCases.Mac.Tests/snapshots/mac/ShouldAppearFlyoutIconAndContentPageTitle.png b/src/Controls/tests/TestCases.Mac.Tests/snapshots/mac/ShouldAppearFlyoutIconAndContentPageTitle.png new file mode 100644 index 000000000000..85ecd47d2efa Binary files /dev/null and b/src/Controls/tests/TestCases.Mac.Tests/snapshots/mac/ShouldAppearFlyoutIconAndContentPageTitle.png differ diff --git a/src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Issue22060.cs b/src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Issue22060.cs new file mode 100644 index 000000000000..81c6f2ccb355 --- /dev/null +++ b/src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Issue22060.cs @@ -0,0 +1,26 @@ +using NUnit.Framework; +using UITest.Appium; +using UITest.Core; + +namespace Microsoft.Maui.TestCases.Tests.Issues; + +public class Issue22060 : _IssuesUITest +{ + public override string Issue => "Flyout icon and content page title disappeared after focusing on the search handler"; + + public Issue22060(TestDevice device) : base(device) + { + } + + [Test] + [Category(UITestCategories.Shell)] + [Category(UITestCategories.SearchBar)] + public void ShouldAppearFlyoutIconAndContentPageTitle() + { + App.EnterTextInShellSearchHandler("Hello"); +#if IOS // When the search handler is focused, the Cancel button is displayed on the right side of the search bar only on the iOS platform. + App.Tap("Cancel"); +#endif + VerifyScreenshot(); + } +} \ No newline at end of file diff --git a/src/Controls/tests/TestCases.WinUI.Tests/snapshots/windows/ShouldAppearFlyoutIconAndContentPageTitle.png b/src/Controls/tests/TestCases.WinUI.Tests/snapshots/windows/ShouldAppearFlyoutIconAndContentPageTitle.png new file mode 100644 index 000000000000..56e3eb4a2b5a Binary files /dev/null and b/src/Controls/tests/TestCases.WinUI.Tests/snapshots/windows/ShouldAppearFlyoutIconAndContentPageTitle.png differ diff --git a/src/Controls/tests/TestCases.iOS.Tests/snapshots/ios/ShouldAppearFlyoutIconAndContentPageTitle.png b/src/Controls/tests/TestCases.iOS.Tests/snapshots/ios/ShouldAppearFlyoutIconAndContentPageTitle.png new file mode 100644 index 000000000000..25839e1bd540 Binary files /dev/null and b/src/Controls/tests/TestCases.iOS.Tests/snapshots/ios/ShouldAppearFlyoutIconAndContentPageTitle.png differ diff --git a/src/TestUtils/src/UITest.Appium/HelperExtensions.cs b/src/TestUtils/src/UITest.Appium/HelperExtensions.cs index 2f5c62d15e59..9796f9933c6c 100644 --- a/src/TestUtils/src/UITest.Appium/HelperExtensions.cs +++ b/src/TestUtils/src/UITest.Appium/HelperExtensions.cs @@ -2736,55 +2736,34 @@ public static bool IsElementVisible(IApp app, string elementName) } } - /// - /// Gets the display density for the current device using the appropriate platform-specific method. - /// For Android, uses the Appium getDisplayDensity command for accurate results. - /// For iOS and Catalyst, uses the deviceScreenInfo command. - /// For other platforms, falls back to driver capabilities. + /// Enters text into the search handler element for the shell. + /// This method is used to enter the search handler element in the app. + /// It uses different queries based on the app type (Android, iOS, Catalyst, or Windows). /// /// The IApp instance representing the application. - /// The display density as a double value (e.g., 1.0 for mdpi, 2.0 for xhdpi/Retina, 3.0 for xxhdpi/Retina HD) - public static double GetDisplayDensity(this IApp app) - { - if (app is not AppiumApp appiumApp) - { - throw new InvalidOperationException($"GetDisplayDensity is only supported on AppiumApp"); - } - - // Use platform-specific methods for accurate results - return app switch - { - AppiumAndroidApp androidApp => GetAndroidDisplayDensity(androidApp), - AppiumIOSApp iOSApp => GetIOSDisplayDensity(iOSApp), - _ => 1.0 // Fallback for other platforms (Catalyst, Windows) - }; - } - - static double GetAndroidDisplayDensity(AppiumAndroidApp androidApp) + /// The search handler element for the shell. + public static void EnterTextInShellSearchHandler(this IApp app, string text) { - // Use the command executor to call the Android-specific action - float? response = (androidApp.Driver as AndroidDriver)?.GetDisplayDensity(); - if (response is not null) + if (app is AppiumWindowsApp) { - return (double)response.Value / 160f; + app.WaitForElement("TextBox"); + app.EnterText("TextBox", text); } - - return 1.0; - } - - static double GetIOSDisplayDensity(AppiumIOSApp iOSApp) - { - var response = (iOSApp.Driver as IOSDriver)?.ExecuteScript("mobile: deviceScreenInfo"); - if (response is not null && response is IDictionary screenInfo) + else if (app is AppiumIOSApp || app is AppiumCatalystApp || app is AppiumAndroidApp) { - // Extract the scale factor from the deviceScreenInfo response - if (screenInfo.TryGetValue("scale", out var scaleValue)) + IQuery query; + if (app is AppiumAndroidApp) { - return Convert.ToDouble(scaleValue); + query = AppiumQuery.ByXPath("//android.widget.EditText"); + } + else + { + query = AppiumQuery.ByXPath("//XCUIElementTypeSearchField"); } - } - return 1.0; + app.WaitForElement(query); + app.EnterText(query, text); + } } } } \ No newline at end of file