SkiaSharp icon indicating copy to clipboard operation
SkiaSharp copied to clipboard

SkiaSharp.Views.Maui.SkCanvasView is not drawing on physical iOS devices

Open whodges opened this issue 2 years ago • 5 comments

Discussed in https://github.com/mono/SkiaSharp/discussions/2293

Originally posted by whodges October 25, 2022 Hello,

I've been trying to get SkCanvasView working on my iPad, and I've run into the same problem as described here: https://github.com/mono/SkiaSharp/issues/341, but with MAUI. On Windows and in the simulators, the canvas in my sample app works (i.e., it paints and show up as a red square). On my physical iPad, the canvas never fires the PaintSurface event, and so ends up black. I can tell it's there at least because of the position of the 'Invalidate' button I added; it's just not drawing.

My MainPage.xaml:

<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             xmlns:skia="clr-namespace:SkiaSharp.Views.Maui.Controls;assembly=SkiaSharp.Views.Maui.Controls"
             x:Class="MauiSample.MainPage">

    <ScrollView>
        <VerticalStackLayout>

            <skia:SKCanvasView
                x:Name="SampleCanvas"
                EnableTouchEvents="true"
                Touch="SampleCanvas_Touch"
                PaintSurface="SampleCanvas_PaintSurface"
                HeightRequest="512"
                WidthRequest="512">
            </skia:SKCanvasView>

            <Button
                x:Name="InvalidateBtn"
                Text="Invalidate"
                SemanticProperties.Hint="Invalidates the canvas"
                Clicked="InvalidateBtn_Clicked"
                HorizontalOptions="Center" >
            </Button>

        </VerticalStackLayout>
    </ScrollView>

</ContentPage>

My MainPage.xaml.cs:

using SkiaSharp;
using SkiaSharp.Views.Maui;

namespace MauiSample;

public partial class MainPage : ContentPage
{
    public MainPage()
    {
        InitializeComponent();
    }

    private void SampleCanvas_Touch(object sender, SKTouchEventArgs e)
    {
        SampleCanvas.InvalidateSurface();
    }

    private void SampleCanvas_PaintSurface(object sender, SKPaintSurfaceEventArgs e)
    {
        e.Surface.Canvas.DrawColor(new SKColor(255, 0, 0));
        return;
    }

    private void InvalidateBtn_Clicked(object sender, EventArgs e)
    {
        SampleCanvas.InvalidateSurface();
    }
}

And I've called UseSkiaSharp() in the app builder.

For the record, the Touch event isn't firing on the iPad either (it does on Windows). I'm using Visual Studio Pro 17.4.0 Preview 4.0, and Skia.Views.Maui.Controls 2.88.3. Any insight is appreciated; perhaps I'm missing something obvious. Screenshots of my output:

Windows:

MAUI Canvas on Windows

iPad:

MAUI Canvas on iPad

EDIT: Fixed my crappy code block formatting.

whodges avatar Oct 26 '22 00:10 whodges

Same issue here on an iphone 8, iOS version 16. Did you find a potential workaround?

AlexanderSCK avatar Dec 08 '22 06:12 AlexanderSCK

Nope! No luck yet - I'll be circling back around to this in the coming week. Doesn't it suck when you find a post that describes exactly the same problem you're having, but has no actual answer? :)

whodges avatar Dec 09 '22 15:12 whodges

Yes exactly but nobody from Skia seems to want to help with this breaking issue.

AlexanderSCK avatar Dec 12 '22 09:12 AlexanderSCK

From:

https://github.com/beto-rodriguez/LiveCharts2/issues/800 https://github.com/Mapsui/Mapsui/issues/1872

Here is a workaround: https://github.com/beto-rodriguez/LiveCharts2/issues/800#issuecomment-1672992578

beto-rodriguez avatar Aug 18 '23 15:08 beto-rodriguez

Also broken on my MacBook running MacOS Sonoma. Did you ever find a fix?

Nebula-Developer avatar Apr 17 '24 12:04 Nebula-Developer