Ooui-tws-port/Ooui.Forms/Renderers/ActivityIndicatorRenderer.cs

68 lines
2.2 KiB
C#
Raw Normal View History

2017-11-26 17:28:06 +00:00
using System;
2017-11-26 17:28:26 +00:00
using System.ComponentModel;
using System.Linq;
using Xamarin.Forms;
2017-11-26 17:28:06 +00:00
namespace Ooui.Forms.Renderers
{
2017-11-26 17:28:26 +00:00
public class ActivityIndicatorRenderer : ViewRenderer<ActivityIndicator, Div>
2017-11-26 17:28:06 +00:00
{
2017-11-26 17:28:26 +00:00
public override SizeRequest GetDesiredSize (double widthConstraint, double heightConstraint)
2017-11-26 17:28:06 +00:00
{
2017-11-26 17:28:26 +00:00
var size = new Size (40, 20);
return new SizeRequest (size, size);
}
protected override void OnElementChanged (ElementChangedEventArgs<ActivityIndicator> e)
{
if (e.NewElement != null) {
if (Control == null) {
var p = new Div { ClassName = "progress" };
var pb = new Div { ClassName = "progress-bar progress-bar-striped" };
pb.SetAttribute ("role", "progressbar");
pb.SetAttribute ("aria-valuenow", "0");
pb.SetAttribute ("aria-valuemin", "0");
pb.SetAttribute ("aria-valuemax", "100");
pb.Style.Width = "0%";
p.AppendChild (pb);
SetNativeControl (p);
}
UpdateColor ();
UpdateIsRunning ();
}
base.OnElementChanged (e);
}
protected override void OnElementPropertyChanged (object sender, PropertyChangedEventArgs e)
{
base.OnElementPropertyChanged (sender, e);
if (e.PropertyName == ActivityIndicator.ColorProperty.PropertyName)
UpdateColor ();
else if (e.PropertyName == ActivityIndicator.IsRunningProperty.PropertyName)
UpdateIsRunning ();
}
void UpdateColor ()
{
}
void UpdateIsRunning ()
{
var pb = (Div)Control.Children[0];
if (Element.IsRunning) {
pb.SetAttribute ("aria-valuenow", "100");
pb.Style.Width = "100%";
pb.ClassName = "progress-bar progress-bar-striped active";
}
else {
pb.SetAttribute ("aria-valuenow", "0");
pb.Style.Width = "0%";
pb.ClassName = "progress-bar progress-bar-striped";
}
2017-11-26 17:28:06 +00:00
}
}
}