Maui icon indicating copy to clipboard operation
Maui copied to clipboard

[BUG][Regression][8.0.1] TouchBevavior binding not working in a CollectionView

Open tranb3r opened this issue 1 year ago • 15 comments
trafficstars

Is there an existing issue for this?

  • [X] I have searched the existing issues

Did you read the "Reporting a bug" section on Contributing file?

  • [X] I have read the "Reporting a bug" section on Contributing file: https://github.com/CommunityToolkit/Maui/blob/main/CONTRIBUTING.md#reporting-a-bug

Current Behavior

TouchBehavior binding is not working in a CollectionView when using 8.0.1. It seems like the wrong item is binded after the CollectionView is scrolled a bit (recycling issue?). This is a regression in 8.0.1. No issue in 8.0.0.

I mentionned this issue in the PR but so far nobody has reacted. https://github.com/CommunityToolkit/Maui/pull/1791#issuecomment-2039825987

Expected Behavior

I expect it to work the same as in 8.0.0.

Steps To Reproduce

  1. Open and run solution from repro.
  2. Tap on any item. Scroll the CollectionView. Tap again any item.
  3. At some point (probably after recycling of views), the alert shows that the TouchBehavior binds to the wrong item.

untitled.webm

Link to public reproduction project repository

https://github.com/tranb3r/Issues/tree/main/MauiAppMct801TouchBehavior

Environment

- .NET MAUI CommunityToolkit:8.0.1
- OS:Android
- .NET MAUI:8.0.14

tranb3r avatar Apr 08 '24 07:04 tranb3r

+1, not working with Collection View data template.

ac-lap avatar Apr 13 '24 12:04 ac-lap

@tranb3r thanks for you repo. Friendly asking, when provide a repo, please make sure it has all platforms on it, that way we can test it better <3

pictos avatar Apr 14 '24 23:04 pictos

My TouchBehavior in a CollectionView Data template doesn't seem to be performing any animations either.

        <DataTemplate x:Key="CustomModeTemplate">
            <components:ShadowFrame x:DataType="models:CustomModeCollectionItem"
                                    Padding="0"
                                    x:Name="Element"
                                    AutomationId="{Binding Title}"
                                    Grid.Row="{Binding GridRow}"
                                    Grid.Column="{Binding GridColumn}"
                                    HeightRequest="{Binding Source={x:Reference Element}, Path=Width}">
                <components:ShadowFrame.Behaviors>
                    <mct:TouchBehavior DefaultAnimationDuration="250"
                                       DefaultAnimationEasing="{x:Static Easing.SpringOut}"
                                       PressedScale=".95"
                                       CommandParameter="{Binding Index}"
                                       Command="{Binding TappedCommand, Source={x:Reference ThisView}}" />
...

For example the shadowFrame in the example above does not change its scale.

Note this is only on Android. It works fine on iOS.

Toolkit version 8.0.1

Hackmodford avatar Apr 16 '24 16:04 Hackmodford

@Hackmodford this is another problem, please open a new issue with a sample project that reproduce the bug

pictos avatar Apr 17 '24 00:04 pictos

Any update?

tranb3r avatar Apr 29 '24 06:04 tranb3r

@jfversluis 8.0.0 was released a month ago, immediately hot-fixed with 8.0.1 which introduced this regression, and now there is a new major release 9.0.0, but still without a fix for this regression. Is there any good reason to keep the hot-fix introduced in 8.0.1? If it cannot be fixed, why not simply rollback it?

tranb3r avatar May 03 '24 08:05 tranb3r

8.0.1 didn't just introduce a regression, it fixed a very important thing as well, which might have this side-effect. I'm sorry you're experiencing that, but the fix in 8.0.1 is too important to roll back. Most notably, its a breaking change to, so rolling it back and reintroducing it later will cause a lot of frustration with our users.

If there is nothing that you need in 8.0.1 and 9.0.0, you can stick to 8.0.0 for now until we get this issue resolved.

jfversluis avatar May 03 '24 08:05 jfversluis

I thought the idea in 8.0.1 was to automatically set the bindingcontext to behaviors, which is something convenient but not absolutely mandatory. Maybe I misunderstood something. I'll stick to 8.0.0 for now. Thanks.

tranb3r avatar May 03 '24 08:05 tranb3r

@brminnick is probably the one you want to talk to. Maybe for a more direct discussion you can join the Discord server to discuss details.

jfversluis avatar May 03 '24 08:05 jfversluis

Any workarounds? I'm trying to get rid of my custom port of Maui.TouchEffect in favor of this but having problems...

phunkeler avatar May 17 '24 01:05 phunkeler

@phunkeler

This is my current workaround. Just add a TapGestureRecognizer with the command instead of using the TouchBehavior.

                                <!-- There is currently a bug in the touch behavior that causes commands to not be bound correctly in Android. Community Tooklit version 8.0.1 -->
                                <Border.GestureRecognizers>
                                    <TapGestureRecognizer Command="{Binding Command}"/>
                                </Border.GestureRecognizers>
                                <Border.Behaviors>
                                    <mct:TouchBehavior DefaultAnimationDuration="250"
                                                       DefaultAnimationEasing="{x:Static Easing.SpringOut}"
                                                       PressedScale=".95" />
                                </Border.Behaviors>
                                ```

Hackmodford avatar May 20 '24 14:05 Hackmodford

@phunkeler

This is my current workaround. Just add a TapGestureRecognizer with the command instead of using the TouchBehavior.

                                <!-- There is currently a bug in the touch behavior that causes commands to not be bound correctly in Android. Community Tooklit version 8.0.1 -->
                                <Border.GestureRecognizers>
                                    <TapGestureRecognizer Command="{Binding Command}"/>
                                </Border.GestureRecognizers>
                                <Border.Behaviors>
                                    <mct:TouchBehavior DefaultAnimationDuration="250"
                                                       DefaultAnimationEasing="{x:Static Easing.SpringOut}"
                                                       PressedScale=".95" />
                                </Border.Behaviors>
                                ```

Sure, but this only works for a simple Tap, not for other gestures like LongPress, which is the reason why we're using TouchBehavior.

tranb3r avatar May 27 '24 08:05 tranb3r

@jfversluis I wonder if this is somehow related to this MAUI issue . I see the same issue for both TapGestures as well as the TouchBehavior and also on iOS.

borrmann avatar Jun 04 '24 16:06 borrmann

Any update?

tranb3r avatar Aug 16 '24 14:08 tranb3r

We plan on fixing this with a breaking change when we do a major-version bump to .NET 9

TheCodeTraveler avatar Aug 16 '24 14:08 TheCodeTraveler