Skip to content

Commit

Permalink
Merge pull request #85 from ZeroGachis/task/fix-greyed-buttons-counter
Browse files Browse the repository at this point in the history
🐛 Fix greyed button when disabled
  • Loading branch information
Keivhin authored Jun 10, 2021
2 parents 6e2ed0d + 1e41abf commit 1d6883a
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 6 deletions.
12 changes: 10 additions & 2 deletions Smartway.UiComponent/Inputs/Counter.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,12 @@
<Setter Property="VerticalOptions" Value="Fill"/>
<Setter Property="HorizontalOptions" Value="Fill"/>
<Setter Property="BackgroundColor" Value="Transparent"/>
<Setter Property="TextColor" Value="{Binding Source={x:Reference Self}, Path=FontColor}"/>
<Style.Triggers>
<Trigger TargetType="Button" Property="IsEnabled" Value="False">
<Setter Property="TextColor" Value="{StaticResource ZgColdGrey}"/>
</Trigger>
</Style.Triggers>
</Style>
</ContentView.Resources>
<ContentView.Content>
Expand All @@ -27,24 +33,26 @@
<ColumnDefinition Width="50"/>
</Grid.ColumnDefinitions>
<Button Grid.Column="0"
x:Name="DecreaseButton"
Style="{StaticResource ButtonsStyle}"
Clicked="DecreaseCounterValue">
<Button.ImageSource>
<FontImageSource Glyph="&#xe15c;"
FontFamily="MaterialRegular"
Color="{Binding Source={x:Reference Self}, Path=FontColor}"
Color="{Binding Source={x:Reference DecreaseButton}, Path=TextColor}"
Size="{Binding Source={x:Reference Self}, Path=FontSize}"/>
</Button.ImageSource>
</Button>
<Label Grid.Column="1"
Style="{StaticResource NumericValueStyle}"/>
<Button Grid.Column="2"
x:Name="IncreaseButton"
Style="{StaticResource ButtonsStyle}"
Clicked="IncreaseCounterValue">
<Button.ImageSource>
<FontImageSource Glyph="&#xe147;"
FontFamily="MaterialRegular"
Color="{Binding Source={x:Reference Self}, Path=FontColor}"
Color="{Binding Source={x:Reference IncreaseButton}, Path=TextColor}"
Size="{Binding Source={x:Reference Self}, Path=FontSize}"/>
</Button.ImageSource>
</Button>
Expand Down
15 changes: 11 additions & 4 deletions Smartway.UiComponent/Inputs/Counter.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using Smartway.UiComponent.Resources;
using Xamarin.Forms;
using Xamarin.Forms.Internals;
using Xamarin.Forms.Xaml;
Expand All @@ -11,6 +12,8 @@ public partial class Counter
public Counter()
{
InitializeComponent();

RefreshButtonsEnabled();
}

public static readonly BindableProperty ValueProperty = BindableProperty.Create(
Expand Down Expand Up @@ -69,16 +72,20 @@ public string FontFamily

private void DecreaseCounterValue(object sender, EventArgs e)
{
if (Value == MinValue)
return;
Value--;
RefreshButtonsEnabled();
}

private void IncreaseCounterValue(object sender, EventArgs e)
{
if (Value == MaxValue)
return;
Value++;
RefreshButtonsEnabled();
}

private void RefreshButtonsEnabled()
{
DecreaseButton.IsEnabled = Value > MinValue;
IncreaseButton.IsEnabled = Value < MaxValue;
}
}
}

0 comments on commit 1d6883a

Please sign in to comment.