xamarin / Xamarin.Forms

Xamarin.Forms is no longer supported. Migrate your apps to .NET MAUI.
https://aka.ms/xamarin-upgrade
Other
5.62k stars 1.87k forks source link

[Bug] SearchButtonClicked never called on ios #12426

Open alihut opened 4 years ago

alihut commented 4 years ago

Description

Steps to Reproduce

I made a custom renderer for Xamarin.Forms SearchBar.

[assembly: ExportRenderer(typeof(SearchBar), typeof(SearchBarRendererForiOS))]

namespace SearchBarSample.iOS
{
    public class SearchBarRendererForiOS : SearchBarRenderer
    {

        protected override void OnElementChanged(ElementChangedEventArgs<Xamarin.Forms.SearchBar> e)
        {
            base.OnElementChanged(e);
           Control.ShowsBookmarkButton = true;
           Control.SearchButtonClicked += ControlOnSearchButtonClicked;
           Control.BookmarkButtonClicked += ControlOnBookmarkButtonClicked;
        }

        private void ControlOnBookmarkButtonClicked(object sender, EventArgs e)
        {
            ...
        }

        private void ControlOnSearchButtonClicked(object sender, EventArgs e)
        {
           ...
        }
    }
}

BookmarkButtonClicked event works just fine. But SearchButtonClicked event doesn't fire when I click to search button.

Expected Behavior

SearchButtonClicked event should fire.

Actual Behavior

SearchButtonClicked event doesn't fire.

Basic Information

Reproduction Link

https://gofile.io/d/V3CSr5

Workaround

GalaxiaGuy commented 4 years ago

This might be a bigger issue.

I tried the Xamarin Forms control gallery, and just using the default renderer for SearchBar, the SearchButtonClicked event didn't seem to fire (either directly in the renderer, or when using it on the cross-platform side).

Then I tried a plain Xamarin.iOS app and it seems SearchButtonClicked no longer fires at all.