SkiaSharp icon indicating copy to clipboard operation
SkiaSharp copied to clipboard

[Maui] SkiaSharp OnPaintSurface not called on iOS device connected to Windows dev computer

Open SailDev opened this issue 2 years ago • 16 comments

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

SailDev avatar Apr 15 '22 08:04 SailDev

What version of Visual Studio are you using?

mattleibow avatar Apr 15 '22 15:04 mattleibow

Microsoft Visual Studio Community 2022 (64-bit) - Preview Version 17.2.0 Preview 3.0

SailDev avatar Apr 15 '22 15:04 SailDev

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.

naweed avatar Jun 09 '22 03:06 naweed

Strangely, it works from my M1 Mac. I have the issue with Intel Mac. May be this is an Intel x86 architecture thing.

naweed avatar Jun 09 '22 12:06 naweed

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

egvijayanand avatar Jun 09 '22 18:06 egvijayanand

Operating System

Windows 11 Pro 21H2 image

Visual Stuido

Microsoft Visual Studio Enterprise 2022 (64-bit) Version 17.4.1 image

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

windows

Android

android

iOS

Windows

ios

macOS

macOS - iOS (1)

Mac Catalyst

macOS - mac catalyst (1)

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));
	}
}

ibocon avatar Dec 01 '22 08:12 ibocon

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.

yoshiask avatar Jan 16 '23 16:01 yoshiask

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.

yoshiask avatar Jan 16 '23 17:01 yoshiask

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

Niv2023 avatar Jul 07 '23 11:07 Niv2023

I have placed under a ContentView....

Niv2023 avatar Jul 07 '23 11:07 Niv2023

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

JoacimWall avatar Sep 26 '23 07:09 JoacimWall

Same issue in MAUI .NET 8 rc 2 on Windows and Android also with StackLayout.

sps014 avatar Nov 07 '23 07:11 sps014

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.

VNGames avatar Dec 04 '23 19:12 VNGames

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.

VNGames avatar Dec 10 '23 11:12 VNGames