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

CanvasView.Touch not firing all events on iOS #2722

Open
1 task done
nm4568 opened this issue Jan 20, 2024 · 2 comments
Open
1 task done

CanvasView.Touch not firing all events on iOS #2722

nm4568 opened this issue Jan 20, 2024 · 2 comments
Labels

Comments

@nm4568
Copy link

nm4568 commented Jan 20, 2024

Description

CanvasView.Touch is only fired on Pressed on iOS

Code

Minimal Reproducible Example - https://github.com/nm4568/SkiaSharpSamples

But, you can also share a short block of code here:

using SkiaSharp;
using SkiaSharp.Views.Maui;
using SKCanvasView = SkiaSharp.Views.Maui.Controls.SKCanvasView;

namespace SkiaSharpSample
{
    public partial class MainPage : ContentPage
    {
        SKBitmap skBitmap;

        public MainPage()
        {
            InitializeComponent();

            skCanvasView.EnableTouchEvents = true;
            skCanvasView.PaintSurface += View_PaintSurface;
            skCanvasView.Touch += SkCanvasView_Touch;
        }

        protected override void OnAppearing()
        {
            base.OnAppearing();

            // Load and render a PNG image using SkiaSharp
            RenderSkiaSharpImage();
        }

        private void RenderSkiaSharpImage()
        {
            // Get the stream of the embedded resource
            var stream = typeof(MainPage).Assembly.GetManifestResourceStream("SkiaSharpSample.Resources.Images.dotnet_bot.png");

            // Create a SKBitmap from the stream
            skBitmap = SKBitmap.Decode(stream);

        }

        private void SkCanvasView_Touch(object? sender, SkiaSharp.Views.Maui.SKTouchEventArgs e)
        {
            switch (e.ActionType)
            {
                case SKTouchAction.Entered:
                    DebugLabel.Text = "Entered";
                    break;
                case SKTouchAction.Pressed:
                    DebugLabel.Text = "Pressed";
                    break;
                case SKTouchAction.Moved:
                    DebugLabel.Text = "Moved";
                    break;
                case SKTouchAction.Released:
                    DebugLabel.Text = "Released";
                    break;
                case SKTouchAction.Cancelled:
                    DebugLabel.Text = "Canceled";
                    break;
                case SKTouchAction.Exited:
                    DebugLabel.Text = "Exited";
                    break;
            }

            // Invalidate the canvas to trigger a redraw
            ((SKCanvasView)sender).InvalidateSurface();
        }

        private void View_PaintSurface(object? sender, SkiaSharp.Views.Maui.SKPaintSurfaceEventArgs e)
        {
            // Get the SKCanvas from the event arguments
            var canvas = e.Surface.Canvas;

            // Clear the canvas
            canvas.Clear(SKColors.White);

            // Draw the SKBitmap onto the canvas
            canvas.DrawBitmap(skBitmap, new SKPoint(0, 0));
        }
    }
}

You can also share some XAML:

<?xml version="1.0" encoding="utf-8" ?>
<ContentPage 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="SkiaSharpSample.MainPage">
<StackLayout>
        <skia:SKCanvasView x:Name="skCanvasView" PaintSurface="View_PaintSurface" HorizontalOptions="FillAndExpand" VerticalOptions="FillAndExpand"/>
        <Label x:Name="DebugLabel"
               FontSize="20"
               HorizontalOptions="Center"
               VerticalOptions="End" />
    </StackLayout>
</ContentPage>

Expected Behavior

Events with all other ActionTypes should be fired.

Actual Behavior

CanvasView.Touch is only firing one ActionType on iOS - ActionType.Pressed.

Version of SkiaSharp

2.88.3 (Current)

Last Known Good Version of SkiaSharp

Other (Please indicate in the description)

IDE / Editor

Visual Studio (Windows)

Platform / Operating System

iOS

Platform / Operating System Version

iOS 17.2

Devices

iOS Simulator - iPhone 14 Pro Max

Relevant Screenshots

No response

Relevant Log Output

No response

Code of Conduct

  • I agree to follow this project's Code of Conduct
@pauldendulk
Copy link

We have this problem in Mapsui.

I would also be interested to hear about the roadmap of SkiaSharp touch. It seems to me a difficult problem to deal with touch on all the platforms, and there were some changes in the api in the past. Perhaps we should use the touch of the platform itself instead of SkiaSharp. Any advise is welcome.

@pauldendulk
Copy link

pauldendulk commented Feb 26, 2024

Heya! Just realized that your test needs to set e.Handled = true; at the end of the OnTouch handler. If you update the sample and it behaves correctly we have to investigate Mapsui again.

See: #334

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
Status: Ready For Work
Development

No branches or pull requests

2 participants