Ooui-tws-port/Ooui.Forms/PageExtensions.cs

49 lines
1.4 KiB
C#
Raw Normal View History

2017-11-09 06:21:05 +00:00
using System;
2017-11-09 07:57:04 +00:00
using Xamarin.Forms;
2017-11-09 07:12:59 +00:00
2017-11-09 07:57:04 +00:00
namespace Xamarin.Forms
2017-11-09 06:21:05 +00:00
{
2017-11-09 21:03:56 +00:00
public static class PageExtensions
{
2018-03-10 05:28:39 +00:00
#if !PCL
2017-11-09 21:03:56 +00:00
public static void Publish (this Xamarin.Forms.Page page, string path)
{
Ooui.UI.Publish (path, () => page.CreateElement ());
}
2017-11-09 07:12:59 +00:00
2017-11-09 21:03:56 +00:00
public static void PublishShared (this Xamarin.Forms.Page page, string path)
{
var lazyPage = new Lazy<Ooui.Element> ((() => page.CreateElement ()), true);
Ooui.UI.Publish (path, () => lazyPage.Value);
}
2018-03-10 05:28:39 +00:00
#endif
2017-11-09 07:12:59 +00:00
public static Ooui.Element GetOouiElement (this Xamarin.Forms.Page page)
2017-11-09 21:03:56 +00:00
{
if (!Xamarin.Forms.Forms.IsInitialized)
throw new InvalidOperationException ("call Forms.Init() before this");
var existingRenderer = Ooui.Forms.Platform.GetRenderer (page);
if (existingRenderer != null)
return existingRenderer.NativeView;
2017-11-09 07:12:59 +00:00
return CreateElement (page);
}
static Ooui.Element CreateElement (this Xamarin.Forms.Page page)
{
2017-11-09 21:03:56 +00:00
if (!(page.RealParent is Application)) {
var app = new DefaultApplication ();
app.MainPage = page;
}
var result = new Ooui.Forms.Platform ();
result.SetPage (page);
return result.Element;
}
2017-11-09 07:57:04 +00:00
2017-11-09 21:03:56 +00:00
class DefaultApplication : Application
{
}
}
2017-11-09 06:21:05 +00:00
}