dotnet / maui

.NET MAUI is the .NET Multi-platform App UI, a framework for building native device applications spanning mobile, tablet, and desktop.
https://dot.net/maui
MIT License
22.14k stars 1.74k forks source link

Property in SearchBar control to Hide "Cancel" button on iOS while edit/text enter operation using MAUI handlers and Mappers #13780

Open muffadal53 opened 1 year ago

muffadal53 commented 1 year ago

Description

As per discussion on issue https://github.com/dotnet/maui/issues/13720 currently there is no property in MAUI SearchBar control to hide Cancel button on iOS. The way it was done in Xamarin Forms is using custom Renderer as below:

protected override void OnElementPropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
{
            base.OnElementPropertyChanged(sender, e);

            if (e.PropertyName == "Text")
            {
                Control.ShowsCancelButton = false;
            }
}

And to do it in MAUI currently as mentioned by @mattleibow we need to do as below:

#if IOS

            Microsoft.Maui.Handlers.SearchBarHandler.Mapper.AppendToMapping("CancelButtonColor", (handler, view) =>
            {
                handler.PlatformView.SetShowsCancelButton(false, false);
            });

#endif

Hence, it would be simple to have a property in SearchBar control to achieve the same.

Public API Changes

<SearchBar  ShowCancelButton="false"> // new API

Intended Use-Case

In iOS if we want to hide Cancel button for SearchBar is the intended use case. This was possible in Xamarin.Forms as mentioned above in description.

ghost commented 1 year ago

We've added this issue to our backlog, and we will work to address it as time and resources allow. If you have any additional information or questions about this issue, please leave a comment. For additional info about issue management, please read our Triage Process.

MNADEEMCH commented 1 year ago

need to remove background or I say BorderlessSearchbar is the any support for this? Please help

AlexanderVanMeerten commented 7 months ago

I vote for an AlwaysShowCancelButton (even when Text is empty).