Add ActivityIndicatorRenderer

This commit is contained in:
Frank A. Krueger 2017-11-26 09:28:26 -08:00
parent ab546d0e28
commit 89652d8779
5 changed files with 65 additions and 7 deletions

View File

@ -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))]

View File

@ -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<ActivityIndicator, Div>
{
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<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";
}
}
}
}

View File

@ -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;
}
}

View File

@ -5,6 +5,7 @@
<ContentPage.Content>
<StackLayout>
<Label Text="Welcome to DisplayAlert Sample!" />
<ActivityIndicator x:Name="activity" />
<Button Text="Tap for Display Alert"
Clicked="OnButtonClicked" />
</StackLayout>

View File

@ -16,8 +16,10 @@ namespace Samples
public async void OnButtonClicked(object sender, EventArgs args)
{
activity.IsRunning = true;
var result = await DisplayAlert("Alert Message", "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Integer nec odio. Praesent libero. Sed cursus ante dapibus diam. Sed nisi. Nulla quis sem at nibh elementum imperdiet. Duis sagittis ipsum. Praesent mauris. Fusce nec tellus sed augue semper porta. Mauris massa.", "YES", "NO");
await DisplayAlert("Alert Response", $"You selected value: {result}", "OK");
activity.IsRunning = false;
}
}
}