From 89652d8779a7ecdcd765c7e14dc41cfb8e0f66d6 Mon Sep 17 00:00:00 2001 From: "Frank A. Krueger" Date: Sun, 26 Nov 2017 09:28:26 -0800 Subject: [PATCH] Add ActivityIndicatorRenderer --- Ooui.Forms/Exports.cs | 1 + .../Renderers/ActivityIndicatorRenderer.cs | 61 ++++++++++++++++++- Ooui.Forms/Renderers/ViewRenderer.cs | 7 +-- Samples/DisplayAlertPage.xaml | 1 + Samples/DisplayAlertPage.xaml.cs | 2 + 5 files changed, 65 insertions(+), 7 deletions(-) diff --git a/Ooui.Forms/Exports.cs b/Ooui.Forms/Exports.cs index c8f3f60..8ad9c7e 100644 --- a/Ooui.Forms/Exports.cs +++ b/Ooui.Forms/Exports.cs @@ -5,6 +5,7 @@ using Xamarin.Forms; using Xamarin.Forms.Internals; [assembly: Dependency (typeof (ResourcesProvider))] +[assembly: ExportRenderer (typeof (ActivityIndicator), typeof (ActivityIndicatorRenderer))] [assembly: ExportRenderer (typeof (BoxView), typeof (BoxRenderer))] [assembly: ExportRenderer (typeof (Button), typeof (ButtonRenderer))] [assembly: ExportRenderer (typeof (Entry), typeof (EntryRenderer))] diff --git a/Ooui.Forms/Renderers/ActivityIndicatorRenderer.cs b/Ooui.Forms/Renderers/ActivityIndicatorRenderer.cs index 8f7373c..e2dec9d 100644 --- a/Ooui.Forms/Renderers/ActivityIndicatorRenderer.cs +++ b/Ooui.Forms/Renderers/ActivityIndicatorRenderer.cs @@ -1,10 +1,67 @@ using System; +using System.ComponentModel; +using System.Linq; +using Xamarin.Forms; + namespace Ooui.Forms.Renderers { - public class ActivityIndicatorRenderer + public class ActivityIndicatorRenderer : ViewRenderer { - public ActivityIndicatorRenderer () + public override SizeRequest GetDesiredSize (double widthConstraint, double heightConstraint) { + var size = new Size (40, 20); + return new SizeRequest (size, size); + } + + protected override void OnElementChanged (ElementChangedEventArgs 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"; + } } } } diff --git a/Ooui.Forms/Renderers/ViewRenderer.cs b/Ooui.Forms/Renderers/ViewRenderer.cs index 75dfb02..edbe129 100644 --- a/Ooui.Forms/Renderers/ViewRenderer.cs +++ b/Ooui.Forms/Renderers/ViewRenderer.cs @@ -100,11 +100,8 @@ namespace Ooui.Forms.Renderers public override void SetControlSize (Size size) { if (Control != null) { - //Control.Style.Position = "absolute"; - //Control.Style.Left = "0px"; - //Control.Style.Top = "0px"; - Control.Style.Width = size.Width + "px"; - Control.Style.Height = size.Height + "px"; + Control.Style.Width = size.Width; + Control.Style.Height = size.Height; } } diff --git a/Samples/DisplayAlertPage.xaml b/Samples/DisplayAlertPage.xaml index 8f3c57f..0caca42 100644 --- a/Samples/DisplayAlertPage.xaml +++ b/Samples/DisplayAlertPage.xaml @@ -5,6 +5,7 @@