maui
maui copied to clipboard
Allow SearchBar to take full width on Android
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
Little funny, is there a way to add a test?
Out of curiosity, what were the other ways you tried that didn't work?
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!
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?
Thank you for your pull request. We are auto-formatting your source code to follow our code guidelines.
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.