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

Commit 532512c

Browse files
The Xamarin Button is removed from MaterialButton
1 parent 393f580 commit 532512c

13 files changed

Lines changed: 117 additions & 121 deletions

File tree

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

src/MaterialDesignControls.Android/Effects/TouchAndPressEffect.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
using System;
22
using Android.Views;
3-
using Plugin.MaterialDesignControls.Effects;
3+
using Plugin.MaterialDesignControls;
44
using Xamarin.Forms;
55
using Xamarin.Forms.Platform.Android;
66
using View = Android.Views.View;
77
using TouchAndPressEffect = Plugin.MaterialDesignControls.Android.TouchAndPressEffect;
88

9-
[assembly: ResolutionGroupName(Plugin.MaterialDesignControls.Effects.TouchAndPressEffect.EffectIdPrefix)]
9+
[assembly: ResolutionGroupName(Plugin.MaterialDesignControls.TouchAndPressEffect.EffectIdPrefix)]
1010
[assembly: ExportEffect(typeof(TouchAndPressEffect), nameof(TouchAndPressEffect))]
1111

1212
namespace Plugin.MaterialDesignControls.Android

src/MaterialDesignControls.Android/MaterialDesignControls.Android.csproj

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,6 @@
130130
<Compile Include="Renderers\MaterialTimePickerRenderer.cs" />
131131
<Compile Include="Renderers\MaterialEditorRenderer.cs" />
132132
<Compile Include="Renderers\MaterialLabelRenderer.cs" />
133-
<Compile Include="Renderers\MaterialButtonRenderer.cs" />
134133
<Compile Include="Effects\TouchAndPressEffect.cs" />
135134
<Compile Include="Effects.cs" />
136135
</ItemGroup>

src/MaterialDesignControls.Android/Renderers.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ public static void Init()
1111
MaterialTimePickerRenderer.Init();
1212
MaterialEditorRenderer.Init();
1313
MaterialLabelRenderer.Init();
14-
MaterialButtonRenderer.Init();
1514
}
1615
}
1716
}

src/MaterialDesignControls.Android/Renderers/MaterialButtonRenderer.cs

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

src/MaterialDesignControls.iOS/Effects/TouchAndPressEffect.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
using Foundation;
2-
using Plugin.MaterialDesignControls.Effects;
2+
using Plugin.MaterialDesignControls;
33
using UIKit;
44
using Xamarin.Forms;
55
using Xamarin.Forms.Platform.iOS;
66
using TouchAndPressEffect = Plugin.MaterialDesignControls.iOS.TouchAndPressEffect;
77

8-
[assembly: ResolutionGroupName(Plugin.MaterialDesignControls.Effects.TouchAndPressEffect.EffectIdPrefix)]
8+
[assembly: ResolutionGroupName(Plugin.MaterialDesignControls.TouchAndPressEffect.EffectIdPrefix)]
99
[assembly: ExportEffect(typeof(TouchAndPressEffect), nameof(TouchAndPressEffect))]
1010

1111
namespace Plugin.MaterialDesignControls.iOS

src/MaterialDesignControls/Controls/MaterialButton.cs

Lines changed: 70 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,7 @@
11
using System;
2-
using System.Linq;
32
using System.Runtime.CompilerServices;
43
using System.Threading.Tasks;
54
using System.Windows.Input;
6-
using Plugin.MaterialDesignControls.Effects;
7-
using Plugin.MaterialDesignControls.Implementations;
85
using Xamarin.Forms;
96

107
namespace Plugin.MaterialDesignControls
@@ -27,9 +24,13 @@ public MaterialButton()
2724

2825
private bool initialized = false;
2926

30-
protected CustomButton button;
27+
protected Frame frmLayout;
3128

32-
private Grid grid;
29+
private StackLayout stcLayout;
30+
31+
private Image imgIcon;
32+
33+
private MaterialLabel lblText;
3334

3435
private ActivityIndicator actIndicator;
3536

