From bf5e8f54d1878ef12d7c25623959d7eb96b57d6a Mon Sep 17 00:00:00 2001 From: unknown Date: Wed, 16 Mar 2016 12:32:33 -0400 Subject: [PATCH] Add a persist mode that will keep the right / left content visible until it is dismissed. --- .../SwipeListBehavior.cs | 5 ++ .../SwipeListViewItem.cs | 53 +++++++++++++++++++ 2 files changed, 58 insertions(+) diff --git a/Runtime/Universal.UI.Xaml.Controls/SwipeListBehavior.cs b/Runtime/Universal.UI.Xaml.Controls/SwipeListBehavior.cs index cff9433..63c0849 100644 --- a/Runtime/Universal.UI.Xaml.Controls/SwipeListBehavior.cs +++ b/Runtime/Universal.UI.Xaml.Controls/SwipeListBehavior.cs @@ -18,6 +18,11 @@ public enum SwipeListBehavior /// Collapse, + /// + /// Triggered when swipe reaches 2/5 of the width of the item. Once triggered side menu will continue to stay open, state is not restored. + /// + Persist, + /// /// Swipe is disabled. /// diff --git a/Runtime/Universal.UI.Xaml.Controls/SwipeListViewItem.cs b/Runtime/Universal.UI.Xaml.Controls/SwipeListViewItem.cs index 626b6b8..f48bc5b 100644 --- a/Runtime/Universal.UI.Xaml.Controls/SwipeListViewItem.cs +++ b/Runtime/Universal.UI.Xaml.Controls/SwipeListViewItem.cs @@ -229,6 +229,8 @@ protected override void OnManipulationCompleted(ManipulationCompletedRoutedEvent { if (LeftBehavior == SwipeListBehavior.Collapse) currentAnim = CollapseAnimation(SwipeListDirection.Left, true); + else if (LeftBehavior == SwipeListBehavior.Persist) + currentAnim = PersistAnimation(SwipeListDirection.Left, target); else currentAnim = ExpandAnimation(SwipeListDirection.Left); } @@ -236,6 +238,8 @@ protected override void OnManipulationCompleted(ManipulationCompletedRoutedEvent { if (RightBehavior == SwipeListBehavior.Collapse) currentAnim = CollapseAnimation(SwipeListDirection.Right, true); + else if (RightBehavior == SwipeListBehavior.Persist) + currentAnim = PersistAnimation(SwipeListDirection.Right, target); else currentAnim = ExpandAnimation(SwipeListDirection.Right); } @@ -329,6 +333,48 @@ private Storyboard ExpandAnimation(SwipeListDirection direction) return currentAnim; } + + + private Storyboard PersistAnimation(SwipeListDirection direction, double target) + { + var currentAnim = new Storyboard(); + if (direction == SwipeListDirection.Left) + { + var animDrag = CreateDouble(target, 300, ContentDragTransform, "TranslateTransform.X", new ExponentialEase { EasingMode = EasingMode.EaseOut }); + var animClip = CreateDouble(target, 300, DragClipTransform, "TranslateTransform.X", new ExponentialEase { EasingMode = EasingMode.EaseOut }); + var animLeft = CreateDouble(-LeftContainer.ActualWidth + target, 300, LeftTransform, "TranslateTransform.X", new ExponentialEase { EasingMode = EasingMode.EaseOut }); + var animRight = CreateDouble((RightContainer.ActualWidth + target), 300, RightTransform, "TranslateTransform.X", new ExponentialEase { EasingMode = EasingMode.EaseOut }); + + currentAnim.Children.Add(animDrag); + currentAnim.Children.Add(animClip); + currentAnim.Children.Add(animLeft); + currentAnim.Children.Add(animRight); + } + else if (direction == SwipeListDirection.Right) + { + var animDrag = CreateDouble(-target, 300, ContentDragTransform, "TranslateTransform.X", new ExponentialEase { EasingMode = EasingMode.EaseOut }); + var animClip = CreateDouble(-target, 300, DragClipTransform, "TranslateTransform.X", new ExponentialEase { EasingMode = EasingMode.EaseOut }); + var animLeft = CreateDouble(-LeftContainer.ActualWidth - target, 300, LeftTransform, "TranslateTransform.X", new ExponentialEase { EasingMode = EasingMode.EaseOut }); + var animRight = CreateDouble((RightContainer.ActualWidth - target), 300, RightTransform, "TranslateTransform.X", new ExponentialEase { EasingMode = EasingMode.EaseOut }); + + currentAnim.Children.Add(animDrag); + currentAnim.Children.Add(animClip); + currentAnim.Children.Add(animLeft); + currentAnim.Children.Add(animRight); + } + + currentAnim.Completed += (s, args) => + { + if (ItemSwipe != null) + ItemSwipe(this, new ItemSwipeEventArgs(Content, direction)); + + if (_parent != null) + _parent.RaiseItemSwipe(new ItemSwipeEventArgs(Content, direction)); + }; + + return currentAnim; + } + private DoubleAnimation CreateDouble(double to, int duration, DependencyObject target, string path, EasingFunctionBase easing) { var anim = new DoubleAnimation(); @@ -346,6 +392,13 @@ private DoubleAnimation CreateDouble(double to, int duration, DependencyObject t return anim; } + + public void CollapseSwipeContent() + { + var animation = CollapseAnimation(SwipeListDirection.Left, false); + animation.Begin(); + } + /// /// Occurs when the item is swiped from left or right. ///