Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
SailDev opened this issue Apr 15, 2022 · 16 comments

Comments

@SailDev
Copy link

SailDev commented Apr 15, 2022

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 dotnet/maui#6120

@mattleibow
Copy link
Contributor

What version of Visual Studio are you using?

@SailDev
Copy link
Author

SailDev commented Apr 15, 2022

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

@naweed
Copy link

naweed commented Jun 9, 2022

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
Copy link

naweed commented Jun 9, 2022

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

@egvijayanand
Copy link

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

@ibocon
Copy link

ibocon commented Dec 1, 2022

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

@yoshiask
Copy link

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
Copy link

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.

@Niv2023
Copy link

Niv2023 commented Jul 7, 2023

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 with seems to work with both Android and IOS

@Niv2023
Copy link

Niv2023 commented Jul 7, 2023

I have placed under a ContentView....

@JoacimWall
Copy link

JoacimWall commented Sep 26, 2023

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

@sps014
Copy link

sps014 commented Nov 7, 2023

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

@VNGames
Copy link

VNGames commented Dec 4, 2023

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
Copy link

VNGames commented Dec 10, 2023

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.

@vladtrabl
Copy link

I had the same problem. I called InvalidateSurface intermittently with System.Timer and on IOS it doesn't call OnPaintSurface. MainThread.BeginInvokeOnMainThread(InvalidateSurface) solves this problem.

@5CoJL
Copy link

5CoJL commented Aug 20, 2024

I'm facing the same issue, solely for iOS as well, and none of the workarounds here work.
I am building with Pair to Mac using the Remote Device. I have tried MainThread.BeginInvokeOnMainThread(() => mySkCanvasView.InvalidateSurface()); to no avail.

Android works perfectly fine.

Edit: Removing VerticalOptions and HorizontalOptions in the XAML of my SKCanvasView worked, my bad.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: No status
Development

No branches or pull requests