SkiaSharp
SkiaSharp copied to clipboard
[Maui] SkiaSharp OnPaintSurface not called on iOS device connected to Windows dev computer
Description
InvalidateSurface does not trigger OnPaintSurface, when the app is deployed to an iOS device, directly connected to the Windows dev computer.
The problem does not occur, when the app is deployed to a remotely connected device via Mac build-host.
Maybe this info saves some time for someone.
Reference: Maui Issue https://github.com/dotnet/maui/issues/6120
What version of Visual Studio are you using?
Microsoft Visual Studio Community 2022 (64-bit) - Preview Version 17.2.0 Preview 3.0
I have the same issue. I am using VS for Mac 17.3 Preview. It works fine for Android and it correctly fires OnPaintSurface on InvalidateSurface, but on iOS, it is not calling OnPaintSurface.
Strangely, it works from my M1 Mac. I have the issue with Intel Mac. May be this is an Intel x86 architecture thing.
It's not getting invoked on any of the platforms (tried iOS, Android, and Windows) with both the recent stable (2.88.0) and preview (2.88.1-preview.63) release versions.
Tried with both XAML and C# definitions, there is no change in the result.
Working with .NET MAUI GA and VS2022 for Windows ver. 17.3.0 Preview 1.1
Operating System
Windows 11 Pro 21H2
Visual Stuido
Microsoft Visual Studio Enterprise 2022 (64-bit) Version 17.4.1
CS Project
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFrameworks>net7.0-ios</TargetFrameworks>
<PackageReference Include="SkiaSharp.Views.Maui.Controls" Version="2.88.3" />
</ItemGroup>
</Project>
Windows
Android
iOS
Windows
macOS
Mac Catalyst
Source Code
public sealed class PreviewView
: SKCanvasView
{
protected override void OnPaintSurface(SKPaintSurfaceEventArgs e)
{
base.OnPaintSurface(e);
using SKCanvas skCanvas = e.Surface.Canvas;
skCanvas.Clear();
skCanvas.DrawColor(SKColors.Wheat);
SKBitmap bitmap = _canvas.Paint(_paper);
skCanvas.DrawBitmap(bitmap, new SKPoint(0, 0));
}
}
I am also seeing this issue with 2.88.3, built with .NET MAUI 7 and Rider 2022.3.1. I can only test on Windows and Android, but OnPaintSurface
is never called on either platform.
It looks like this issue may be caused by placing the SKCanvasView
inside a StackLayout
. Placing it directly inside a ScrollView
, while of course doesn't scroll, does fire the PaintSurface
event and renders.
Had same issue now (VS 2022 17.6.3 and SkiaSharp 2.88.3) Spent quite some time to get it figured out. Herewith my finds
- SKCanvasView indeed doesn’t work as a StackLayout child
- It does work under a ScrollView, but the scrollview impacts the gesture events passed to the SKcanvasView (events gets 'cancelled' when 'dragging' vertically)
- Than I’ve placed under a FlexLayout which works great on Android (touch events properly passed to the child)…. But then it doesn't work on IOS ☹
- I have finally placed under a <ContentView> with seems to work with both Android and IOS
I have placed under a ContentView....
Any solution for this have the same problem on 8 rc1 and Mac m1 and on release off app to App Store. Same code work onAndriod
//Joacim
Same issue in MAUI .NET 8 rc 2 on Windows and Android also with StackLayout.
For me on Android it doesn't work when it is inside a grid and I set HorizontalOptions="center". Without it it works. If I try to wrap it into contentview or another grid to center it by centering a wrapper it also doesn't work. I use MeasureOverride to calculate size. It may affect. Overall it seems very unstable. I don't know whether the problem is in MAUI or SkiaSharp but this is a critical bug.
I solved all my problems on Android where OnPaintSurface wasn't called. Haven't tried iOS yet. I use MeasureOverride to calculate the size of the control based on some properties and available height. OnPaintSurface isn't called when HorizontalOptions="Center". Also it isn't called/or it is but calculation is wrong (I forgot) if you want for example to have a HeightRequest="200" on the control but Width being calculated based on Height inside MeasureOverride. MAUI will just call MeasureOverride with infinite constraint for both width and height instead of (Double.Infinite, 200) To solve this I have to wrap control into ContentView and set HeightRequest="200" for ContentView. If I want to center the control I also should center this ContentView instead of control itself.
It is like returning back 8 years when Xamarin was a chaos and such kind of hacks were needed for everything.