Skip to content
This repository was archived by the owner on May 15, 2025. It is now read-only.

Commit d7b3f27

Browse files
agaldanaw2agaldanawAgustinBonilla
authored
Support to Clicked event button (#16)
* support to Clicked event button * Modify the ITouchAndPressEffectConsumer interface Co-authored-by: AndresAldana <agaldanaw@unal.edu.co> Co-authored-by: Agustin Bonilla <agustin.bonilla@horus.com.uy>
1 parent dce6594 commit d7b3f27

9 files changed

Lines changed: 32 additions & 99 deletions

File tree

example/ExampleMaterialDesignControls/ExampleMaterialDesignControls.csproj

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,6 @@
1515
<PackageReference Include="Xamarin.Forms.Skeleton" Version="2.0.0" />
1616
<PackageReference Include="Xamarin.FFImageLoading.Svg.Forms" Version="2.4.11.982" />
1717
</ItemGroup>
18-
<ItemGroup>
19-
<ProjectReference Include="..\..\src\MaterialDesignControls\MaterialDesignControls.csproj" />
20-
</ItemGroup>
2118
<ItemGroup>
2219
<Folder Include="Pages\" />
2320
<Folder Include="ViewModels\" />
@@ -52,4 +49,7 @@
5249
<EmbeddedResource Include="Resources/Fonts/*" />
5350
<EmbeddedResource Include="Resources/Svg/*" />
5451
</ItemGroup>
52+
<ItemGroup>
53+
<ProjectReference Include="..\..\src\MaterialDesignControls\MaterialDesignControls.csproj" />
54+
</ItemGroup>
5555
</Project>

example/ExampleMaterialDesignControls/MainPage.xaml.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,7 @@ public MainPage()
1616
InitializeComponent();
1717
this.Children.Add(new ProductDetailsPage());
1818
this.Children.Add(new AddCardPage());
19-
this.Children.Add(new MaterialDatePickerPage());
20-
this.Children.Add(new NavigationPage(new MaterialControlsPage()) { Title="Controls", IconImageSource="" });
19+
this.Children.Add(new NavigationPage(new MaterialControlsPage()) { Title = "Controls", IconImageSource = "Product.png" });
2120

2221
//masterPage.ListView.ItemSelected += OnItemSelected;
2322
}

example/ExampleMaterialDesignControls/Pages/MaterialButtonPage (copy).xaml

Lines changed: 0 additions & 58 deletions
This file was deleted.

example/ExampleMaterialDesignControls/Pages/MaterialButtonPage (copy).xaml.cs

Lines changed: 0 additions & 19 deletions
This file was deleted.

example/ExampleMaterialDesignControls/Pages/MaterialButtonPage.xaml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
<StackLayout Padding="16" Spacing="16">
1414
<material:MaterialButton Text="Save" ToUpper="True" Icon="save.png" Command="{Binding TapCommand}" CommandParameter="Saved" IsBusy="{Binding IsBusy}" CornerRadius="14" />
1515

16-
<material:MaterialOutlineButton Text="Cancel" Command="{Binding TapCommand}" CommandParameter="Canceled" IsBusy="{Binding IsBusy}" CornerRadius="14" IconSize="34" ActivityIndicatorSize="34">
16+
<material:MaterialOutlineButton Text="Cancel" Command="{Binding TapCommand}" CommandParameter="Canceled" CornerRadius="14" IconSize="34" ActivityIndicatorSize="34">
1717
<material:MaterialButton.CustomIcon>
1818
<ffimageloadingsvg:SvgCachedImage Source="resource://ExampleMaterialDesignControls.Resources.Svg.ic_help_b.svg"/>
1919
</material:MaterialButton.CustomIcon>
@@ -32,6 +32,10 @@
3232
<material:MaterialButton Animation="None" Text="None" ToUpper="True" CornerRadius="14" />
3333
<material:MaterialButton Animation="Fade" AnimationParameter="0.6" Text="Fade" ToUpper="True" CornerRadius="14" />
3434
<material:MaterialButton Animation="Scale" AnimationParameter="0.98" Text="Scale" ToUpper="True" CornerRadius="14" />
35+
36+
<Label Text="Clicked event" HorizontalTextAlignment="Center" Margin="0,40,0,0" />
37+
<material:MaterialButton Animation="Fade" AnimationParameter="0.6" Text="Clicked" ToUpper="True" CornerRadius="14" Clicked="Button_Clicked" />
38+
3539
</StackLayout>
3640
</ScrollView>
3741
</ContentPage.Content>

