Skip to content

Commit

Permalink
Use SizeToFit for SearchBar when constraints are infinite
Browse files Browse the repository at this point in the history
Possibly fixes #5346
  • Loading branch information
hartez authored and rmarinho committed Apr 1, 2022
1 parent de39554 commit d932e4a
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/Core/src/Handlers/SearchBar/SearchBarHandler.iOS.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using Foundation;
using Microsoft.Maui.Graphics;
using UIKit;

namespace Microsoft.Maui.Handlers
Expand Down Expand Up @@ -54,6 +55,17 @@ protected override void DisconnectHandler(MauiSearchBar platformView)
base.DisconnectHandler(platformView);
}

public override Size GetDesiredSize(double widthConstraint, double heightConstraint)
{
if (double.IsInfinity(widthConstraint) || double.IsInfinity(heightConstraint))
{
PlatformView.SizeToFit();
return new Size(PlatformView.Frame.Width, PlatformView.Frame.Height);
}

return base.GetDesiredSize(widthConstraint, heightConstraint);
}

public static void MapIsEnabled(ISearchBarHandler handler, ISearchBar searchBar)
{
handler.PlatformView?.UpdateIsEnabled(searchBar);
Expand Down

0 comments on commit d932e4a

Please sign in to comment.