diff --git a/Ooui.Forms/DisplayAlert.cs b/Ooui.Forms/DisplayAlert.cs new file mode 100644 index 0000000..d5f22f5 --- /dev/null +++ b/Ooui.Forms/DisplayAlert.cs @@ -0,0 +1,114 @@ +using System.Web; +using Xamarin.Forms.Internals; + +namespace Ooui.Forms +{ + public class DisplayAlert + { + private readonly Button _closeButton; + private readonly Button _acceptButton; + private readonly Button _cancelButton; + + public DisplayAlert(AlertArguments arguments) + { + Element = new Div + { + ClassName = "modal-dialog" + }; + + var content = new Div + { + ClassName = "modal-content" + }; + + var header = new Div + { + ClassName = "modal-header" + }; + + _closeButton = new Button + { + ClassName = "close" + }; + + _closeButton.AppendChild(new Span(HttpUtility.HtmlDecode("×"))); + + 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" + }; + + _cancelButton = new Button(arguments.Cancel) + { + ClassName = "btn btn-default" + }; + _cancelButton.Clicked += (s, e) => SetResult(false); + + footer.AppendChild(_cancelButton); + + if (!string.IsNullOrEmpty(arguments.Accept)) + { + _acceptButton = new Button(arguments.Accept) + { + ClassName = "btn btn-default" + }; + + _acceptButton.Clicked += (s, e) => SetResult(true); + footer.AppendChild(_acceptButton); + } + + content.AppendChild(footer); + } + + + Element.AppendChild(content); + + void SetResult(bool result) + { + arguments.SetResult(result); + } + } + + public event TargetEventHandler Clicked + { + add + { + _closeButton.Clicked += value; + + if(_cancelButton != null) + _cancelButton.Clicked += value; + + if(_acceptButton != null) + _acceptButton.Clicked += value; + } + remove + { + _closeButton.Clicked -= value; + + if (_cancelButton != null) + _cancelButton.Clicked -= value; + + if (_acceptButton != null) + _acceptButton.Clicked -= value; + } + } + public Element Element { get; private set; } + } +} diff --git a/Ooui.Forms/Ooui.Forms.csproj b/Ooui.Forms/Ooui.Forms.csproj index 5c0c488..e081c10 100644 --- a/Ooui.Forms/Ooui.Forms.csproj +++ b/Ooui.Forms/Ooui.Forms.csproj @@ -15,7 +15,6 @@ - diff --git a/Ooui.Forms/Platform.cs b/Ooui.Forms/Platform.cs index 931d867..5295ac6 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,19 @@ namespace Ooui.Forms public Platform () { _renderer = new PlatformRenderer (this); + + MessagingCenter.Subscribe(this, Page.AlertSignalName, (Page sender, AlertArguments arguments) => + { + var alert = new DisplayAlert(arguments); + alert.Clicked += CloseAlert; + + _renderer.AppendChild(alert.Element); + + void CloseAlert(object s, EventArgs e) + { + _renderer.RemoveChild(alert.Element); + } + }); } void IDisposable.Dispose () @@ -70,10 +84,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 +187,5 @@ namespace Ooui.Forms { throw new NotImplementedException (); } - } -} + } +} diff --git a/Samples/ButtonXamlPage.xaml b/Samples/ButtonXamlPage.xaml index 2026370..02012d6 100755 --- a/Samples/ButtonXamlPage.xaml +++ b/Samples/ButtonXamlPage.xaml @@ -2,12 +2,12 @@ - - -