example/ExampleMaterialDesignControls/Pages/MaterialButtonPage.xaml.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,5 +15,10 @@ public MaterialButtonPage()
1515

1616
this.BindingContext = new MaterialButtonViewModel { DisplayAlert = this.DisplayAlert };
1717
}
18+
19+
private void Button_Clicked(object sender, EventArgs e)
20+
{
21+
DisplayAlert("Clicked Event", "Executing the click event in the code behind", "Ok");
22+
}
1823
}
1924
}

src/MaterialDesignControls/Animations/TouchAndPressAnimation.cs

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,7 @@ public static void Animate(View view, EventType gestureType)
1717
break;
1818
case EventType.Cancelled:
1919
case EventType.Released:
20-
if (touchAndPressEffectConsumer.IsEnabled && touchAndPressEffectConsumer.Command != null && touchAndPressEffectConsumer.Command.CanExecute(touchAndPressEffectConsumer.CommandParameter))
21-
{
22-
touchAndPressEffectConsumer.Command.Execute(touchAndPressEffectConsumer.CommandParameter);
23-
}
24-
20+
touchAndPressEffectConsumer.ExecuteAction();
2521
RestoreAnimation(view, touchAndPressEffectConsumer);
2622
break;
2723
case EventType.Ignored:
@@ -34,7 +30,7 @@ public static void Animate(View view, EventType gestureType)
3430

3531
private static void SetAnimation(View view, ITouchAndPressEffectConsumer touchAndPressEffectConsumer)
3632
{
37-
if (touchAndPressEffectConsumer.Animation != AnimationTypes.None && view.IsEnabled && (touchAndPressEffectConsumer.Command == null || touchAndPressEffectConsumer.Command.CanExecute(touchAndPressEffectConsumer.CommandParameter)))
33+
if (touchAndPressEffectConsumer.Animation != AnimationTypes.None && touchAndPressEffectConsumer.IsEnabled)
3834
{
3935
Task.Run(async () =>
4036
{
@@ -68,5 +64,4 @@ private static void RestoreAnimation(View view, ITouchAndPressEffectConsumer tou
6864
}
6965
}
7066
}
71-
}
72-
67+
}

src/MaterialDesignControls/Controls/MaterialButton.cs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -258,6 +258,8 @@ public double ActivityIndicatorSize
258258
set { SetValue(ActivityIndicatorSizeProperty, value); }
259259
}
260260

261+
public event EventHandler Clicked;
262+
261263
#endregion Properties
262264

263265
#region Methods
@@ -468,6 +470,15 @@ public void ConsumeEvent(EventType gestureType)
468470
TouchAndPressAnimation.Animate(this, gestureType);
469471
}
470472

473+
public void ExecuteAction()
474+
{
475+
if (IsEnabled && Command != null && Command.CanExecute(CommandParameter))
476+
Command.Execute(CommandParameter);
477+
478+
if (IsEnabled && Clicked != null)
479+
Clicked.Invoke(this, null);
480+
}
481+
471482
#endregion Methods
472483
}
473-
}
484+
}

src/MaterialDesignControls/Effects/TouchAndPressEffect.cs

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,14 @@
1-
using System;
2-
using System.Threading.Tasks;
3-
using System.Windows.Input;
4-
using Xamarin.Forms;
1+
using Xamarin.Forms;
52

63
namespace Plugin.MaterialDesignControls
74
{
85
public interface ITouchAndPressEffectConsumer
96
{
107
void ConsumeEvent(EventType gestureType);
11-
ICommand Command { get; set; }
12-
object CommandParameter { get; set; }
138
bool IsEnabled { get; set; }
149
AnimationTypes Animation { get; set; }
1510
double? AnimationParameter { get; set; }
11+
void ExecuteAction();
1612
}
1713

1814
public enum EventType
@@ -31,4 +27,4 @@ public TouchAndPressEffect() : base($"{EffectIdPrefix}.{nameof(TouchAndPressEffe
3127
{
3228
}
3329
}
34-
}
30+
}

0 commit comments

Comments
 (0)