From 2b0e1ce206b68ac034d4f1adb651ebf627baeb59 Mon Sep 17 00:00:00 2001 From: Andrew Hoefling Date: Fri, 17 Nov 2017 20:28:22 +0000 Subject: [PATCH] Platform now subscribes and unsubscribes to Alert Messages that come in from the Xamarin.Forms Message Center. Implemented a basic modal using the included bootstrap styles --- Ooui.Forms/Platform.cs | 95 ++++++++++++++++++++++++++++++++++++++---- 1 file changed, 87 insertions(+), 8 deletions(-) diff --git a/Ooui.Forms/Platform.cs b/Ooui.Forms/Platform.cs index 931d867..c603aa4 100644 --- a/Ooui.Forms/Platform.cs +++ b/Ooui.Forms/Platform.cs @@ -1,11 +1,12 @@ -using System; +using System; using System.Collections.Generic; using System.Threading.Tasks; using Ooui.Forms.Renderers; using Xamarin.Forms; using Xamarin.Forms.Internals; +using System.Web; -namespace Ooui.Forms +namespace Ooui.Forms { public class Platform : BindableObject, IPlatform, INavigation, IDisposable { @@ -31,6 +32,84 @@ namespace Ooui.Forms public Platform () { _renderer = new PlatformRenderer (this); + + MessagingCenter.Subscribe(this, Page.AlertSignalName, (Page sender, AlertArguments arguments) => + { + var alert = new Div + { + ClassName = "modal-dialog" + }; + + var content = new Div + { + ClassName = "modal-content" + }; + + var header = new Div + { + ClassName = "modal-header" + }; + + var closeButton = new Button + { + ClassName = "close" + }; + + closeButton.AppendChild(new Span(HttpUtility.HtmlDecode("×"))); + closeButton.Clicked += CloseAlert; + + var h4 = new Heading(4) + { + Text = arguments.Title + }; + + header.AppendChild(closeButton); + header.AppendChild(h4); + + content.AppendChild(header); + content.AppendChild(new Div() + { + ClassName = "modal-body", + Text = arguments.Message + }); + + if (!string.IsNullOrEmpty(arguments.Cancel)) + { + var footer = new Div() + { + ClassName = "modal-footer" + }; + + var cancel = new Button(arguments.Cancel) + { + ClassName = "btn btn-default" + }; + cancel.Clicked += CloseAlert; + + footer.AppendChild(cancel); + + if (!string.IsNullOrEmpty(arguments.Accept)) + { + var accept = new Button(arguments.Accept) + { + ClassName = "btn btn-default" + }; + accept.Clicked += CloseAlert; + + footer.AppendChild(accept); + } + + content.AppendChild(footer); + } + + alert.AppendChild(content); + _renderer.AppendChild(alert); + + void CloseAlert(object s, EventArgs e) + { + _renderer.RemoveChild(alert); + } + }); } void IDisposable.Dispose () @@ -70,10 +149,10 @@ namespace Ooui.Forms public SizeRequest GetNativeSize (VisualElement view, double widthConstraint, double heightConstraint) { - var renderView = GetRenderer (view); - if (renderView == null || renderView.NativeView == null) - return new SizeRequest (Size.Zero); - + var renderView = GetRenderer (view); + if (renderView == null || renderView.NativeView == null) + return new SizeRequest (Size.Zero); + return renderView.GetDesiredSize (widthConstraint, heightConstraint); } @@ -173,5 +252,5 @@ namespace Ooui.Forms { throw new NotImplementedException (); } - } -} + } +}