From 7d1cf22fb632cf64fb11a7dda77d26275674faec Mon Sep 17 00:00:00 2001 From: Troy Stanger Date: Wed, 7 Nov 2018 10:33:51 -0600 Subject: [PATCH 1/5] Implemented button images as background images. --- Ooui.Forms/Renderers/ButtonRenderer.cs | 51 ++++++++++++++------------ Ooui/Style.cs | 13 ++++++- 2 files changed, 39 insertions(+), 25 deletions(-) diff --git a/Ooui.Forms/Renderers/ButtonRenderer.cs b/Ooui.Forms/Renderers/ButtonRenderer.cs index fc06700..d4c9857 100644 --- a/Ooui.Forms/Renderers/ButtonRenderer.cs +++ b/Ooui.Forms/Renderers/ButtonRenderer.cs @@ -110,32 +110,37 @@ namespace Ooui.Forms.Renderers Element.SetStyleFont (Element.FontFamily, Element.FontSize, Element.FontAttributes, Control.Style); } - void UpdateImage () + async void UpdateImage () { - //IImageSourceHandler handler; - //FileImageSource source = Element.Image; - //if (source != null && (handler = Internals.Registrar.Registered.GetHandlerForObject (source)) != null) { - // UIImage uiimage; - // try { - // uiimage = await handler.LoadImageAsync (source, scale: (float)UIScreen.MainScreen.Scale); - // } - // catch (OperationCanceledException) { - // uiimage = null; - // } - // Ooui.Button button = Control; - // if (button != null && uiimage != null) { - // button.SetImage (uiimage.ImageWithRenderingMode (UIImageRenderingMode.AlwaysOriginal), UIControlState.Normal); + IImageSourceHandler handler; + FileImageSource source = Element.Image; - // button.ImageView.ContentMode = UIViewContentMode.ScaleAspectFit; + if (source != null && + (handler = Xamarin.Forms.Internals.Registrar.Registered.GetHandler(source.GetType())) != null) + { + string uiimage; + try + { + uiimage = await handler.LoadImageAsync(source, scale: 1.0f); + } + catch (OperationCanceledException) + { + uiimage = null; + } - // ComputeEdgeInsets (Control, Element.ContentLayout); - // } - //} - //else { - // Control.SetImage (null, UIControlState.Normal); - // ClearEdgeInsets (Control); - //} - //((IVisualElementController)Element).NativeSizeChanged (); + var Button = Control; + if (Button != null && uiimage != null) + { + Button.Style.BackgroundImage = uiimage; + Button.Style.BackgroundPosition = "center"; + } + } + else + { + Control.Style.BackgroundImage = null; + Control.Style.BackgroundPosition = null; + } + ((IVisualElementController)Element).NativeSizeChanged (); } void UpdateText () diff --git a/Ooui/Style.cs b/Ooui/Style.cs index 5a83415..3460e22 100644 --- a/Ooui/Style.cs +++ b/Ooui/Style.cs @@ -32,9 +32,14 @@ namespace Ooui public Value BackgroundImage { get => this["background-image"]; - set => this["background-image"] = value; + set => this["background-image"] = AddUrl(value); } + public Value BackgroundPosition { + get => this["background-position"]; + set => this["background-position"] = value; + } + public Value BorderTopColor { get => this["border-top-color"]; set => this["border-top-color"] = value; @@ -425,7 +430,11 @@ namespace Ooui } return o.ToString (); } - + static string AddUrl(object val) + { + return String.Format("url('{0}')", val); + } + static string AddNumberUnits (object val, string units) { if (val == null) From 0d316279ec8504bbd1849625ba019ef952c2da9a Mon Sep 17 00:00:00 2001 From: Troy Stanger Date: Wed, 7 Nov 2018 10:41:29 -0600 Subject: [PATCH 2/5] Fix incorrect style when AddUrl is passed null --- Ooui/Style.cs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Ooui/Style.cs b/Ooui/Style.cs index 3460e22..1d41705 100644 --- a/Ooui/Style.cs +++ b/Ooui/Style.cs @@ -432,6 +432,8 @@ namespace Ooui } static string AddUrl(object val) { + if (val == null) + return null; return String.Format("url('{0}')", val); } From b29060fea5473cb7c4fb81d0ce4be08e8f1c1b3d Mon Sep 17 00:00:00 2001 From: Troy Stanger Date: Wed, 7 Nov 2018 11:20:39 -0600 Subject: [PATCH 3/5] Implemented actionsheets for Ooui.Forms. AddNumberUnits() should be called for margin values. --- Ooui.Forms/ActionSheet.cs | 100 ++++++++++++++++++++++++++++++++++++++ Ooui.Forms/Platform.cs | 13 +++++ Ooui/Style.cs | 16 +++--- 3 files changed, 121 insertions(+), 8 deletions(-) create mode 100644 Ooui.Forms/ActionSheet.cs diff --git a/Ooui.Forms/ActionSheet.cs b/Ooui.Forms/ActionSheet.cs new file mode 100644 index 0000000..d0e7ebc --- /dev/null +++ b/Ooui.Forms/ActionSheet.cs @@ -0,0 +1,100 @@ +using System; +using System.Collections.Generic; +using Xamarin.Forms.Internals; + +namespace Ooui.Forms +{ + public class ActionSheet + { + private readonly Button _cancelButton; + private readonly List