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.53k stars 540 forks source link

[BUG] [Android] Dissalow further propagation for touch events #937

Open FoggyFinder opened 5 years ago

FoggyFinder commented 5 years ago

Description

When SKCanvasView is placed inside, for example, ScrollViewer then touch events are intercepted even though e.Handled = args.Handled.

Here is a link to the SO topic with proper description of the issue:

ACTION_CANCEL while touching

And with advise how to handle it.

Code

With slight modification to demo app:

https://github.com/mattleibow/SkiaSharpDemo/tree/master/SkiaSharpDemo/SkiaSharpDemo

Add ListView to the bottom and Label to the top of the StackLayout:

    <ScrollView>
        <StackLayout>
            <Label Text="Some text" HorizontalOptions="Center" />
            <views:SKCanvasView HeightRequest="300"
                                WidthRequest="400"
                                HorizontalOptions="Center" 
                                PaintSurface="OnPainting" EnableTouchEvents="True" Touch="OnTouch" />
            <ListView  />
        </StackLayout>
    </ScrollView>

I also changed background color but it's doesn't related.

Expected Behavior

Content doesn't scroll when user drags inside of SKCanvasView.

Actual Behavior

It does scroll:

skDroid

Basic Information

Reproduction Link

Since it's very easy to modify demo I haven't uploaded MCVE anywhere. But I could if it's required.

charlesroddie commented 5 years ago

@axeluser can you look at a fix for this? We tried disabling the scrollview on initial touch (after your PR in Xamarin.Forms) but that doesn't prevent subsequent touch events from being eaten by the scrollview.

mattleibow commented 5 years ago

So, I had a look and tested a few things.

What I found was that UWP works in that as soon as you start drawing, it captures the pointer and won't scroll. This PR will fix it for Android.

I checked iOS and there is no easy way to prevent the bubbling of events, so it always scrolls. I fill that it is correct to stop scrolling, so we should probably fix iOS as well.

Not sure what Tizen, macOS, WPF will do.

But then again, maybe UWP is wrong. If you want to work with gestures and touch evens inside the canvas, you either disable the scroll on the scrollview, or you don't put the canvas inside the scrollview.

FoggyFinder commented 5 years ago

I can check WPF but not iOS since I don't have device or emulator. I've found this with quick search:

Stop ScrollView scrolling from child elements (works in Android but not iOS)

but I think there is easier and better way to achieve it.

mattleibow commented 5 years ago

I think the issue is there is a bug: https://github.com/xamarin/Xamarin.Forms/issues/8497

The correct way would be to track the touch events, and when you start dragging, you disable the scroll.

kevcrooks commented 5 years ago

Matching @FoggyFinder , we have the scrolling problem on Android. iOS appears to be working as expected for us though @mattleibow (clicking and dragging inside the box doesn't scroll, which is what we want)

I think if your fix works for Android, then that would work in our case on all the devices we've tested.

---As an update: We were previously using a PanGestureRecognizer rather than the native SkiaSharp ones, which explains why we saw iOS working ok with the scrolling. Having just tested with the native SkiaSharp touch, we also do see a problem on iOS

FoggyFinder commented 4 years ago

I think the issue is there is a bug: xamarin/Xamarin.Forms#8497

@mattleibow I see. Almost 3 weeks past without any responses and I have feeling that it won't be changed in foreseeable future. No, really, I understand why - ScrollOrientation.Neither was added relatively recently and there are much more important bugs to fix.

The correct way would be to track the touch events, and when you start dragging, you disable the scroll.

But currently, as far as I can tell, there is no such way, isn't it?

I do think having a fix (even temporary) much better than nothing.

vecalion commented 4 years ago

Did anyone find a workaround for this issue?

imuller commented 6 months ago

For .NET MAUI: https://github.com/dotnet/maui/discussions/18758