How to make pinch and Touched working using SkCanvasView

Hello,

i am added following code to get pinch and touch event working using SkCanvasView.

<views:SKCanvasView x:Name="canvas" PaintSurface="OnPaintSample" >
                <views:SKCanvasView.GestureRecognizers>
                    <PinchGestureRecognizer PinchUpdated="PinchGestureRecognizer_PinchUpdated" />
                </views:SKCanvasView.GestureRecognizers>
            </views:SKCanvasView>
            <Grid.Effects>
                <local:TouchEffect Capture="True"
                                TouchAction="OnTouchEffectAction" />
            </Grid.Effects>

i am geeting issue when i add both only pinch get working. but when i click on canvas touch event not trigger.
when i comment out pinch event then onlt touch event trigger.
can any one having solution how to make both event working simultaneously.
please give me solution.

Best Answer

Answers

  • sachinJsachinJ INMember ✭✭

    Hello All,

    i am creating one small app where image showing with canvas using SkCanvasView.
    here i am adding touch and pinch zoom. in both iOS and android.
    touch and pinch working fine in iOS but in android only pinch work not touch.

    here issue is touch working fine and pinch also but when both added at same time then
    only pinch zoom works but touch not get trigger.
    just check this code and if you get any idea why touch not working when adding pinch.
    after checking this code if it gets working then upload same so that i can use it.

    i am uploading code zip using git, here is url
    https://github.com/testpiph001/SkiaSharp_Touch_PinchZoom

  • sachinJsachinJ INMember ✭✭

    Hello All,

    anyone having solution to above issue/problem?

  • mattleibowmattleibow ZAXamarin Team Xamurai

    @sachinJ I was getting the same issue with my changes to SkiaSharp.Views.Forms. When I added touch events, they stopped the gestures from working on some platforms: iOS and Android.

    UWP and macOS work fine because they just fire off a bunch of events and come what may. Android requires that the user make a decision on whether to handle the event in the touch event. If the user chooses to handle the event, then he will get all the events and nothing gets to the gestures, if he chooses not to handle the event, then everything goes to the gestures. iOS can do both, but currently has a bug: https://github.com/xamarin/Xamarin.Forms/pull/990

    My work is mostly here: https://github.com/mono/SkiaSharp/pull/309, but I have added a few extra commits to tweak some more. I hope to release this soon, but I need to do a bit more testing.

  • mattleibowmattleibow ZAXamarin Team Xamurai

    @sachinJ I just wanted to let you know that I pushed out the release that has touch events: https://github.com/mono/SkiaSharp/releases/tag/v1.58.1

    <views:SKCanvasView ... EnableTouchEvents="True" Touch="OnTouch" />
    
    private void OnTouch(object sender, SKTouchEventArgs e)
    {
        // handle touch events
    }
    

    The EnableTouchEvents property is required to explicitly enable touch events. Right now there is a bug in Xamarin.Forms that will prevent the gesture recognizers from working at all if this is true, so I default to false. As soon as the fix goes live and stable, then I can change this to default to true.

  • LindsayMilesLindsayMiles CAMember ✭✭✭
    edited November 2017

    @mattleibow, any further news on this?

    I'm finding that if EnableTouchEvents="True":
    Android
    On a touch, the event handler deals with the PRESSED and ignores the RELEASED part.
    On a second touch, the event handler fails as it seems to think the first touch is still being handled...
    iOS
    All works fine, including pressed, move or moving, release etc.

    EnableTouchEvents="False" or not set at all (default):
    Android events woks fine, iOS does not fire the touch event at all.

    Any resolution to this?

    I've tried setting this in code instead of in the xaml, within a #if iOS statement, set it to true else ignore.
    Android still works as the flag was not set to start with but hitting and setting that in code does nothing in iOS, still won't fire unless set to true in xaml.

    You might be able to see this in the SpinPaintShared sample off the Xamarin site. I cannot post my code but I know it works in either condition, just not both with that flag set or not set.

    Feedback would be great, thanks!

    Anyone?

    @CharlesPetzold.4997 ? your take on this?

  • mattleibowmattleibow ZAXamarin Team Xamurai

    @LindsayMiles if you are handling the event, you must also set the Handled property:

    private void OnTouch(object sender, SKTouchEventArgs e)
    {
        // handle touch events
        e.Handled = true;
    }
    

    This is because you have to let the OS know that you are handling a particular event. If you don't set the property to true, the event is bubbled up to the parent and thus you won't get any further events.

  • LindsayMilesLindsayMiles CAMember ✭✭✭
    edited November 2017

    @mattleibow

    Hi Matt, yes, thanks, I realized I was missing that after much messing around.

    Looks like the EnableTouchEvent bug has been fixed too, all seems to be behaving now.

    Thanks for your response!

  • Conor.MurphyConor.Murphy GBMember ✭✭

    Was there any updates on this regrading touch and pinch working together?

  • DannykhreetDannykhreet USMember ✭✭

    Any updates ?

Sign In or Register to comment.