maui icon indicating copy to clipboard operation
maui copied to clipboard

Allow SearchBar to take full width on Android

Open jfversluis opened this issue 2 years ago • 4 comments

Description of Change

By setting the MaxWidth to something big the SearchView can take full width. This is what I found being recommended in this case for Android. Don't necessarily like it, but other ways didn't seem to work. This makes the width consistent with how it was on Xamarin.Forms.

As a workaround you should be able to use this today:

#if ANDROID
Microsoft.Maui.Handlers.SearchBarHandler.Mapper.AppendToMapping("FullWidth", (handler, control) =>
{
	handler.PlatformView.MaxWidth = int.MaxValue;
});
#endif

You can put this code somewhere in the startup path of your app, doesn't really matter where.

Issues Fixed

Fixes #7137

jfversluis avatar Mar 06 '23 15:03 jfversluis

Little funny, is there a way to add a test?

mandel-macaque avatar Mar 08 '23 23:03 mandel-macaque

Out of curiosity, what were the other ways you tried that didn't work?

rachelkang avatar Mar 10 '23 17:03 rachelkang

Out of curiosity, what were the other ways you tried that didn't work?

It had to do with variations of trying to set the layout params here: https://github.com/dotnet/maui/pull/13716/files#diff-7c2aecd3476068af543aeee8e5ad243f007947dcff80ca09deb159d2ea4eb844R25-R29

If you have any more ideas, I'm open to it!

jfversluis avatar Mar 10 '23 18:03 jfversluis

Out of curiosity, what were the other ways you tried that didn't work?

It had to do with variations of trying to set the layout params here: https://github.com/dotnet/maui/pull/13716/files#diff-7c2aecd3476068af543aeee8e5ad243f007947dcff80ca09deb159d2ea4eb844R25-R29

If you have any more ideas, I'm open to it!

sorry, I missed this! gotcha - I think that makes sense (that editing that didn't seem to work) since that bit relates to the EditText (textinput area) of the searchBar, rather than the whole SearchBar itself. But hmm... were you able to figure out why there is this discrepancy between the default 0 vs. infinity MaxWidth? I think that would be most helpful.

As an idea, I wonder if rather than assigning max value, we can maybe get the width of the parent and have it set to that? Would that be better?

rachelkang avatar Mar 10 '23 21:03 rachelkang

Thank you for your pull request. We are auto-formatting your source code to follow our code guidelines.

github-actions[bot] avatar Apr 18 '23 09:04 github-actions[bot]

Suggesting backport, it seems like a small enough change and a customer is waiting on this. On the other hand: a workaround (that is essentially this code) is available through custom mappers.

jfversluis avatar Apr 19 '23 08:04 jfversluis