Init Forms platform
This commit is contained in:
parent
12948ea170
commit
f06b57f240
|
@ -0,0 +1,97 @@
|
||||||
|
using System;
|
||||||
|
using System.Diagnostics;
|
||||||
|
using Xamarin.Forms;
|
||||||
|
using Xamarin.Forms.Internals;
|
||||||
|
using Ooui.Forms;
|
||||||
|
using System.IO;
|
||||||
|
using System.Reflection;
|
||||||
|
using System.Threading;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace Xamarin.Forms
|
||||||
|
{
|
||||||
|
public static class Forms
|
||||||
|
{
|
||||||
|
public static bool IsInitialized { get; private set; }
|
||||||
|
|
||||||
|
public static void Init ()
|
||||||
|
{
|
||||||
|
if (IsInitialized)
|
||||||
|
return;
|
||||||
|
IsInitialized = true;
|
||||||
|
|
||||||
|
Log.Listeners.Add (new DelegateLogListener ((c, m) => Trace.WriteLine (m, c)));
|
||||||
|
|
||||||
|
Device.SetIdiom (TargetIdiom.Desktop);
|
||||||
|
Device.PlatformServices = new OouiPlatformServices ();
|
||||||
|
Device.Info = new OouiDeviceInfo ();
|
||||||
|
|
||||||
|
Registrar.RegisterAll (new[] {
|
||||||
|
typeof(ExportRendererAttribute),
|
||||||
|
//typeof(ExportCellAttribute),
|
||||||
|
//typeof(ExportImageSourceHandlerAttribute),
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
class OouiDeviceInfo : DeviceInfo
|
||||||
|
{
|
||||||
|
public override Size PixelScreenSize => new Size (640, 480);
|
||||||
|
|
||||||
|
public override Size ScaledScreenSize => PixelScreenSize;
|
||||||
|
|
||||||
|
public override double ScalingFactor => 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
class OouiPlatformServices : IPlatformServices
|
||||||
|
{
|
||||||
|
public bool IsInvokeRequired => false;
|
||||||
|
|
||||||
|
public string RuntimePlatform => "Ooui";
|
||||||
|
|
||||||
|
public void BeginInvokeOnMainThread (Action action)
|
||||||
|
{
|
||||||
|
Task.Run (action);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Ticker CreateTicker ()
|
||||||
|
{
|
||||||
|
throw new NotImplementedException ();
|
||||||
|
}
|
||||||
|
|
||||||
|
public Assembly[] GetAssemblies ()
|
||||||
|
{
|
||||||
|
return AppDomain.CurrentDomain.GetAssemblies ();
|
||||||
|
}
|
||||||
|
|
||||||
|
public string GetMD5Hash (string input)
|
||||||
|
{
|
||||||
|
throw new NotImplementedException ();
|
||||||
|
}
|
||||||
|
|
||||||
|
public double GetNamedSize (NamedSize size, Type targetElementType, bool useOldSizes)
|
||||||
|
{
|
||||||
|
throw new NotImplementedException ();
|
||||||
|
}
|
||||||
|
|
||||||
|
public Task<Stream> GetStreamAsync (Uri uri, CancellationToken cancellationToken)
|
||||||
|
{
|
||||||
|
throw new NotImplementedException ();
|
||||||
|
}
|
||||||
|
|
||||||
|
public IIsolatedStorageFile GetUserStoreForApplication ()
|
||||||
|
{
|
||||||
|
throw new NotImplementedException ();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void OpenUriAction (Uri uri)
|
||||||
|
{
|
||||||
|
throw new NotImplementedException ();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void StartTimer (TimeSpan interval, Func<bool> callback)
|
||||||
|
{
|
||||||
|
throw new NotImplementedException ();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,10 +1,25 @@
|
||||||
using System;
|
using System;
|
||||||
|
|
||||||
namespace Ooui.Forms
|
namespace Ooui.Forms
|
||||||
{
|
{
|
||||||
public static class PageExtensions
|
public static class PageExtensions
|
||||||
{
|
{
|
||||||
|
public static void Publish (this Xamarin.Forms.Page page, string path)
|
||||||
|
{
|
||||||
|
UI.Publish (path, () => page.CreateElement ());
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void PublishShared (this Xamarin.Forms.Page page, string path)
|
||||||
|
{
|
||||||
|
var lazyPage = new Lazy<Element> ((() => page.CreateElement ()), true);
|
||||||
|
UI.Publish (path, () => lazyPage.Value);
|
||||||
|
}
|
||||||
|
|
||||||
public static Element CreateElement (this Xamarin.Forms.Page page)
|
public static Element CreateElement (this Xamarin.Forms.Page page)
|
||||||
{
|
{
|
||||||
|
if (!Xamarin.Forms.Forms.IsInitialized)
|
||||||
|
throw new InvalidOperationException ("call Forms.Init() before this");
|
||||||
|
|
||||||
throw new NotImplementedException ();
|
throw new NotImplementedException ();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -27,8 +27,9 @@ namespace Samples
|
||||||
new TodoSample ().Publish ();
|
new TodoSample ().Publish ();
|
||||||
new DrawSample ().Publish ();
|
new DrawSample ().Publish ();
|
||||||
new FilesSample ().Publish ();
|
new FilesSample ().Publish ();
|
||||||
|
new XamarinFormsSample ().Publish ();
|
||||||
|
|
||||||
UI.Present ("/files");
|
UI.Present ("/xamarin-forms");
|
||||||
|
|
||||||
Console.ReadLine ();
|
Console.ReadLine ();
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,8 +2,12 @@
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ProjectReference Include="..\Ooui\Ooui.csproj" />
|
<ProjectReference Include="..\Ooui\Ooui.csproj" />
|
||||||
|
<ProjectReference Include="..\Ooui.Forms\Ooui.Forms.csproj" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<PackageReference Include="Xamarin.Forms" Version="2.4.0.38779" />
|
||||||
|
</ItemGroup>
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<OutputType>Exe</OutputType>
|
<OutputType>Exe</OutputType>
|
||||||
<TargetFramework>netcoreapp2.0</TargetFramework>
|
<TargetFramework>netcoreapp2.0</TargetFramework>
|
||||||
|
|
|
@ -0,0 +1,36 @@
|
||||||
|
using System;
|
||||||
|
using Xamarin.Forms;
|
||||||
|
using Ooui.Forms;
|
||||||
|
|
||||||
|
namespace Samples
|
||||||
|
{
|
||||||
|
public class XamarinFormsSample
|
||||||
|
{
|
||||||
|
public void Publish ()
|
||||||
|
{
|
||||||
|
Forms.Init ();
|
||||||
|
|
||||||
|
var countLabel = new Label {
|
||||||
|
Text = "0",
|
||||||
|
};
|
||||||
|
var countButton = new Button {
|
||||||
|
};
|
||||||
|
countButton.Clicked += (sender, e) => {
|
||||||
|
var v = int.Parse (countLabel.Text);
|
||||||
|
countLabel.Text = (v + 1).ToString ();
|
||||||
|
};
|
||||||
|
var page = new ContentPage {
|
||||||
|
Content = new StackLayout {
|
||||||
|
Children = {
|
||||||
|
new Label { Text = "Hello World!" },
|
||||||
|
countLabel,
|
||||||
|
countButton,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
page.Publish ("/xamarin-forms");
|
||||||
|
page.PublishShared ("/xamarin-forms-shared");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue