Skip to content

[BUG] SKGLView doesn't repaint if it's in a TabBarΒ #2550

@noelbk

Description

@noelbk

Description

SKGLView doesn't repaint if it's in a TabBar.

Code

AppShell.xaml - puts the MainPage with the MySKGLView in a tab bar. When the tabs switch, the MySKGLView doesn't redraw

    <TabBar x:Name="SKGLViewTabs">
        <Tab Title="Tab1">
            <ShellContent
                Title="Home"
                ContentTemplate="{DataTemplate local:MainPage}"
                Route="MainPage" />
        </Tab>
        <Tab Title="Tab2">
        ...
        </Tab>
    </TabBar>

MainPage.xaml - contains the MySKGLView

<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             xmlns:local="clr-namespace:TestTabsMauiApp2"
             x:Class="TestTabsMauiApp2.MainPage">

    <ScrollView>
        <VerticalStackLayout
            Spacing="25"
            Padding="30,0"
            VerticalOptions="Center">

            <local:MySKGLView
                x:Name="MySKGLView1"
                SemanticProperties.Description="MySKGLView"
                HeightRequest="200"
                HorizontalOptions="Center"
            />
...

MySKGLView.cs - this draws a gradient filled rectangle usually

public class MySKGLView : SKGLView
{
    protected override void OnPaintSurface(SKPaintGLSurfaceEventArgs e)
    {
        base.OnPaintSurface(e);
        SKCanvas canvas = e.Surface.Canvas;
        canvas.Clear();
        SKRectI rect = new SKRectI(0, 0, (int)CanvasSize.Width, (int)CanvasSize.Height);

        // Create linear gradient from upper-left to lower-right
        using SKPaint paint = new SKPaint();
        paint.Shader = SKShader.CreateLinearGradient(
                            new SKPoint(rect.Left, rect.Top),
                            new SKPoint(rect.Right, rect.Bottom),
                            new SKColor[] { SKColors.Red, SKColors.Blue },
                            new float[] { 0, 1 },
                            SKShaderTileMode.Repeat);

        // Draw the gradient on the rectangle
        canvas.DrawRect(rect, paint);
    }
}

Expected Behavior

  1. Click Tab1, the SKGLView draws
  2. Click Tab2, the second tab draws
  3. Click back to Tab1, the SKGLView is blank. It should redraw [BUG]

Basic Information

  • Version with issue: SkiaSharp.Views.Maui.Controls.Compatibility 2.88.3
  • Last known good version: No previous version tested
  • IDE: Microsoft Visual Studio Community 2022 (64-bit) Version 17.6.5
  • Platform Target Frameworks:
    • Android: Android SDK Platform 33, Android 12.0 - S
  • Target Devices:
    • Android Emulator 32.1.14
    • Google Pixel 5 - API 31

Screenshots

Reproduction Link

TestTabsMauiApp2.zip

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    Status

    New

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions