Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GestureRecognizers inhibit CollectionView Selection on Android #6644

Open
david-maw opened this issue Apr 29, 2022 · 11 comments
Open

GestureRecognizers inhibit CollectionView Selection on Android #6644

david-maw opened this issue Apr 29, 2022 · 11 comments
Labels
area-controls-collectionview CollectionView, CarouselView, IndicatorView area-xaml XAML, CSS, Triggers, Behaviors platform/android 🤖 s/triaged Issue has been reviewed s/verified Verified / Reproducible Issue ready for Engineering Triage t/bug Something isn't working
Milestone

Comments

@david-maw
Copy link

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 david-maw added s/needs-verification Indicates that this issue needs initial verification before further triage will happen t/bug Something isn't working labels Apr 29, 2022
@kristinx0211 kristinx0211 added s/verified Verified / Reproducible Issue ready for Engineering Triage and removed s/needs-verification Indicates that this issue needs initial verification before further triage will happen labels Apr 29, 2022
@kristinx0211
Copy link

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

@Eilon Eilon added area-xaml XAML, CSS, Triggers, Behaviors area-controls-collectionview CollectionView, CarouselView, IndicatorView labels Apr 29, 2022
@Redth Redth added this to the 6.0.300 milestone May 3, 2022
@Redth Redth added the p/0 Work that we can't release without label May 3, 2022
@Redth Redth added p/1 Work that is critical for the release, but we could probably ship without and removed p/0 Work that we can't release without labels May 3, 2022
@kristinx0211
Copy link

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

@samhouts samhouts modified the milestones: 6.0.300, 6.0.300-servicing May 12, 2022
@Redth Redth modified the milestones: 6.0.300-servicing, 6.0.3xx-sr1 May 18, 2022
@PureWeen PureWeen removed their assignment May 25, 2022
@hartez hartez modified the milestones: 6.0-sr1, 6.0-sr2 Jun 6, 2022
@samhouts samhouts removed the p/1 Work that is critical for the release, but we could probably ship without label Jul 20, 2022
@mattleibow mattleibow modified the milestones: 6.0-sr2, 6.0-servicing Aug 29, 2022
@Redth Redth modified the milestones: 6.0-servicing, Backlog Aug 30, 2022
@ghost
Copy link

ghost commented Aug 30, 2022

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.

@samhouts samhouts removed the s/verified Verified / Reproducible Issue ready for Engineering Triage label Apr 5, 2023
@XamlTest XamlTest added s/verified Verified / Reproducible Issue ready for Engineering Triage s/triaged Issue has been reviewed labels Apr 25, 2023
@XamlTest
Copy link
Collaborator

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

@StephenWin
Copy link

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.

@EvoZ1310
Copy link

EvoZ1310 commented Jan 8, 2024

I have the same issue on MacCatalyst as well

@axa88
Copy link

axa88 commented Feb 4, 2024

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.

@wesleykuhn
Copy link

wesleykuhn commented Feb 7, 2024

@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.

@axa88
Copy link

axa88 commented Feb 7, 2024

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

@wesleykuhn
Copy link

@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.

@ghuotvez
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-controls-collectionview CollectionView, CarouselView, IndicatorView area-xaml XAML, CSS, Triggers, Behaviors platform/android 🤖 s/triaged Issue has been reviewed s/verified Verified / Reproducible Issue ready for Engineering Triage t/bug Something isn't working
Projects
None yet
Development

No branches or pull requests