Skip to content

Commit

Permalink
request layout of measure changes force layout if it doesn't (xamarin…
Browse files Browse the repository at this point in the history
  • Loading branch information
PureWeen authored Jun 30, 2019
1 parent 40961c1 commit e224948
Showing 1 changed file with 17 additions and 4 deletions.
21 changes: 17 additions & 4 deletions Xamarin.Forms.Platform.Android/ButtonLayoutManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,21 @@ protected virtual void Dispose(bool disposing)

internal SizeRequest GetDesiredSize(int widthConstraint, int heightConstraint)
{
var previousHeight = View.MeasuredHeight;
var previousWidth = View.MeasuredWidth;

View.Measure(widthConstraint, heightConstraint);
View.ForceLayout();

// if the measure of the view has changed then trigger a request for layout
// if the measure hasn't changed then force a layout of the button
if (previousHeight != View.MeasuredHeight || previousWidth != View.MeasuredWidth)
{
if (!View.IsLayoutRequested)
View.RequestLayout();
}
else
View.ForceLayout();

return new SizeRequest(new Size(View.MeasuredWidth, View.MeasuredHeight), Size.Zero);
}

Expand Down Expand Up @@ -289,7 +302,7 @@ void UpdateImage()
Drawable existingImage = null;
var images = TextViewCompat.GetCompoundDrawablesRelative(view);
for (int i = 0; i < images.Length; i++)
if(images[i] != null)
if (images[i] != null)
{
existingImage = images[i];
break;
Expand All @@ -314,8 +327,8 @@ void UpdateImage()
TextViewCompat.SetCompoundDrawablesRelativeWithIntrinsicBounds(view, null, null, null, image);
break;
default:
// Defaults to image on the left
TextViewCompat.SetCompoundDrawablesRelativeWithIntrinsicBounds(view, image, null, null, null);
// Defaults to image on the left
TextViewCompat.SetCompoundDrawablesRelativeWithIntrinsicBounds(view, image, null, null, null);
break;
}

Expand Down

0 comments on commit e224948

Please sign in to comment.