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

50 lines
1.5 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
{
2023-03-17 08:08:32 +00:00
public static Ooui.UI Ui;
2017-11-09 21:03:56 +00:00
public static void Publish (this Xamarin.Forms.Page page, string path)
{
2023-03-17 08:08:32 +00:00
Ui.Publish (path, () => page.CreateElement ());
2017-11-09 21:03:56 +00:00
}
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);
2023-03-17 08:08:32 +00:00
Ui.Publish (path, () => lazyPage.Value);
2017-11-09 21:03:56 +00:00
}
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
((IPageController)page).SendAppearing ();
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
}