SkiaSharp
SkiaSharp copied to clipboard
CanvasView.Touch not firing all events on iOS
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
- [X] I agree to follow this project's Code of Conduct
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.
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: https://github.com/mono/SkiaSharp/issues/334