xamarin / Xamarin.Forms

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

[Bug] Closed-Event for SwipeView #10466

Open HarryLobster opened 4 years ago

HarryLobster commented 4 years ago

I am missing a Close-Event for the SwipeView if it is generally closing e.g. by tapping on the form. There is only the event CloseRequested that only fires if I close the SwipeView programatically. I want to use the SwipeView in a ListView-Scenario and would like to lock the ListView while the SwipeView is open.

jsuarezruiz commented 4 years ago

Thanks for the suggested enhancement @HarryLobster. Actually, you can programmatically open the SwipeView using: swipeView.Open(OpenSwipeItem.LeftItems); And close it with: swipeView.Close();

Related, recently the IsOpen property has also been added to SwipeEndedEventArgs. In this way, you can know if the SwipeView is open or closed when you stop swipping.

What would better cover this enhancement better, have a Closed event that is fired always when the SwipeView is closed?

AlexandraMash commented 4 years ago

As well as @HarryLobster I would really appreciate having some event to track changes of IsOpen property. The thing is that SwipeEnded event is only called when I am swiping to open the view, but when I am closing it (either by tap or by swipe) nothing is called. It allows to learn when swipe view state changes from Closed to Open, but not vice versa.

In my use case I need to change state of some elements inside the swipe view depending on whether it is open or closed (by the user). To achieve it right now I am adding a tap and a few swipe gesture recognizers and inside of them I am assuming that if the view was open it's state is about to change to closed. It kind of works (though looks a bit hacky) but some cases of swipe view being closed are still not covered with this approach.

So it would be awesome if some sort of Closed or IsOpenChanged event was introduced that would fire every time when the state is actually changing.

HarryLobster commented 4 years ago

Thanks for the suggested enhancement @HarryLobster. Actually, you can programmatically open the SwipeView using: swipeView.Open(OpenSwipeItem.LeftItems); And close it with: swipeView.Close();

Related, recently the IsOpen property has also been added to SwipeEndedEventArgs. In this way, you can know if the SwipeView is open or closed when you stop swipping.

What would better cover this enhancement better, have a Closed event that is fired always when the SwipeView is closed?

Yes, that would solve my problem and it is logical for me that this should be implemented anyways !?

hairatic commented 4 years ago

As well as @HarryLobster I would really appreciate having some event to track changes of IsOpen property. The thing is that SwipeEnded event is only called when I am swiping to open the view, but when I am closing it (either by tap or by swipe) nothing is called. It allows to learn when swipe view state changes from Closed to Open, but not vice versa.

In my use case I need to change state of some elements inside the swipe view depending on whether it is open or closed (by the user). To achieve it right now I am adding a tap and a few swipe gesture recognizers and inside of them I am assuming that if the view was open it's state is about to change to closed. It kind of works (though looks a bit hacky) but some cases of swipe view being closed are still not covered with this approach.

So it would be awesome if some sort of Closed or IsOpenChanged event was introduced that would fire every time when the state is actually changing.

I'm using Xamarin.Forms 4.8.0.1364 and SwipeEnded event is NOT firing when SwipeView is closed on Android. Only when its opened (obviously isOpen is always true). SwipeStarted is also fired only during opening.

AdamDiament commented 4 years ago

@hairatic @jsuarezruiz I am using xam forms 5.0 pre-1, and I can confirm the same behaviour on Android - swipe ended only fires when opening the swipe view, not closing it. So I am unable to reliably know the open/closed state of the swipe view at any point in time. In fact there appear to be various problems with all of the exposed swipe events, as follows.

CloseRequested - never fires when swiping OpenRequested - never fires when swiping SwipeChanging - only fires on swiping to open, not swiping to close SwipeEnded - only fires on swiping to open, not swiping to close SwipeStarted -only fires on swiping to open, not swiping to close

My swipe view is inside a collectionview, running on an android physical device, samsung galaxy A30, android 10.

Although working versions of these events would be useful for me, what I am really looking for is an INotifyPropertyChanged boolean "IsOpen" on the swipe view itself, that I could check and bind UI bindable properties against.

acaliaro commented 4 years ago

@hairatic @jsuarezruiz I am using xam forms 5.0 pre-1, and I can confirm the same behaviour on Android - swipe ended only fires when opening the swipe view, not closing it. So I am unable to reliably know the open/closed state of the swipe view at any point in time. In fact there appear to be various problems with all of the exposed swipe events, as follows.

CloseRequested - never fires when swiping OpenRequested - never fires when swiping SwipeChanging - only fires on swiping to open, not swiping to close SwipeEnded - only fires on swiping to open, not swiping to close SwipeStarted -only fires on swiping to open, not swiping to close

My swipe view is inside a collectionview, running on an android physical device, samsung galaxy A30, android 10.

Although working versions of these events would be useful for me, what I am really looking for is an INotifyPropertyChanged boolean "IsOpen" on the swipe view itself, that I could check and bind UI bindable properties against.

It seems that 5.0.0.1558-pre3 has the same problems...

lhughey commented 4 years ago

Can we get this reclassified as a bug since none of events correctly fire on Android? I am afraid that tit may not get the proper visibility due to it being labeled as an enhancement.

jsuarezruiz commented 3 years ago

I have done some tests using Xamarin.Forms 5.0 in a Device using Android 10:

issue10466

The results:

Is that your expected behavior?

AdamDiament commented 3 years ago

Thanks @jsuarezruiz . I have upgraded to 5 pre3 and I get the same behaviour now. However SwipeChanging, SwipeEnded and SwipeStarted only seem to fire when opening the item. Once the item is open, upon swiping to close, none of the events fire. Is this expected behaviour?

timjamwoo commented 3 years ago

However SwipeChanging, SwipeEnded and SwipeStarted only seem to fire when opening the item. Once the item is open, upon swiping to close, none of the events fire. Is this expected behaviour?

Hi @jsuarezruiz, I see the exact same behaviour on iOS 14.5 using Xamarin.Forms 5.0.0.2012. Is there a fix on the horizon?

stavroaudisho commented 3 years ago

I have the same behaviour. It should be that SwipeEnded is fired when the swipe item is closed. Is there going to be a fix for this?

stavroaudisho commented 3 years ago

@jsuarezruiz I've noticed that SwipeEnded works for the swipe item being closed only when it isn't fully opened in the first place. If your video above continued, it wouldn't have shown SwipeEnded when you were closing the swipeview item.

If I swipe the view but don't swipe it all the way, SwipeEnded will be triggered. I'd like SwipeStarted to be triggered no matter where you are in the swipe. It seems to only be working when the swipe view is in its default position. Similarly, SwipeEnded only gets triggered when you are starting from the default position or you swipe from one side across the middle to the other side.

jpailler commented 3 years ago

I´m experiencing the same behaviour as @stavroaudisho. Is there going to be a fix? It would be nice if SwipeEnded event triggers if SwipeView closes.

SchindlerFlorian commented 3 years ago

Having the same issue. I would also appreciate a fix for this.

haavamoa commented 3 years ago

Works for Android, not for iOS.

On a side note; I was a bit surprised by this API as most other controls have a simple IsOpen property that you can use in a property changed scenario. SwipeEnded + IsOpen works (if it worked for both platforms), but it's kinda different than most other controls IMO.

I tried to listen to property changed in general for both the SwipeView and the content of the SwipeView. On iOS there is no event to hook on to when you close it, which is really disapointing.

A potential workaround I tried was: Use Xamarin Community Toolkit Lifecycle effects on the content of the SwipeView to get Loaded/Unloaded events. This also worked on Android, but not for iOS.

michaelbourke commented 2 years ago

Is there any update on this? As far as I can see it's currently impossible to determine if the SwipeView has been swiped closed.

misve0411 commented 2 years ago

I have the same issue. Did manage to create a new ticket before I found this thread (https://github.com/xamarin/Xamarin.Forms/issues/15194 ). Is there a solution in sight?

draganDBL commented 2 years ago

I have the same issue

pasha-o commented 2 years ago

@jsuarezruiz has there been any progress on this item?

chaoyebugao commented 2 years ago

Any progress? I can's think why there is't a IsOpen property... such a ez thing...