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

This commit is contained in:
Andrew Hoefling 2017-11-17 20:28:22 +00:00
parent 31170de0ed
commit 2b0e1ce206
1 changed files with 87 additions and 8 deletions

View File

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