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

[Enhancement] SlidesView add IsOpen onSwipeChanging and swipe threshold percentage value #13501

Open Centurys opened 3 years ago

Centurys commented 3 years ago

Summary

Would be very good to control UI when SwipeView swipe gesture on Mode=SwipeMode.Execute would be executed. I would like to show to the user with visual change when swipe is executed, e.g. user would see visually if finger release would cause action to be invoked and when it would nothing happens, this is already calculated on SwipeEndedEventArgs property IsOpen.

And to configure control custom percentage value when action is invoked, now is hardcoded here: https://github.com/xamarin/Xamarin.Forms/blob/b0ec43649c67165cacb3e7fa5e4842ed56405362/Xamarin.Forms.Platform.Android/Renderers/SwipeViewRenderer.cs#L27

API Changes

Add to SwipeView class property OpenSwipeThresholdPercentage to control default percentage, could be min and max values required (e.g. 10-90%). Usage of this property could be similar like existing property Threshold.

SwipeView class has SwipeChanging event, this event is fired when user do swipe motion, returns SwipeChangingEventArgs class. Add to this class new bool property IsOpen. Implementation would be exactly same as in SwipeEnded event SwipeEndedEventArgs class IsOpen property.

e.g.

<SwipeView OpenSwipeThresholdPercentage="50" /> // slide to half size
private void SwipeView_SwipeChanging(object sender, SwipeChangingEventArgs e)
{
  if (e.IsOpen)
    // Change UI
}

Intended Use Case

More fine grained control on app visual appearance.

bakerhillpins commented 3 years ago

@Centurys

Unless I'm mistaken, you can determine the percentage swipe position by comparing the Offset value to the Threshold setting. Once the Offset value reaches 60% of the Threshold value it should be IsOpen... and when it goes back below IsOpen would be false again. You can get the Threshold value from the Sender parameter (which is the SwipeView itself). So adding the property to the SwipeChangingEventArgs isn't really needed.

[edit] It would seem that unless you specifically set the SwipeView.Threshold value, it is 0 (the default). In this case it attempts to use the total width of the SwipeItems collection if horizontal or the height of the SwipeItems if vertical.

Centurys commented 3 years ago

@bakerhillpins yes you can code some workaround as I did (which works only on some cases), but universal code where this universal calculation happens is at: Xamarin.Forms.Platform.Android/Renderers/SwipeViewRenderer.cs So I think for simplicity reasons is better that calculation results are coming from there is simple result values, rather we do same calculation locally.

marksarcade commented 3 years ago

I like the idea of this, i have a screen i'd like to replicate the functionality found in the iOS Outlook app, where the swipe hits a threshold and the icon changes and haptics are triggered to let the user know it'll execute. The standard execute is a bit plain compared with this, and the reveal mode is okay but not as nice either.