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

Commit 06de4c3

Browse files
Merge branch 'develop'
2 parents cce3098 + 532512c commit 06de4c3

20 files changed

Lines changed: 448 additions & 92 deletions

MaterialDesignControls.nuspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<package xmlns="http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd">
33
<metadata minClientVersion="2.8.1">
44
<id>Plugin.MaterialDesignControls</id>
5-
<version>1.3.1</version>
5+
<version>1.4.0</version>
66
<title>MaterialDesignControls Plugin for Xamarin Forms</title>
77
<authors>Horus</authors>
88
<owners>AgustinBonillaHorus</owners>

README.md

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,44 @@ Displays a value with its respective label in read-only format.
148148
```XML
149149
<material:MaterialField LabelText="Mail" Text="michael.jordan@hotmail.com" LeadingIcon="email.png" />
150150
```
151+
## Effects
152+
153+
### TouchAndPressEffect
154+
Effect to detect the different types of taps on a view: Pressing, Released and Canceled can be detected.
155+
156+
**Example**
157+
```XML
158+
<MyControl.Effects>
159+
<material:TouchAndPressEffect />
160+
</MyControl.Effects>
161+
```
162+
163+
```C#
164+
public class MyControl : ContentView, ITouchAndPressEffectConsumer
165+
{
166+
public void ConsumeEvent(EventType gestureType)
167+
{
168+
switch (gestureType)
169+
{
170+
case EventType.Pressing:
171+
Task.Run(async () =>
172+
{
173+
await this.ScaleTo(0.90, 100);
174+
});
175+
break;
176+
case EventType.Cancelled:
177+
case EventType.Released:
178+
Task.Run(async () =>
179+
{
180+
await this.ScaleTo(1, 100);
181+
});
182+
break;
183+
default:
184+
throw new ArgumentOutOfRangeException(nameof(gestureType), gestureType, null);
185+
}
186+
}
187+
}
188+
```
151189

152190
## Demo
153191
https://github.com/HorusSoftwareUY/MaterialDesignControlsPlugin/tree/master/example

example/ExampleMaterialDesignControls/Pages/MaterialButtonPage.xaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,11 @@
1414
<material:MaterialButton IsEnabled="false" Text="Save" Icon="save.png" DisabledIcon="save.png" CornerRadius="20" Command="{Binding TapCommand}" CommandParameter="Saved" />
1515
<material:MaterialOutlineButton IsEnabled="false" Text="Cancel" Command="{Binding TapCommand}" CornerRadius="20" CommandParameter="Canceled" />
1616
<material:MaterialFlatButton IsEnabled="false" Text="Delete" Icon="delete.png" DisabledIcon="delete.png" Command="{Binding TapCommand}" CommandParameter="Deleted" />
17+
18+
<Label Text="Animations" HorizontalTextAlignment="Center" />
19+
<material:MaterialButton Animation="None" Text="None" ToUpper="True" />
20+
<material:MaterialButton Animation="Fade" AnimationParameter="0.6" Text="Fade" ToUpper="True" />
21+
<material:MaterialButton Animation="Scale" AnimationParameter="0.98" Text="Scale" ToUpper="True" />
1722
</StackLayout>
1823
</ScrollView>
1924
</ContentPage.Content>

example/ExampleMaterialDesignControls/Pages/MaterialButtonPage.xaml.cs

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,18 @@ public MaterialButtonPage()
2121

2222
public async void OnTap(object parameter)
2323
{
24-
if (parameter is string && ((string)parameter).ToString().Equals("Saved"))
24+
if (parameter != null)
2525
{
26-
this.btnSave.IsBusy = true;
27-
await Task.Delay(2000);
28-
this.btnSave.IsBusy = false;
29-
}
26+
if (parameter is string && ((string)parameter).ToString().Equals("Saved"))
27+
{
28+
this.btnSave.IsBusy = true;
29+
await Task.Delay(2000);
30+
this.btnSave.IsBusy = false;
31+
}
3032

31-
string text = parameter.ToString();
32-
await this.DisplayAlert("", text, "Ok");
33+
string text = parameter.ToString();
34+
await this.DisplayAlert("", text, "Ok");
35+
}
3336
}
3437
}
3538
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using Android.Runtime;
5+
using Xamarin.Forms.Platform.Android;
6+
7+
namespace Plugin.MaterialDesignControls.Android
8+
{
9+
[Preserve(AllMembers = true)]
10+
public static class Effects
11+
{
12+
private static List<PlatformEffect> _allEffects = new List<PlatformEffect>();
13+
14+
public static void Init()
15+
{
16+
_allEffects = new List<PlatformEffect>(typeof(Effects).Assembly.GetTypes()
17+
.Where(t => typeof(PlatformEffect).IsAssignableFrom(t))
18+
.Select(t => (PlatformEffect)Activator.CreateInstance(t)));
19+
}
20+
}
21+
}
Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
using System;
2+
using Android.Views;
3+
using Plugin.MaterialDesignControls;
4+
using Xamarin.Forms;
5+
using Xamarin.Forms.Platform.Android;
6+
using View = Android.Views.View;
7+
using TouchAndPressEffect = Plugin.MaterialDesignControls.Android.TouchAndPressEffect;
8+
9+
[assembly: ResolutionGroupName(Plugin.MaterialDesignControls.TouchAndPressEffect.EffectIdPrefix)]
10+
[assembly: ExportEffect(typeof(TouchAndPressEffect), nameof(TouchAndPressEffect))]
11+
12+
namespace Plugin.MaterialDesignControls.Android
13+
{
14+
public class TouchAndPressEffect : PlatformEffect
15+
{
16+
private View _view;
17+
private ITouchAndPressEffectConsumer _touchAndPressEffectConsumer;
18+
19+
protected override void OnAttached()
20+
{
21+
_view = Control ?? Container;
22+
23+
if (_view != null && Element is ITouchAndPressEffectConsumer touchAndPressEffectConsumer)
24+
{
25+
_view.Touch += OnViewOnTouch;
26+
_touchAndPressEffectConsumer = touchAndPressEffectConsumer;
27+
}
28+
}
29+
30+
protected override void OnDetached()
31+
{
32+
if (_view != null)
33+
{
34+
_view.Touch -= OnViewOnTouch;
35+
}
36+
}
37+
38+
private void OnViewOnTouch(object sender, View.TouchEventArgs e)
39+
{
40+
switch (e.Event.ActionMasked)
41+
{
42+
case MotionEventActions.ButtonPress:
43+
_touchAndPressEffectConsumer?.ConsumeEvent(EventType.Pressing);
44+
break;
45+
case MotionEventActions.ButtonRelease:
46+
_touchAndPressEffectConsumer?.ConsumeEvent(EventType.Released);
47+
break;
48+
case MotionEventActions.Cancel:
49+
_touchAndPressEffectConsumer?.ConsumeEvent(EventType.Cancelled);
50+
break;
51+
case MotionEventActions.Down:
52+
_touchAndPressEffectConsumer?.ConsumeEvent(EventType.Pressing);
53+
break;
54+
case MotionEventActions.HoverEnter:
55+
break;
56+
case MotionEventActions.HoverExit:
57+
break;
58+
case MotionEventActions.HoverMove:
59+
break;
60+
case MotionEventActions.Mask:
61+
break;
62+
case MotionEventActions.Move:
63+
break;
64+
case MotionEventActions.Outside:
65+
break;
66+
case MotionEventActions.Pointer1Down:
67+
_touchAndPressEffectConsumer?.ConsumeEvent(EventType.Pressing);
68+
break;
69+
case MotionEventActions.Pointer1Up:
70+
_touchAndPressEffectConsumer?.ConsumeEvent(EventType.Released);
71+
break;
72+
case MotionEventActions.Pointer2Down:
73+
break;
74+
case MotionEventActions.Pointer2Up:
75+
break;
76+
case MotionEventActions.Pointer3Down:
77+
break;
78+
case MotionEventActions.Pointer3Up:
79+
break;
80+
case MotionEventActions.PointerIdMask:
81+
break;
82+
case MotionEventActions.PointerIdShift:
83+
break;
84+
case MotionEventActions.Up:
85+
_touchAndPressEffectConsumer?.ConsumeEvent(EventType.Released);
86+
break;
87+
default:
88+
throw new ArgumentOutOfRangeException();
89+
}
90+
}
91+
}
92+
}

src/MaterialDesignControls.Android/MaterialDesignControls.Android.csproj

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,8 @@
130130
<Compile Include="Renderers\MaterialTimePickerRenderer.cs" />
131131
<Compile Include="Renderers\MaterialEditorRenderer.cs" />
132132
<Compile Include="Renderers\MaterialLabelRenderer.cs" />
133-
<Compile Include="Renderers\MaterialButtonRenderer.cs" />
133+
<Compile Include="Effects\TouchAndPressEffect.cs" />
134+
<Compile Include="Effects.cs" />
134135
</ItemGroup>
135136
<ItemGroup>
136137
<None Include="Resources\AboutResources.txt" />
@@ -141,6 +142,7 @@
141142
</ItemGroup>
142143
<ItemGroup>
143144
<Folder Include="Renderers\" />
145+
<Folder Include="Effects\" />
144146
</ItemGroup>
145147
<ItemGroup>
146148
<ProjectReference Include="..\MaterialDesignControls\MaterialDesignControls.csproj">

src/MaterialDesignControls.Android/Renderers.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,13 @@ public static class Renderer
44
{
55
public static void Init()
66
{
7+
Effects.Init();
78
MaterialDatePickerRenderer.Init();
89
MaterialEntryRenderer.Init();
910
MaterialPickerRenderer.Init();
1011
MaterialTimePickerRenderer.Init();
1112
MaterialEditorRenderer.Init();
1213
MaterialLabelRenderer.Init();
13-
MaterialButtonRenderer.Init();
1414
}
1515
}
1616
}

src/MaterialDesignControls.Android/Renderers/MaterialButtonRenderer.cs

Lines changed: 0 additions & 27 deletions
This file was deleted.
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using Foundation;
5+
using Xamarin.Forms.Platform.iOS;
6+
7+
namespace Plugin.MaterialDesignControls.iOS
8+
{
9+
[Preserve(AllMembers = true)]
10+
public static class Effects
11+
{
12+
private static List<PlatformEffect> _allEffects = new List<PlatformEffect>();
13+
14+
public static void Init()
15+
{
16+
_allEffects = new List<PlatformEffect>(typeof(Effects).Assembly.GetTypes()
17+
.Where(t => typeof(PlatformEffect).IsAssignableFrom(t))
18+
.Select(t => (PlatformEffect)Activator.CreateInstance(t)));
19+
}
20+
}
21+
}

0 commit comments

Comments
 (0)