Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SearchBar not expanding horizontally #10823

Closed
owl-guy opened this issue Oct 21, 2022 · 20 comments
Closed

SearchBar not expanding horizontally #10823

owl-guy opened this issue Oct 21, 2022 · 20 comments
Labels
area-controls-entry Entry area-layout StackLayout, GridLayout, ScrollView, ContentView, AbsoluteLayout, FlexLayout, ContentPresenter platform/windows 🪟 s/triaged Issue has been reviewed s/verified Verified / Reproducible Issue ready for Engineering Triage t/bug Something isn't working
Milestone

Comments

@owl-guy
Copy link

owl-guy commented Oct 21, 2022

Description

image
image
As can be seen, the SearchBar does not expand to fit its parent.

Steps to Reproduce

  1. Create a new .NET MAUI project
  2. Add a SearchBar, either directly on the ContentPage or inside a Layout
  3. The SearchBar will not adjust its size when no width is specified

Link to public reproduction project repository

https://github.com/owl-guy/SearchBarExample

Version with bug

Unknown/Other (please specify)

Last version that worked well

Unknown/Other

Affected platforms

Android

Affected platform versions

Android 11 and up

Did you find any workaround?

No response

Relevant log output

No response

@owl-guy owl-guy added the t/bug Something isn't working label Oct 21, 2022
@ghost ghost added the legacy-area-controls Label, Button, CheckBox, Slider, Stepper, Switch, Picker, Entry, Editor label Oct 21, 2022
@rachelkang rachelkang added this to the Backlog milestone Oct 21, 2022
@ghost
Copy link

ghost commented Oct 21, 2022

We've moved this issue to the Backlog milestone. This means that it is not going to be worked on for the coming release. We will reassess the backlog following the current release and consider this item at that time. To learn more about our issue management process and to have better expectation regarding different types of issues you can read our Triage Process.

@rachelkang rachelkang added the area-layout StackLayout, GridLayout, ScrollView, ContentView, AbsoluteLayout, FlexLayout, ContentPresenter label Oct 21, 2022
@owl-guy
Copy link
Author

owl-guy commented Jan 24, 2023

Any progress here?

@Laim
Copy link

Laim commented Feb 12, 2023

Would be interesting to know if there has been any progress on this as I'm having the exact same issue. What's odder is that the BackgroundColor does expand to fit the parent, it's just the actual SearchBar elements that don't and the only way to fix it is to hardcode a value into WidthRequest.

oH18ngR

<StackLayout>
  <Grid RowDefinitions="*,*" ColumnDefinitions="*,*">
    <SearchBar BackgroundColor="#FBCBF3" Grid.RowSpan="2" Grid.ColumnSpan="2" HorizontalOptions="FillAndExpand"/>
  </Grid>
</StackLayout>

and

<StackLayout>
  <SearchBar BackgroundColor="#FBCBF3" HorizontalOptions="FillAndExpand"/>
</StackLayout>

Both have the same result - inconsistent weird padding on both sides, no expanding. I've tried every layout possible.

@PramodMAUI
Copy link

Getting same issue. Searchbar is not expanding horizontally. Any workaround on this issue?

@vaidotasstrazdas
Copy link

One workaround is the following.

  1. Put this to your view model:
public double ScreenWidth
{
  get
  {
    return DeviceDisplay.Current.MainDisplayInfo.Width / DeviceDisplay.Current.MainDisplayInfo.Density;
  }
}

It calculates the current screen width, so it is not some random value. Why division by density? Probably, more experienced users of the .NET MAUI can explain this, but it seems that logical pixels here are deduced through the relation of the pixels and density of the device. Of course, it would be much better that these relations would be encapsulated like it is done in Flutter. And finally, when the orientation of the device changes, you would need to recalculate this value again. Or you can just do not allow users changing the orientation which in my opinion would result in a quite poor UI/UX.

  1. Then, use it like this:
    <SearchBar WidthRequest="{Binding ScreenWidth}" <... etc ...> />

