Skip to content

SearchBar: Inconsistent behavior (Keyboard and Properties) in iOS and Android #9092

@jbizcloud

Description

@jbizcloud

Description

  • <SearchBar> does not show the proper Keyboard setting. It can display the proper Keyboard after attaching a Renderer.
  • <CustomSearchBar> control does not inherit all Properties from <SearchBar> in iOS.
Topic Description XAML C# iOS Android
Keyboard not showing <SearchBar> does not show the proper Keyboard setting. <SearchBar Placeholder="Search - Native" Keyboard="Numeric" /> n/a Keyboard not correct. Should be a Numeric type.
Screen Shot 2022-07-30 at 1 53 48 PM
Keyboard not correct. Should be a Numeric type.
Screen Shot 2022-07-30 at 1 53 06 PM
(Workaround-ish) Keyboard showing but cannot write in iOS <SearchBar> shows the proper Keyboard setting when attaching a Renderer. (same as above) [below] Cannot type and Placeholder is already NOT visible.
Screen Shot 2022-07-30 at 1 58 01 PM
Can type
Screen Shot 2022-07-30 at 1 56 30 PM
A custom control based on SearchBar w/ Renderer Keyboard will show but properties are lost in OS. Cannot type in iOS. Note that without renderer, Keyboard setting setting does not work in iOS nor Android <components:CustomSearchBar Placeholder="Search - Custom control" Keyboard="Numeric" /> [below] Screen Shot 2022-07-30 at 2 09 00 PM Same as above. Without a renderer, the Keyboard setting does not work.

Renderers

  • iOS
namespace MauiBlazor.Platforms.iOS.Renderers
{
    public class AcDaSearchBarRenderer : SearchBarRenderer
    {
        public AcDaSearchBarRenderer() : base()
        {
        }

        protected override void OnElementChanged(ElementChangedEventArgs<SearchBar> e)
        {
            base.OnElementChanged(e);
        }
    }
}
  • Android
namespace MauiBlazor.Platforms.Android.Renderers
{
    public class AcDaSearchBarRenderer : SearchBarRenderer
    {
        public AcDaSearchBarRenderer(Context context) : base(context)
        {
        }

        protected override void OnElementChanged(ElementChangedEventArgs<SearchBar> e)
        {
            base.OnElementChanged(e);
        }
    }
}

MauiProgram.cs

        var builder = MauiApp.CreateBuilder();
        builder
            .UseMauiApp<App>()
            .ConfigureFonts(fonts =>
            {
                fonts.AddFont("OpenSans-Regular.ttf", "OpenSansRegular");
            })
             .UseMauiCompatibility()
            .ConfigureMauiHandlers(handlers =>
            {
#if ANDROID
                //                handlers.AddCompatibilityRenderer<CustomSearchBar,MauiBlazor.Platforms.Android.Renderers.AcDaSearchBarRenderer>();
                handlers.AddCompatibilityRenderer<SearchBar,MauiBlazor.Platforms.Android.Renderers.AcDaSearchBarRenderer>();

#endif

#if IOS
//                handlers.AddCompatibilityRenderer<CustomSearchBar,MauiBlazor.Platforms.iOS.Renderers.AcDaSearchBarRenderer>();
               handlers.AddCompatibilityRenderer<SearchBar,MauiBlazor.Platforms.iOS.Renderers.AcDaSearchBarRenderer>();


#endif

            });

CustomSearchBar

public class CustomSearchBar : SearchBar
    {
        public CustomSearchBar() : base()
        {

        }
    }

Steps to Reproduce

  1. Create a MAUI project with /Blazor.
  2. Add a SearchBar to any XAML page. Set Keyboard to Numeric.
  3. Expect the behaviors shown in the table above.

Version with bug

6.0.400

Last version that worked well

Unknown/Other

Affected platforms

iOS

Affected platform versions

iOS

Did you find any workaround?

Yes but partial workarounds. Above in table.

Relevant log output

n/a

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions