xamarin / Xamarin.Forms

Xamarin.Forms is no longer supported. Migrate your apps to .NET MAUI.
https://aka.ms/xamarin-upgrade
Other
5.63k stars 1.87k forks source link

SwipeGestureRecognizer Not Working Inside ListView Android #4628

Open daves1992 opened 5 years ago

daves1992 commented 5 years ago

Description

SwipeGestures on a ViewCell in Android don't work and they break ContextActiions

 <ViewCell>
                            <ViewCell.ContextActions>
                                <MenuItem Command="{Binding Source={x:Reference CPMobileOrderPage}, Path=BindingContext.RemoveProductCommand}" CommandParameter="{Binding .}" Text="Delete" IsDestructive="True"/>
                            </ViewCell.ContextActions>
                            <ViewCell.View>
                                <Frame BackgroundColor="LightGray" Padding="1.5" HasShadow="False" CornerRadius="0">
                                    <Frame.GestureRecognizers>
                                        <SwipeGestureRecognizer Direction="Up" Command="{Binding Source={x:Reference CPMobileOrderPage}, Path=BindingContext.MoveProductUpList}" CommandParameter="{Binding .}"/>
                                        <SwipeGestureRecognizer Direction="Down" Command="{Binding Source={x:Reference CPMobileOrderPage}, Path=BindingContext.MoveProductDownList}" CommandParameter="{Binding .}"/>
                                    </Frame.GestureRecognizers>
                                    <Grid Padding="5,8,5,8" BackgroundColor="White">
                                        <Grid.ColumnDefinitions>
                                            <ColumnDefinition Width="Auto"/>
                                            <ColumnDefinition Width="*"/>
                                            <ColumnDefinition Width="Auto"/>
                                        </Grid.ColumnDefinitions>
                                        <Grid.RowDefinitions>
                                            <RowDefinition Height="Auto"/>
                                        </Grid.RowDefinitions>
                                        <Label Text="{Binding ID}" FontSize="Small" FontAttributes="Bold" TextColor="{Binding Source={x:Reference CPMobileOrderPage}, Path=BindingContext.DefaultPageDetailColor}" Grid.Column="0" Grid.Row="0" VerticalTextAlignment="Center"/>
                                    </Grid>
                                </Frame>
                            </ViewCell.View>
                        </ViewCell>

I have a Page where I have a switch and a Listview with items in. If I swipe the items with the switch enabled I can move them around. This works great on IOS. The SwipeGestureRecognizers are attached to the Frame inside the ViewCell.

Android the SwipeGestureRecognizer doesn't seem to work. It also seems to break the ContextActions and the binding for SelectedItem.

BrokenSwipeGes.zip

kingces95 commented 5 years ago

I'm able to run your reproduction but I'm not entirely clear what your actual and expected behaviors are. When you say "move them around" what exactly do you mean? I'm able to move them with the switch thrown either way on iOS and neither on Android. So that is different but before digging in I'd like to know what you expect. A video would be helpful. Or if you could reduce the reproduction further. Maybe start with a blank project and add the minimum code necessary to demonstrate the problem.

daves1992 commented 5 years ago

What I meant was as you described. On IOS I can swipe up and down on a viewcell arranging items in a list (using the SwipeGestureRecognizer's commands bound to two methods in the viewmodel which move items up and down the list). On Android I can't the items stay static. Ill create a new project and try to replicate with minimum code.

daves1992 commented 5 years ago

Attached a new repro.

ListSwipeGes.zip

If you run the app you will get a listview. Swipe up on any item they should move up the list. Swipe down they should move down.

Android this doesn't happen. The context actions in android also don't work when there is a SwipeGestureRecognizer attached to anything in the viewcell. IOS swipe right and left you get the delete option. Android hold pressing an item usually you get the delete option at the top.

bojanmisic commented 5 years ago

I'm experiencing the same issue. If I use SwipeGestureRecognizer on a ContentPage, if I have ScrollView or ListView inside that page (with only vertical scrolling behavior), left and right swipes are not detected only on Android device. Emulator works fine, iOS both the device and the simulator are also OK.

PureWeen commented 5 years ago

@bojanmisic can you elaborate on your ScrollView use case over here? https://github.com/xamarin/Xamarin.Forms/issues/4552

I have a repro attached to that issue where I'm able to swipe in a ScrollView If you can modify that repro? Or elaborate so we can reproduce that would be really helpful

msangtarash commented 5 years ago

I have the same problem. I have a Listview inside a Stcklayout. when i use SwipeGestureRecognizer on the stacklayout its leftswipe and rightswipe doesn't work on Android , but that is working fine on iOS and UWp

vasuthakker commented 5 years ago

Please update and resolve bug asap in android platform.

vasuthakker commented 5 years ago

Any update on the issue, when it will be fixed ?

D4rkC1own187 commented 5 years ago

Why was this close? It has not been resolve.

BoutemineOualid commented 5 years ago

Any updates on this?

ivanxamarin032019 commented 4 years ago

Any updates on this?

guilhermereisti commented 4 years ago

Any updates on this? Still happening at XF 4.6.0.847 just on Android.

stephenhauck commented 2 years ago

Anyone ... I "assumed" this would work ... it's 2021 ....

stephenhauck commented 2 years ago

Here is how to do it and have it work ... image

dasunmax89 commented 2 years ago

its not working still. XF 5.0.0.2196

stephenhauck commented 2 years ago

@dasunfit89 stop waiting for them to fix it and use the suggestion above. Move to a CollectionView