Skip to content
This repository has been archived by the owner on May 1, 2024. It is now read-only.

Commit

Permalink
Restrict the material button border to 1px. See #4951.
Browse files Browse the repository at this point in the history
  • Loading branch information
mattleibow committed Jan 16, 2019
1 parent a629234 commit e09d3da
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,8 @@ public MaterialButtonRenderer(Context context)
_automationPropertiesProvider = new AutomationPropertiesProvider(this);
_buttonLayoutManager = new ButtonLayoutManager(this,
alignIconWithText: true,
borderAdjustsPadding: true);
preserveInitialPadding: true,
borderAdjustsPadding: false);

SoundEffectsEnabled = false;
SetOnClickListener(this);
Expand Down Expand Up @@ -240,7 +241,7 @@ void UpdateBorder()
if (borderColor.IsDefault)
StrokeColor = _defaultBorderColor;
else
base.StrokeColor = new ColorStateList(new[] { new int[0] }, new int[] { borderColor.ToAndroid() });
StrokeColor = new ColorStateList(new[] { new int[0] }, new int[] { borderColor.ToAndroid() });
}

double borderWidth = Element.BorderWidth;
Expand All @@ -249,10 +250,15 @@ void UpdateBorder()
if (_defaultBorderWidth < 0)
_defaultBorderWidth = StrokeWidth;

// TODO: The Material button does not support borders:
// https://github.com/xamarin/Xamarin.Forms/issues/4951
if (borderWidth > 1)
borderWidth = 1;

if (borderWidth < 0f)
StrokeWidth = _defaultBorderWidth;
else
base.StrokeWidth = (int)Context.ToPixels(borderWidth);
StrokeWidth = (int)Context.ToPixels(borderWidth);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public MaterialButtonRenderer()
_buttonLayoutManager = new ButtonLayoutManager(this,
preserveInitialPadding: true,
spacingAdjustsPadding: false,
borderAdjustsPadding: true,
borderAdjustsPadding: false,
collapseHorizontalPadding: true);
}

Expand Down Expand Up @@ -209,6 +209,11 @@ void UpdateBorder()
if (_defaultBorderWidth == -1)
_defaultBorderWidth = Control.GetBorderWidth(UIControlState.Normal);

// TODO: The Material button does not support borders:
// https://github.com/xamarin/Xamarin.Forms/issues/4951
if (borderWidth > 1)
borderWidth = 1;

if (borderWidth == (double)Button.BorderWidthProperty.DefaultValue)
Control.SetBorderWidth(_defaultBorderWidth, UIControlState.Normal);
else
Expand Down

0 comments on commit e09d3da

Please sign in to comment.