Skip to content
This repository has been archived by the owner on May 1, 2024. It is now read-only.

CollectionView highlight item with Visual State Manager doesn't work when GestureRecognizers applied #14005

Open
arahmancsd opened this issue Mar 12, 2021 · 2 comments

Comments

@arahmancsd
Copy link

arahmancsd commented Mar 12, 2021

The code was working in Xamarin.Forms 4.6, however, after upgrading to the latest Xamarin.Form 5.0.0.2012 highlighting CollectionView item with visual state manager doesn't work as expected. I found the problem is with GestureRecognizers on the Grid. If I remove the GestureRecognizers from the Grid, it works as expected.

After adding GestureRecognizers on the Grid, the expected behaviour is lost and it doesn't work any more.

<DataTemplate x:Key="AndroidAyaItemTemplate">
            <Grid RowDefinitions="*,Auto">
                <VisualStateManager.VisualStateGroups>
                    <VisualStateGroup x:Name="CommonStates">
                        <VisualState x:Name="Normal"/>
                        <VisualState x:Name="Selected">
                            <VisualState.Setters>
                                <Setter Property="BackgroundColor" Value="red"/>
                            </VisualState.Setters>
                        </VisualState>
                    </VisualStateGroup>
                </VisualStateManager.VisualStateGroups>
                <Label Text="Hello"/>
                <BoxView Grid.Row="1" Style="{DynamicResource HLine}" IsVisible="{Binding BindingContext.ShowHorizentalLine, Source={x:Reference MyPage}}"/>
                <Grid.GestureRecognizers>
                    <TapGestureRecognizer NumberOfTapsRequired="2" Command="{Binding BindingContext.ShareAyaCommand,Source={x:Reference itemView}}" CommandParameter="{Binding .}"/>
                    <SwipeGestureRecognizer Direction="Right" Command="{Binding BindingContext.NextChapterCommand, Source={x:Reference MyPage}}"/>
                    <SwipeGestureRecognizer Direction="Left" Command="{Binding BindingContext.PreviousChapterCommand, Source={x:Reference MyPage}}"/>
                </Grid.GestureRecognizers>
            </Grid>
        </DataTemplate>

<CollectionView Grid.Row="0" ItemsSource="{Binding ArabicListText}" SelectedItem="{Binding SelectedAya}" SelectionMode="Single" ItemTemplate="{OnPlatform Android={StaticResource AndroidAyaItemTemplate}, iOS={StaticResource iOSAyaItemTemplate}}"
                        x:Name="itemView">
                    <CollectionView.ItemsLayout>
                        <LinearItemsLayout Orientation="Vertical" ItemSpacing="5"/>
                    </CollectionView.ItemsLayout>
                </CollectionView>

Expected Behavior

Highlight Selected Item

Actual Behavior

Doesn't select them item neither highlight it

  • Version with issue: Xamarin.Form 5.0.0.2012
  • Android:
    It is not working in Android only, but the same code works fine in iOS.

Workaround
If I wrap the Grid inside SwipeView, it works fine. However, the problem still remain when CollectionView has more than 100 items.
2nd Workaround
This worked nicely for any number of items in the CollectionView. Add second Grid inside the 1st Grid and apply GestureRecognizers event on the 2nd Grid and everythings works smoothly and as expected.

@arahmancsd arahmancsd added s/unverified New report that has yet to be verified t/bug 🐛 labels Mar 12, 2021
@jsuarezruiz jsuarezruiz added this to New in Triage via automation Mar 22, 2021
@jsuarezruiz
Copy link
Contributor

Attach a sample where reproduce the issue:
Issue14005.zip

@jsuarezruiz jsuarezruiz removed the s/unverified New report that has yet to be verified label Mar 25, 2021
@jsuarezruiz jsuarezruiz moved this from New to Needs Estimate in Triage Mar 25, 2021
@jsuarezruiz jsuarezruiz added this to Review Backlog in CollectionView via automation Mar 25, 2021
@arahmancsd
Copy link
Author

@jsuarezruiz Thanks for gettings in. I have uploaded a sample project in gitHub with the workaround as well.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
CollectionView
  
Review Backlog
Triage
  
Needs Estimate
Development

No branches or pull requests

2 participants