forked from xamarin/Xamarin.Forms
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMaterialStepperRenderer.cs
120 lines (96 loc) · 3.13 KB
/
MaterialStepperRenderer.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
#if __ANDROID_28__
using System.ComponentModel;
using Android.Content;
using Android.Views;
using Android.Widget;
using Xamarin.Forms;
using Xamarin.Forms.Material.Android;
using Xamarin.Forms.Platform.Android;
using AButton = Android.Widget.Button;
using MButton = Android.Support.Design.Button.MaterialButton;
namespace Xamarin.Forms.Material.Android
{
public class MaterialStepperRenderer : ViewRenderer<Stepper, LinearLayout>, IStepperRenderer
{
const int DefaultButtonSpacing = 4;
MButton _downButton;
MButton _upButton;
bool _inputTransparent;
public MaterialStepperRenderer(Context context) : base(context)
{
AutoPackage = false;
}
protected override LinearLayout CreateNativeControl()
{
return new LinearLayout(Context)
{
Orientation = Orientation.Horizontal,
Focusable = true,
DescendantFocusability = DescendantFocusability.AfterDescendants
};
}
protected override void OnElementChanged(ElementChangedEventArgs<Stepper> e)
{
base.OnElementChanged(e);
if (e.OldElement == null)
{
if (Control == null)
{
var layout = CreateNativeControl();
StepperRendererManager.CreateStepperButtons(this, out _downButton, out _upButton);
layout.AddView(_downButton, new LinearLayout.LayoutParams(LayoutParams.WrapContent, LayoutParams.MatchParent)
{
Weight = 1,
RightMargin = (int)(Context.ToPixels(DefaultButtonSpacing) / 2),
});
layout.AddView(_upButton, new LinearLayout.LayoutParams(LayoutParams.WrapContent, LayoutParams.MatchParent)
{
Weight = 1,
LeftMargin = (int)(Context.ToPixels(DefaultButtonSpacing) / 2),
});
SetNativeControl(layout);
}
}
StepperRendererManager.UpdateButtons(this, _downButton, _upButton);
UpdateInputTransparent();
}
protected override void OnElementPropertyChanged(object sender, PropertyChangedEventArgs e)
{
base.OnElementPropertyChanged(sender, e);
StepperRendererManager.UpdateButtons(this, _downButton, _upButton, e);
if (e.PropertyName == VisualElement.InputTransparentProperty.PropertyName)
UpdateInputTransparent();
}
void UpdateInputTransparent()
{
if (Element == null)
return;
_inputTransparent = Element.InputTransparent;
}
public override bool OnTouchEvent(MotionEvent e)
{
if (!Enabled || _inputTransparent)
return false;
return base.OnTouchEvent(e);
}
protected override void UpdateBackgroundColor()
{
// don't call base
}
// IStepperRenderer
Stepper IStepperRenderer.Element => Element;
AButton IStepperRenderer.UpButton => _upButton;
AButton IStepperRenderer.DownButton => _downButton;
AButton IStepperRenderer.CreateButton()
{
var button = new MButton(MaterialContextThemeWrapper.Create(Context), null, Resource.Attribute.materialOutlinedButtonStyle);
// the buttons are meant to be "square", but are usually wide,
// so, copy the vertical properties into the horizontal properties
button.SetMinimumWidth(button.MinimumHeight);
button.SetMinWidth(button.MinHeight);
button.SetPadding(button.PaddingTop, button.PaddingTop, button.PaddingBottom, button.PaddingBottom);
return button;
}
}
}
#endif