Skip to content

Commit

Permalink
Show badge counter if count is above 99 (#257)
Browse files Browse the repository at this point in the history
* Badge now shows count if its above 99

* Pixel pushing

* iOS pixel pushing

Co-authored-by: Erling Moxnes Kristiansen <emk@dips.no>
  • Loading branch information
ErlingMK and Erling Moxnes Kristiansen authored Feb 1, 2021
1 parent 4b58d6a commit f63f5b8
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,6 @@
Grid.Column="1"
IsVisible="{Binding Source={x:Reference CodeBehind}, Path= IsBadgeVisible}"
BackgroundColor="{Binding Source={x:Reference CodeBehind}, Path= BadgeColor}"
HeightRequest="20"
WidthRequest="20"
CornerRadius="10"
InputTransparent="True"
Padding="0"
VerticalOptions="Start"
Expand All @@ -97,9 +94,9 @@
FontFamily="{Binding Source={x:Reference CodeBehind}, Path= BadgeFontFamily}"
FontSize="12"
LineBreakMode="NoWrap"
BackgroundColor="Transparent"
VerticalTextAlignment="Center"
HorizontalTextAlignment="Center" />
BackgroundColor="Transparent"
VerticalOptions="Center"
HorizontalOptions="Center"/>

</Frame>
</Grid>
Expand Down
26 changes: 19 additions & 7 deletions src/DIPS.Xamarin.UI/Controls/FloatingActionMenu/MenuButton.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -395,16 +395,28 @@ private static object CoerceValue(BindableObject bindable, object value)
{
if (newCount > 99)
{
menuButton.BadgeFrame.HeightRequest = 25;
menuButton.BadgeFrame.WidthRequest = 25;
menuButton.BadgeFrame.CornerRadius = 12.5f;
return "99+";
menuButton.BadgeFrame.HeightRequest = 20;
menuButton.BadgeFrame.WidthRequest = -1;
menuButton.BadgeFrame.Padding = new Thickness(5, 0);
menuButton.BadgeFrame.CornerRadius = 8;
return value;
}
}

menuButton.BadgeFrame.HeightRequest = 20;
menuButton.BadgeFrame.WidthRequest = 20;
menuButton.BadgeFrame.CornerRadius = 10;
if (Device.RuntimePlatform == Device.Android)
{
menuButton.BadgeFrame.HeightRequest = 20;
menuButton.BadgeFrame.WidthRequest = 20;
menuButton.BadgeFrame.CornerRadius = 10;
menuButton.BadgeFrame.Padding = new Thickness(1);
}
else
{
menuButton.BadgeFrame.HeightRequest = 22;
menuButton.BadgeFrame.WidthRequest = 22;
menuButton.BadgeFrame.CornerRadius = 11;
menuButton.BadgeFrame.Padding = new Thickness(0);
}
}

return value;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@
IsBadgeVisible="{Binding ShowBadge}"
BadgeColor="{Binding BadgeColor}"
BadgeCount="{Binding BadgeCounter}"
BadgeTextColor="White"
IsVisible="{Binding IsMenuButtonVisible}"
Source="https://www.pngitem.com/pimgs/m/549-5493065_xamarin-logo-png-transparent-xamarin-forms-logo-png.png"
Title="Second page"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@ public class FloatingActionMenuPageViewmodel : INotifyPropertyChanged
{
private string m_text;
private bool m_showBadge;
private int m_badgeCounter;
private Color m_badgeColor;
private int m_badgeCounter = 99;
private Color m_badgeColor = Color.Green;
private string m_currentEvent;
private bool m_isMenuButtonVisible = true;

Expand All @@ -65,8 +65,8 @@ public FloatingActionMenuPageViewmodel()
DecreaseCounterCommand = new Command(() => BadgeCounter--);
ChangeBadgeColorCommand = new Command(() =>
{
if ( BadgeColor != Color.BlueViolet) BadgeColor = Color.BlueViolet;
else BadgeColor = Color.IndianRed;
if (BadgeColor != Color.Green) BadgeColor = Color.Red;
else BadgeColor = Color.Red;
});
ToggleButtonVisibilityCommand = new Command(() => IsMenuButtonVisible = !IsMenuButtonVisible);

Expand Down

0 comments on commit f63f5b8

Please sign in to comment.