Switch to reusing renderers on Forms elements
This commit is contained in:
parent
5575578c2d
commit
4a51859da1
|
@ -16,16 +16,24 @@ namespace Xamarin.Forms
|
|||
Ooui.UI.Publish (path, () => lazyPage.Value);
|
||||
}
|
||||
|
||||
public static Ooui.Element CreateElement (this Xamarin.Forms.Page page)
|
||||
public static Ooui.Element GetOouiElement (this Xamarin.Forms.Page page)
|
||||
{
|
||||
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;
|
||||
|
||||
return CreateElement (page);
|
||||
}
|
||||
|
||||
static Ooui.Element CreateElement (this Xamarin.Forms.Page page)
|
||||
{
|
||||
if (!(page.RealParent is Application)) {
|
||||
var app = new DefaultApplication ();
|
||||
app.MainPage = page;
|
||||
}
|
||||
|
||||
var result = new Ooui.Forms.Platform ();
|
||||
result.SetPage (page);
|
||||
return result.Element;
|
||||
|
|
|
@ -7,9 +7,17 @@ namespace Samples
|
|||
{
|
||||
public string Title => "Xamarin.Forms BoxViewClock";
|
||||
|
||||
BoxViewClockPage page;
|
||||
|
||||
public Ooui.Element CreateElement ()
|
||||
{
|
||||
return new BoxViewClockPage ().CreateElement ();
|
||||
//
|
||||
// Always return the same page because the code never stops the timer
|
||||
// and we don't want to create an unlimited number of them.
|
||||
//
|
||||
if (page == null)
|
||||
page = new BoxViewClockPage ();
|
||||
return page.GetOouiElement ();
|
||||
}
|
||||
|
||||
class BoxViewClockPage : ContentPage
|
||||
|
|
|
@ -44,12 +44,12 @@ namespace Samples
|
|||
var page = MakePage ();
|
||||
page.Publish ("/xamarin-forms-shared");
|
||||
|
||||
Ooui.UI.Publish ("/xamarin-forms", () => MakePage ().CreateElement ());
|
||||
Ooui.UI.Publish ("/xamarin-forms", () => MakePage ().GetOouiElement ());
|
||||
}
|
||||
|
||||
public Ooui.Element CreateElement ()
|
||||
{
|
||||
return MakePage ().CreateElement ();
|
||||
return MakePage ().GetOouiElement ();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue