This repository has been archived by the owner on May 1, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
/
Copy pathProgressBarRenderer.cs
67 lines (54 loc) · 1.61 KB
/
ProgressBarRenderer.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
using System.ComponentModel;
using UIKit;
using SizeF = CoreGraphics.CGSize;
namespace Xamarin.Forms.Platform.iOS
{
public class ProgressBarRenderer : ViewRenderer<ProgressBar, UIProgressView>
{
[Internals.Preserve(Conditional = true)]
public ProgressBarRenderer()
{
}
public override SizeF SizeThatFits(SizeF size)
{
// progress bar will size itself to be as wide as the request, even if its inifinite
// we want the minimum need size
var result = base.SizeThatFits(size);
return new SizeF(10, result.Height);
}
protected override void OnElementChanged(ElementChangedEventArgs<ProgressBar> e)
{
if (e.NewElement != null)
{
if (Control == null)
SetNativeControl(new UIProgressView(UIProgressViewStyle.Default));
UpdateProgressColor();
UpdateProgress();
}
base.OnElementChanged(e);
}
protected override void OnElementPropertyChanged(object sender, PropertyChangedEventArgs e)
{
base.OnElementPropertyChanged(sender, e);
if (e.PropertyName == ProgressBar.ProgressColorProperty.PropertyName)
UpdateProgressColor();
else if (e.PropertyName == ProgressBar.ProgressProperty.PropertyName)
UpdateProgress();
}
protected override void SetBackgroundColor(Color color)
{
base.SetBackgroundColor(color);
if (Control == null)
return;
Control.TrackTintColor = color != Color.Default ? color.ToUIColor() : null;
}
void UpdateProgressColor()
{
Control.ProgressTintColor = Element.ProgressColor == Color.Default ? null : Element.ProgressColor.ToUIColor();
}
void UpdateProgress()
{
Control.Progress = (float)Element.Progress;
}
}
}