It is a hack, but it is more hackish for the HorizontalOptions not to work in this case as the developer would expect. Hopefully, the team fill fix it soon, and this or similar hacks will no longer be needed for us. 😀

@PramodMAUI
Copy link

PramodMAUI commented May 23, 2023

Hi @vaidotasstrazdas , This workaround will work if only Searchbar is used in a row.
If we need to use a button placed with Searchbar in a row then it will not work as we are setting the entire width to SearchBar and the button will not fit in a single row with Searchbar.

Pls check attached screenshot for the design where this workaround will not work.
image

@jinxinjuan jinxinjuan added s/triaged Issue has been reviewed s/verified Verified / Reproducible Issue ready for Engineering Triage labels May 30, 2023
@jinxinjuan
Copy link
Collaborator

Verified this issue with Visual Studio Enterprise 17.7.0 Preview 1.0. Can repro on Android API-33 with sample project.
SearchBarExample.

@jsuarezruiz
Copy link
Contributor

Could you try again with the latest version?
Captura de pantalla 2023-07-12 a las 12 30 05

@tibuprophen
Copy link

Not working for me with latest .NET and .NET Workloads

@FreakyAli
Copy link

@jsuarezruiz The issue still persists with the latest versions of Maui

@nonoc
Copy link

nonoc commented Jan 22, 2024

Yes I'm using NET 8 and same persistence not growing when It should be.

@owl-guy
Copy link
Author

owl-guy commented Mar 28, 2024

Will someone work on this?

@alexsmi-noveo
Copy link

alexsmi-noveo commented Apr 11, 2024

In the latest NET7 (v7.0.18, sdk 7.0.315) issue is still reproducable. This workaround from @jfversluis helped me:

#7137 (comment)

@jfversluis
Copy link
Member

@alexsmi-noveo this won't be fixed for .NET 7 so that is expected. You can indeed use the workaround.

@nonoc @FreakyAli would you be able to put together a small reproduction sample for this? The original problem should be fixed by #13716 so I'm curious why it is still not working for you.

@naxoscompact
Copy link

naxoscompact commented Apr 26, 2024

Another solution is to bind the width of the search bar to that of another control that is resizing as it should. typically our search bar relates to another item on screen - eg ListView or similar. Seems to be working for me
<SearchBar HorizontalOptions="Start" Placeholder="Search" Text="{Binding SearchText, Mode=TwoWay}" WidthRequest="{Binding Width, Source={x:Reference ListView1}}" />

@FreakyAli
Copy link

@jfversluis Just saw this let me see what i can do

@FreakyAli
Copy link

So I checked this and it is working now but it adds a cancel button in iOS is this the intended behavior?

You can checkout this for reproduction: https://github.com/FreakyAli/Maui.FreakyEffects/tree/grahpicsViewBug

@jfversluis
Copy link
Member

@FreakyAli would you be able to check if it adds the Cancel button on Xamarin.Forms?

Looking at the docs the Cancel button is expected.

I'm leaning towards this seems to be fixed 😄

@FreakyAli
Copy link

@jfversluis As long as it matches the docs it works for me :)

@jfversluis
Copy link
Member

OK assuming this is fixed in the latest .NET MAUI versions. If you think otherwise, please open a new issue with all the details. Thanks!

@Eilon Eilon removed the legacy-area-controls Label, Button, CheckBox, Slider, Stepper, Switch, Picker, Entry, Editor label May 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-controls-entry Entry area-layout StackLayout, GridLayout, ScrollView, ContentView, AbsoluteLayout, FlexLayout, ContentPresenter platform/windows 🪟 s/triaged Issue has been reviewed s/verified Verified / Reproducible Issue ready for Engineering Triage t/bug Something isn't working
Projects
None yet
Development

No branches or pull requests