Android uses a renderer, not events

This commit is contained in:
Matthew Leibowitz 2017-03-22 18:56:54 -04:00
Родитель 05f2fb2c4d
Коммит cb447a196a
1 изменённых файлов: 29 добавлений и 0 удалений

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

@ -38,7 +38,11 @@ namespace SkiaSharp.Views.Forms
if (Control != null)
{
var control = Control;
#if __ANDROID__
control.SetRenderer(null);
#else
control.PaintSurface -= OnPaintSurface;
#endif
}
if (e.NewElement != null)
@ -47,7 +51,11 @@ namespace SkiaSharp.Views.Forms
// create the native view
var view = CreateNativeControl();
#if __ANDROID__
view.SetRenderer(new Renderer(newController));
#else
view.PaintSurface += OnPaintSurface;
#endif
SetNativeControl(view);
// subscribe to events from the user
@ -96,7 +104,11 @@ namespace SkiaSharp.Views.Forms
var control = Control;
if (control != null)
{
#if __ANDROID__
control.SetRenderer(null);
#else
control.PaintSurface -= OnPaintSurface;
#endif
}
base.Dispose(disposing);
@ -127,5 +139,22 @@ namespace SkiaSharp.Views.Forms
// the control is being repainted, let the user know
controller?.OnPaintSurface(new SKPaintGLSurfaceEventArgs(e.Surface, e.RenderTarget));
}
#if __ANDROID__
private class Renderer : SKNativeView.ISKRenderer
{
private readonly ISKGLViewController controller;
public Renderer(ISKGLViewController controller)
{
this.controller = controller;
}
public void OnDrawFrame(SKSurface surface, GRBackendRenderTargetDesc renderTarget)
{
controller.OnPaintSurface(new SKPaintGLSurfaceEventArgs(surface, renderTarget));
}
}
#endif
}
}