This commit is contained in:
Matthew Leibowitz 2016-09-15 17:51:13 +02:00
Родитель 5f9036af5d
Коммит 54c29900c1
4 изменённых файлов: 94 добавлений и 1 удалений

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

@ -0,0 +1,78 @@
using System;
using Xamarin.Forms;
using Xamarin.Forms.Platform.UWP;
using SKFormsView = SkiaSharp.Views.Forms.SKView;
using SKNativeView = SkiaSharp.Views.SKXamlCanvas;
[assembly: ExportRenderer(typeof(SKFormsView), typeof(SkiaSharp.Views.Forms.SKViewRenderer))]
namespace SkiaSharp.Views.Forms
{
internal class SKViewRenderer : ViewRenderer<SKFormsView, SKNativeView>
{
protected override void OnElementChanged(ElementChangedEventArgs<SKFormsView> e)
{
if (e.OldElement != null)
{
var oldController = (ISKViewController)e.OldElement;
// unsubscribe from events
oldController.SurfaceInvalidated -= OnSurfaceInvalidated;
}
if (e.NewElement != null)
{
var newController = (ISKViewController)e.NewElement;
// create the native view
var view = new InternalView(newController);
SetNativeControl(view);
// subscribe to events from the user
newController.SurfaceInvalidated += OnSurfaceInvalidated;
// paint for the first time
Control.Invalidate();
}
base.OnElementChanged(e);
}
protected override void Dispose(bool disposing)
{
// detach all events before disposing
var controller = (ISKViewController)Element;
if (controller != null)
{
controller.SurfaceInvalidated -= OnSurfaceInvalidated;
}
base.Dispose(disposing);
}
private void OnSurfaceInvalidated(object sender, EventArgs eventArgs)
{
// repaint the native control
Control.Invalidate();
}
private class InternalView : SKNativeView
{
private readonly ISKViewController controller;
public InternalView(ISKViewController controller)
{
this.controller = controller;
}
protected override void OnPaintSurface(SkiaSharp.Views.SKPaintSurfaceEventArgs e)
{
base.OnPaintSurface(e);
// the control is being repainted, let the user know
controller.OnPaintSurface(new SKPaintSurfaceEventArgs(e.Surface, e.Info));
}
}
}
}

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

@ -108,6 +108,7 @@
</ItemGroup>
<ItemGroup>
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="SKViewRenderer.cs" />
<EmbeddedResource Include="Properties\SkiaSharp.Views.Forms.UWP.rd.xml" />
</ItemGroup>
<Import Project="..\SkiaSharp.Views.Forms.Shared\SkiaSharp.Views.Forms.Shared.projitems" Label="Shared" />

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

@ -0,0 +1,11 @@
<?xml version="1.0" encoding="utf-8" standalone="no"?>
<Project ToolsVersion="14.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup Condition="'$(NuGetPackageRoot)' == ''">
<NuGetPackageRoot>$(UserProfile)\.nuget\packages\</NuGetPackageRoot>
</PropertyGroup>
<ImportGroup>
<Import Project="$(NuGetPackageRoot)\SkiaSharp\1.54.0.1\build\uap10.0\SkiaSharp.targets" Condition="Exists('$(NuGetPackageRoot)\SkiaSharp\1.54.0.1\build\uap10.0\SkiaSharp.targets')" />
<Import Project="$(NuGetPackageRoot)\SkiaSharp.Views\1.54.0.1-beta1\build\uap10.0\SkiaSharp.Views.targets" Condition="Exists('$(NuGetPackageRoot)\SkiaSharp.Views\1.54.0.1-beta1\build\uap10.0\SkiaSharp.Views.targets')" />
<Import Project="$(NuGetPackageRoot)\Xamarin.Forms\2.3.0.49\build\portable-win+net45+wp80+win81+wpa81+MonoAndroid10+MonoTouch10+Xamarin.iOS10\Xamarin.Forms.targets" Condition="Exists('$(NuGetPackageRoot)\Xamarin.Forms\2.3.0.49\build\portable-win+net45+wp80+win81+wpa81+MonoAndroid10+MonoTouch10+Xamarin.iOS10\Xamarin.Forms.targets')" />
</ImportGroup>
</Project>

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

@ -1,6 +1,9 @@
{
"dependencies": {
"Microsoft.NETCore.UniversalWindowsPlatform": "5.1.0"
"Microsoft.NETCore.UniversalWindowsPlatform": "5.1.0",
"SkiaSharp": "1.54.0.1",
"SkiaSharp.Views": "1.54.0.1-beta1",
"Xamarin.Forms": "2.3.0.49"
},
"frameworks": {
"uap10.0": {}