mono / SkiaSharp

SkiaSharp is a cross-platform 2D graphics API for .NET platforms based on Google's Skia Graphics Library. It provides a comprehensive 2D API that can be used across mobile, server and desktop models to render images.
MIT License
4.14k stars 522 forks source link

[BUG] On iOS only, .NET 9.0 / SkiaSharp 3.0 SKCanvasView inside a custom control does not draw itself upon first appearance of the first page #2814

Open janne-hmp opened 1 month ago

janne-hmp commented 1 month ago

Description

On iOS in .NET 9.0 and SkiaSharp 3.0 Preview 2, in game GnollHack, SKCanvasView inside a custom control (called CustomImageButton) does not invalidate its canvas and draw itself when first entering the app on the first page of the app, resulting in a transparent picture, instead of intended graphics. If I open page on the top of the starting page, or interact with the control, then suddenly it properly draws itself. (Turning the screen from landscape to portrait or vice versa, keeps the transparent button, though.) On Android, the control works just fine. Other such buttons on other pages in iOS seem to work fine, so it seems to be something related to the behavior when entering / starting the app.

Code

https://github.com/hyvanmielenpelit/GnollHack

Here's the XAML of CustomImageButton for the sake of ease:

<?xml version="1.0" encoding="UTF-8"?>
<ContentView 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="GnollHackM.CustomImageButton">
  <ContentView.Content>
        <Grid x:Name="customGrid">
            <skia:SKCanvasView x:Name="customCanvasView" HorizontalOptions="FillAndExpand" VerticalOptions="FillAndExpand" EnableTouchEvents="false" PaintSurface="CustomCanvasView_PaintSurface" />
            <Button Text="" x:Name="customButton" Clicked="CustomButton_Clicked" BackgroundColor="Transparent" HorizontalOptions="FillAndExpand" VerticalOptions="FillAndExpand" />
        </Grid>
    </ContentView.Content>
</ContentView>

Expected Behavior

Both on iOS and Android, SkiaSharp draws intended button graphics for CustomImageButtons instead of a transparent bitmap when entering / starting the app.

Actual Behavior

On iOS, none of the background images of CustomImageButtons on MainPage get drawn when entering the page (first page in the app). If a page is opened above the buttons or some interaction with the buttons take place, the background is suddenly drawn. On Android, the controls work fine.

Version of SkiaSharp

3.x (Alpha)

Last Known Good Version of SkiaSharp

2.80.x (Deprecated)

IDE / Editor

Visual Studio (Windows)

Platform / Operating System

Android, iOS

Platform / Operating System Version

Android 14, iOS 17.3.1

Devices

Google Pixel 6a, iPad 11,7

Relevant Screenshots

ScreenWhenEnteringTheApp CorrectScreenAfterOpeningSettingsScreenAndComingBack

Relevant Log Output

No response

Code of Conduct

janne-hmp commented 1 month ago

This may also have something to do with the fact that these controls fade in using animation functionality on opacity at the start of the game. Perhaps SkiaSharp does not realize that on iOS and does not draw itself for that reason.