maui icon indicating copy to clipboard operation
maui copied to clipboard

GestureRecognizers inhibit CollectionView Selection on Android

Open david-maw opened this issue 3 years ago • 6 comments

Description

In a CollectionView I use click to select an item and have a gesturerecognizer attached so as to be able to do other things in response to the click. A Windows build selects the item then calls the GestureRecognizer, on Android it does not select the item before calling the GestureRecognizer.

Steps to Reproduce

  1. Unzip the project from MAUIListEntry-TapGestureRecognizer.zip
  2. Cmpile and run it on Windows, click each item in the list in turn, you should see this: MauiListEntry-TapGestureRecognizer-Windows
  3. repeat on Android, this time clicking the items will do nothing and you'll just see this: MauiListEntry-TapGestureRecognizer-Android

Also, the default line spacing seems to be wildly different between Windows and Android.

Version with bug

Release Candidate 2 (current)

Last version that worked well

Unknown/Other

Affected platforms

Android, I was not able test on other platforms

Affected platform versions

Android 11

Did you find any workaround?

No

Relevant log output

No response

david-maw avatar Apr 29 '22 05:04 david-maw

verified repro on android with above project, vs 17.3.0 Preview 1.0 [32426.537.main].

kristinx0211 avatar Apr 29 '22 05:04 kristinx0211

still an issue on android with 17.3.0 Preview 2.0 [32507.29.main].

kristinx0211 avatar May 09 '22 07:05 kristinx0211

We've moved this issue to the Backlog milestone. This means that it is not going to be worked on for the coming release. We will reassess the backlog following the current release and consider this item at that time. To learn more about our issue management process and to have better expectation regarding different types of issues you can read our Triage Process.

ghost avatar Aug 30 '22 14:08 ghost

Verified this on Visual Studio Enterprise 17.6.0 Preview 4.0. This issue does not repro on Windows 11, but repro on Android emulator (13.0-API 33) with below Project: 6644.zip No response when clicking items on Android. NoResponse

XamlTest avatar Apr 25 '23 08:04 XamlTest

I hope this will get fixed soon, it has been over a year waiting and it is very important to use the CollectionView on Android. I want selection on single tap and navigation on 2 taps. This works easy on Windows but as the Android ignores selection when the GestureRecognizers are used for double tap it is useless.

StephenWin avatar Jul 25 '23 12:07 StephenWin

I have the same issue on MacCatalyst as well

EvoZ1310 avatar Jan 08 '24 17:01 EvoZ1310

Verified this on with VS Version 17.8.5

One bug prevents me from using Border so i switch to the suggested Layout. Then the next bug states i must use Border as the CollectionView wont generate a SelectedItem otherwise. So in the stalemate i switch to a TapGestureRecognizer to substitute for SelectedItem only to find this problem and i cant use it either. I spend as much time finding workaround for things rather than doing actual work. Sometimes im shocked Maui is a released product.

axa88 avatar Feb 04 '24 17:02 axa88

@axa88 So sadly for you mate 😞 But you can do a workaround that aways works for me. Instead of use the selection command of the CollectionView, place a gesture recognizer on the first view of the item template, then you can send the binding object itself as command paramenter. Then you don't a selected item property on your VM to watch the selected item on your CollectionView. It should be something like this:

<CollectionView
    ...
    SelectionMode="None">
    
    <CollectionView.ItemTemplate>
        <DataTemplate x:DataType="MyModelClass">
            <Frame>
                <Frame.GestureRecognizers>
                    <TapGestureRecognizer Command="{Binding Source={RelativeSource AncestorType={x:Type ContentPage}}, Path=BindingContext.ItemSelectedCommand}" CommandParameter="{Binding .}" />
                </Frame.GestureRecognizers>

                <Some components of the item layout/>
            </Frame>
        </DataTemplate>
    </CollectionView.ItemTemplate>
</CollectionView>

Basically the ideia is access the binding context of the entire ContentPage (via AncestorType) on the CollectionView item and call the command from there. That's not a very good code, but it's what is aways working for me. And don't forget to accept the model which is used on the template of CollectionView as parameter on the command:

private ICommand itemSelectedCommand;
public ICommand ItemSelectedCommand =>
    itemSelectedCommand ??= new Command<MyModelClass>((arg) => ItemSelectedCommandExecute(arg));

private void ItemSelectedCommandExecute(MyModelClass selected)
{
    ...
}

Hope that helps you.

wesleykuhn avatar Feb 07 '24 15:02 wesleykuhn

@wesleykuhn Does this work with a DataTemplateSelector and use of modern Border rather than Frame?

axa88 avatar Feb 07 '24 17:02 axa88

@wesleykuhn Does this work with a DataTemplateSelector and use of modern Border rather than Frame?

I never did it with DataTemplateSelector, maybe it will work, because it will seek for the parent of the item template view, using its type as criteria. Border has gesture recognizer, you can use it.

wesleykuhn avatar Feb 07 '24 17:02 wesleykuhn

Still having this issue under Android, but works fine in Win.

ghuotvez avatar May 16 '24 13:05 ghuotvez