@@ -216,30 +217,51 @@ private void Initialize()
216217
{
217218
this.initialized = true;
218219

219-
this.grid = new Grid
220+
this.frmLayout = new Frame
220221
{
222+
HasShadow = false,
223+
CornerRadius = 4,
221224
MinimumHeightRequest = 40,
222225
HeightRequest = 40,
226+
Padding = new Thickness(12, 0)
223227
};
224-
this.Content = this.grid;
228+
this.Content = this.frmLayout;
225229

226-
this.actIndicator = new ActivityIndicator
230+
this.stcLayout = new StackLayout
227231
{
228-
VerticalOptions = LayoutOptions.Center,
232+
Orientation = StackOrientation.Horizontal,
233+
Spacing = 12,
229234
HorizontalOptions = LayoutOptions.Center,
235+
};
236+
this.frmLayout.Content = this.stcLayout;
237+
238+
this.imgIcon = new Image
239+
{
240+
VerticalOptions = LayoutOptions.Center,
230241
WidthRequest = 24,
231242
HeightRequest = 24,
232-
IsRunning = false,
233243
IsVisible = false
234244
};
235-
this.grid.Children.Add(this.actIndicator, 0, 0);
245+
this.stcLayout.Children.Add(this.imgIcon);
236246

237-
this.button = new CustomButton
247+
this.lblText = new MaterialLabel
238248
{
239-
CornerRadius = 4,
240-
Padding = new Thickness(12, 0)
249+
LineBreakMode = LineBreakMode.NoWrap,
250+
VerticalOptions = LayoutOptions.Center
241251
};
242-
this.grid.Children.Add(this.button, 0, 0);
252+
this.stcLayout.Children.Add(this.lblText);
253+
254+
this.actIndicator = new ActivityIndicator
255+
{
256+
VerticalOptions = LayoutOptions.Center,
257+
HorizontalOptions = LayoutOptions.Center,
258+
WidthRequest = 24,
259+
HeightRequest = 24,
260+
IsVisible = false
261+
};
262+
this.stcLayout.Children.Add(this.actIndicator);
263+
264+
this.Effects.Add(new TouchAndPressEffect());
243265
}
244266

