Added ViewRepresentable for Mac.

This commit is contained in:
Jon Lipsky 2019-07-11 11:19:32 -05:00
Родитель 524fd5a388
Коммит 4971a59481
4 изменённых файлов: 59 добавлений и 2 удалений

Просмотреть файл

@ -0,0 +1,32 @@
using System;
using UIKit;
// ReSharper disable ClassNeverInstantiated.Global
// ReSharper disable MemberCanBePrivate.Global
namespace HotUI.iOS
{
public class ViewRepresentableHandler : AbstractHandler<ViewRepresentable, UIView>
{
public static readonly PropertyMapper<ViewRepresentable> Mapper = new PropertyMapper<ViewRepresentable>(ViewHandler.Mapper)
{
[nameof(ViewRepresentable.Data)] = MapDataProperty
};
public ViewRepresentableHandler() : base(Mapper)
{
}
protected override UIView CreateView()
{
return VirtualView?.MakeView() as UIView;
}
public static void MapDataProperty(IViewHandler viewHandler, ViewRepresentable virtualView)
{
var data = virtualView.Data;
virtualView.UpdateView?.Invoke(viewHandler.NativeView, data);
}
}
}

Просмотреть файл

@ -89,6 +89,8 @@
<Compile Include="Handlers\HStackHandler.cs" />
<Compile Include="Handlers\SpacerHandler.cs" />
<Compile Include="Services\MacFontService.cs" />
<Compile Include="UIViewRepresentable.cs" />
<Compile Include="Handlers\ViewRepresentableHandler.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\HotUI\HotUI.csproj">

Просмотреть файл

@ -25,9 +25,10 @@ namespace HotUI.Mac
Registrar.Handlers.Register<Image, ImageHandler> ();
Registrar.Handlers.Register<View, ViewHandler> ();
Registrar.Handlers.Register<ContentView, ContentViewHandler> ();
Registrar.Handlers.Register<ListView, ListViewHandler> ();
Registrar.Handlers.Register<ListView, ListViewHandler>();
Registrar.Handlers.Register<ViewRepresentable, ViewRepresentableHandler>();
Device.PerformInvokeOnMainThread = invoker.BeginInvokeOnMainThread;
Device.PerformInvokeOnMainThread = invoker.BeginInvokeOnMainThread;
Device.FontService = new MacFontService();
}
}

Просмотреть файл

@ -0,0 +1,22 @@
using System;
using AppKit;
namespace HotUI.Mac
{
public class NSViewRepresentable<T> : ViewRepresentable where T:NSView
{
public delegate void UpdateNSView(T view, object state);
public new Func<NSView> MakeView
{
get => () => base.MakeView?.Invoke() as T;
set => base.MakeView = () => value?.Invoke();
}
public new UpdateNSView UpdateView
{
get => (view, state) => base.UpdateView?.Invoke(view, state);
set => base.UpdateView = (view, state) => value?.Invoke(view as T, state);
}
}
}