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 @@
-
-
-
+
+
+
-
-
+
diff --git a/Samples/ButtonXamlPageSample.cs b/Samples/ButtonXamlPageSample.cs
deleted file mode 100644
index 4b95f6d..0000000
--- a/Samples/ButtonXamlPageSample.cs
+++ /dev/null
@@ -1,17 +0,0 @@
-using System;
-using Ooui;
-using Xamarin.Forms;
-
-namespace Samples
-{
- public class ButtonXamlPageSample : ISample
- {
- public string Title => "Xamarin.Forms Button XAML";
-
- public Ooui.Element CreateElement ()
- {
- var page = new ButtonXaml.ButtonXamlPage ();
- return page.GetOouiElement ();
- }
- }
-}
diff --git a/Samples/DisplayAlertSample.xaml b/Samples/DisplayAlertSample.xaml
new file mode 100644
index 0000000..77fa509
--- /dev/null
+++ b/Samples/DisplayAlertSample.xaml
@@ -0,0 +1,13 @@
+
+
+
+
+
+
+
+
+
diff --git a/Samples/DisplayAlertSample.xaml.cs b/Samples/DisplayAlertSample.xaml.cs
new file mode 100644
index 0000000..5c2ee1d
--- /dev/null
+++ b/Samples/DisplayAlertSample.xaml.cs
@@ -0,0 +1,29 @@
+using Ooui;
+using System;
+
+using Xamarin.Forms;
+using Xamarin.Forms.Xaml;
+
+namespace Samples
+{
+ [XamlCompilation(XamlCompilationOptions.Compile)]
+ public partial class DisplayAlertSample : ContentPage
+ {
+ public DisplayAlertSample ()
+ {
+ InitializeComponent ();
+ }
+
+ public async void OnButtonClicked(object sender, EventArgs args)
+ {
+ var result = await DisplayAlert("Alert Message", "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Integer nec odio. Praesent libero. Sed cursus ante dapibus diam. Sed nisi. Nulla quis sem at nibh elementum imperdiet. Duis sagittis ipsum. Praesent mauris. Fusce nec tellus sed augue semper porta. Mauris massa.", "YES", "NO");
+ await DisplayAlert("Alert Response", $"You selected value: {result}", "OK");
+ }
+
+ public void Publish()
+ {
+ var sample = new XamlPageSample();
+ UI.Publish("/display-alert", sample.CreateElement(this));
+ }
+ }
+}
diff --git a/Samples/Program.cs b/Samples/Program.cs
index ee406c6..afff463 100644
--- a/Samples/Program.cs
+++ b/Samples/Program.cs
@@ -28,9 +28,10 @@ namespace Samples
new ButtonSample ().Publish ();
new TodoSample ().Publish ();
new DrawSample ().Publish ();
- new FilesSample ().Publish ();
+ new FilesSample ().Publish ();
+ new DisplayAlertSample ().Publish ();
- UI.Present ("/todo");
+ UI.Present ("/display-alert");
Console.ReadLine ();
}
diff --git a/Samples/Samples.csproj b/Samples/Samples.csproj
index e9de299..883c5f7 100644
--- a/Samples/Samples.csproj
+++ b/Samples/Samples.csproj
@@ -17,10 +17,19 @@
+
+
+ Code
+
+
+
MSBuild:UpdateDesignTimeXaml
+
+ MSBuild:UpdateDesignTimeXaml
+
diff --git a/Samples/XamlPageSample.cs b/Samples/XamlPageSample.cs
new file mode 100644
index 0000000..ae6b365
--- /dev/null
+++ b/Samples/XamlPageSample.cs
@@ -0,0 +1,14 @@
+using Xamarin.Forms;
+
+namespace Samples
+{
+ public class XamlPageSample
+ {
+ public string Title => "Xamarin.Forms Button XAML";
+
+ public Ooui.Element CreateElement (Page page)
+ {
+ return page.GetOouiElement ();
+ }
+ }
+}