245267
protected override void OnPropertyChanged([CallerMemberName] string propertyName = null)
@@ -257,43 +279,43 @@ protected override void OnPropertyChanged([CallerMemberName] string propertyName
257279
break;
258280
case nameof(this.Text):
259281
case nameof(this.ToUpper):
260-
this.button.Text = this.ToUpper ? this.Text?.ToUpper() : this.Text;
282+
this.lblText.Text = this.ToUpper ? this.Text?.ToUpper() : this.Text;
261283
break;
262284
case nameof(this.TextColor):
263285
case nameof(this.DisabledTextColor):
264-
this.button.TextColor = this.IsEnabled ? this.TextColor : this.DisabledTextColor;
286+
this.lblText.TextColor = this.IsEnabled ? this.TextColor : this.DisabledTextColor;
265287
break;
266288
case nameof(this.TextSize):
267-
this.button.FontSize = this.TextSize;
289+
this.lblText.FontSize = this.TextSize;
268290
break;
269291
case nameof(this.FontFamily):
270-
this.button.FontFamily = this.FontFamily;
292+
this.lblText.FontFamily = this.FontFamily;
271293
break;
272294
case nameof(this.CornerRadius):
273-
this.button.CornerRadius = Convert.ToInt32(this.CornerRadius);
295+
this.frmLayout.CornerRadius = Convert.ToInt32(this.CornerRadius);
274296
break;
275297
case nameof(this.BackgroundColor):
276298
case nameof(this.DisabledBackgroundColor):
277-
this.button.BackgroundColor = this.IsEnabled ? this.BackgroundColor : this.DisabledBackgroundColor;
299+
this.frmLayout.BackgroundColor = this.IsEnabled ? this.BackgroundColor : this.DisabledBackgroundColor;
278300
break;
279301
case nameof(this.BorderColor):
280302
case nameof(this.DisabledBorderColor):
281-
this.button.BorderColor = this.IsEnabled ? this.BorderColor : this.DisabledBorderColor;
303+
this.frmLayout.BorderColor = this.IsEnabled ? this.BorderColor : this.DisabledBorderColor;
282304
break;
283305
case nameof(this.Icon):
284306
case nameof(this.DisabledIcon):
285307
if (!string.IsNullOrEmpty(this.Icon) || !string.IsNullOrEmpty(this.DisabledIcon))
286308
{
287-
this.button.ImageSource = this.IsEnabled ? this.Icon : this.DisabledIcon;
309+
this.imgIcon.Source = this.IsEnabled ? this.Icon : this.DisabledIcon;
288310
}
289311
break;
290312
case nameof(this.IsEnabled):
291-
this.button.TextColor = this.IsEnabled ? this.TextColor : this.DisabledTextColor;
292-
this.button.BackgroundColor = this.IsEnabled ? this.BackgroundColor : this.DisabledBackgroundColor;
293-
this.button.BorderColor = this.IsEnabled ? this.BorderColor : this.DisabledBorderColor;
313+
this.lblText.TextColor = this.IsEnabled ? this.TextColor : this.DisabledTextColor;
314+
this.frmLayout.BackgroundColor = this.IsEnabled ? this.BackgroundColor : this.DisabledBackgroundColor;
315+
this.frmLayout.BorderColor = this.IsEnabled ? this.BorderColor : this.DisabledBorderColor;
294316
if (!string.IsNullOrEmpty(this.Icon) || !string.IsNullOrEmpty(this.DisabledIcon))
295317
{
296-
this.button.ImageSource = this.IsEnabled ? this.Icon : this.DisabledIcon;
318+
this.imgIcon.Source = this.IsEnabled ? this.Icon : this.DisabledIcon;
297319
}
298320
break;
299321
case nameof(this.BusyColor):
@@ -302,39 +324,21 @@ protected override void OnPropertyChanged([CallerMemberName] string propertyName
302324
case nameof(this.IsBusy):
303325
if (this.IsBusy)
304326
{
327+
this.lblText.IsVisible = false;
328+
this.imgIcon.IsVisible = false;
305329
this.actIndicator.IsVisible = true;
306330
this.actIndicator.IsRunning = true;
307-
this.button.IsVisible = false;
331+
this.frmLayout.BackgroundColor = Color.Transparent;
332+
this.frmLayout.BorderColor = Color.Transparent;
308333
}
309334
else
310335
{
336+
this.lblText.IsVisible = true;
337+
this.imgIcon.IsVisible = !string.IsNullOrEmpty(this.Icon) || !string.IsNullOrEmpty(this.DisabledIcon);
311338
this.actIndicator.IsVisible = false;
312339
this.actIndicator.IsRunning = false;
313-
this.button.IsVisible = true;
314-
}
315-
break;
316-
case nameof(this.Command):
317-
if (this.Animation == AnimationTypes.None)
318-
{
319-
this.button.Command = this.Command;
320-
}
321-
break;
322-
case nameof(this.CommandParameter):
323-
if (this.Animation == AnimationTypes.None)
324-
{
325-
this.button.CommandParameter = this.CommandParameter;
326-
}
327-
break;
328-
case nameof(this.Animation):
329-
if (this.Animation != AnimationTypes.None)
330-
{
331-
this.button.Command = null;
332-
this.button.CommandParameter = null;
333-
334-
if (!this.Effects.Any())
335-
{
336-
this.Effects.Add(new TouchAndPressEffect());
337-
}
340+
this.frmLayout.BackgroundColor = this.IsEnabled ? this.BackgroundColor : this.DisabledBackgroundColor;
341+
this.frmLayout.BorderColor = this.IsEnabled ? this.BorderColor : this.DisabledBorderColor;
338342
}
339343
break;
340344
}
@@ -345,7 +349,7 @@ public void ConsumeEvent(EventType gestureType)
345349
switch (gestureType)
346350
{
347351
case EventType.Pressing:
348-
if (this.IsEnabled && (this.Command == null || this.Command.CanExecute(this.CommandParameter)))
352+
if (this.Animation != AnimationTypes.None && this.IsEnabled && (this.Command == null || this.Command.CanExecute(this.CommandParameter)))
349353
{
350354
Task.Run(async () =>
351355
{
@@ -367,17 +371,20 @@ public void ConsumeEvent(EventType gestureType)
367371
this.Command.Execute(this.CommandParameter);
368372
}
369373

370-
Task.Run(async () =>
374+
if (this.Animation != AnimationTypes.None)
371375
{
372-
if (this.Animation == AnimationTypes.Fade)
373-
{
374-
await this.FadeTo(1, 100);
375-
}
376-
else
376+
Task.Run(async () =>
377377
{
378-
await this.ScaleTo(1, 100);
379-
}
380-
});
378+
if (this.Animation == AnimationTypes.Fade)
379+
{
380+
await this.FadeTo(1, 100);
381+
}
382+
else
383+
{
384+
await this.ScaleTo(1, 100);
385+
}
386+
});
387+
}
381388
break;
382389
default:
383390
throw new ArgumentOutOfRangeException(nameof(gestureType), gestureType, null);

src/MaterialDesignControls/Controls/MaterialFlatButton.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ public class MaterialFlatButton : MaterialButton
77
{
88
public MaterialFlatButton()
99
{
10-
this.button.BackgroundColor = Color.Transparent;
11-
this.button.BorderColor = Color.Transparent;
10+
this.frmLayout.BackgroundColor = Color.Transparent;
11+
this.frmLayout.BorderColor = Color.Transparent;
1212
}
1313
}
1414
}

src/MaterialDesignControls/Controls/MaterialOutlineButton.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,7 @@ public class MaterialOutlineButton : MaterialButton
77
{
88
public MaterialOutlineButton()
99
{
10-
this.button.BackgroundColor = Color.Transparent;
11-
this.button.BorderWidth = 1;
10+
this.frmLayout.BackgroundColor = Color.Transparent;
1211
}
1312
}
1413
}

0 commit comments

Comments
 (0)