From ab546d0e280831f23d559e5b5a7a4999fd3f9f8d Mon Sep 17 00:00:00 2001 From: "Frank A. Krueger" Date: Sun, 26 Nov 2017 09:28:06 -0800 Subject: [PATCH 1/5] Add SetAttribute to Element --- .../Renderers/ActivityIndicatorRenderer.cs | 10 ++++++++++ Ooui/Client.js | 16 +++++++++++++++- Ooui/Element.cs | 10 ++++++++++ Ooui/EventTarget.cs | 6 ++++++ Ooui/Message.cs | 2 ++ 5 files changed, 43 insertions(+), 1 deletion(-) create mode 100644 Ooui.Forms/Renderers/ActivityIndicatorRenderer.cs diff --git a/Ooui.Forms/Renderers/ActivityIndicatorRenderer.cs b/Ooui.Forms/Renderers/ActivityIndicatorRenderer.cs new file mode 100644 index 0000000..8f7373c --- /dev/null +++ b/Ooui.Forms/Renderers/ActivityIndicatorRenderer.cs @@ -0,0 +1,10 @@ +using System; +namespace Ooui.Forms.Renderers +{ + public class ActivityIndicatorRenderer + { + public ActivityIndicatorRenderer () + { + } + } +} diff --git a/Ooui/Client.js b/Ooui/Client.js index 108fc35..e796069 100644 --- a/Ooui/Client.js +++ b/Ooui/Client.js @@ -84,7 +84,7 @@ function ooui (rootElementPath) { if (!resizeTimeout) { resizeTimeout = setTimeout(function() { resizeTimeout = null; - actualResizeHandler(); + resizeHandler(); }, 100); } } @@ -145,6 +145,17 @@ function msgSet (m) { if (debug) console.log ("Set", node, parts, value); } +function msgSetAttr (m) { + const id = m.id; + const node = getNode (id); + if (!node) { + console.error ("Unknown node id", m); + return; + } + node.setAttribute(m.k, m.v); + if (debug) console.log ("SetAttr", node, m.k, m.v); +} + function msgCall (m) { const id = m.id; const node = getNode (id); @@ -203,6 +214,9 @@ function processMessage (m) { case "set": msgSet (m); break; + case "setAttr": + msgSetAttr (m); + break; case "call": msgCall (m); break; diff --git a/Ooui/Element.cs b/Ooui/Element.cs index 8ba85e9..a7287d1 100644 --- a/Ooui/Element.cs +++ b/Ooui/Element.cs @@ -102,6 +102,16 @@ namespace Ooui Style.PropertyChanged += HandleStylePropertyChanged; } + public void SetAttribute (string attributeName, string value) + { + Send (new Message { + MessageType = MessageType.SetAttribute, + TargetId = Id, + Key = attributeName, + Value = value, + }); + } + void HandleStylePropertyChanged (object sender, PropertyChangedEventArgs e) { SendSet ("style." + Style.GetJsName (e.PropertyName), Style[e.PropertyName]); diff --git a/Ooui/EventTarget.cs b/Ooui/EventTarget.cs index 2f66139..a7be894 100644 --- a/Ooui/EventTarget.cs +++ b/Ooui/EventTarget.cs @@ -163,6 +163,12 @@ namespace Ooui state.Add (message); }); break; + case MessageType.SetAttribute: + UpdateStateMessages (state => { + state.RemoveAll (x => x.MessageType == MessageType.SetAttribute && x.Key == message.Key); + state.Add (message); + }); + break; case MessageType.Listen: AddStateMessage (message); break; diff --git a/Ooui/Message.cs b/Ooui/Message.cs index ae9ffb1..0498437 100644 --- a/Ooui/Message.cs +++ b/Ooui/Message.cs @@ -46,6 +46,8 @@ namespace Ooui Create, [EnumMember(Value = "set")] Set, + [EnumMember (Value = "setAttr")] + SetAttribute, [EnumMember(Value = "call")] Call, [EnumMember(Value = "listen")] From 89652d8779a7ecdcd765c7e14dc41cfb8e0f66d6 Mon Sep 17 00:00:00 2001 From: "Frank A. Krueger" Date: Sun, 26 Nov 2017 09:28:26 -0800 Subject: [PATCH 2/5] 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 @@