Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions Runtime/Universal.UI.Xaml.Controls/SwipeListBehavior.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@ public enum SwipeListBehavior
/// </summary>
Collapse,

/// <summary>
/// Triggered when swipe reaches 2/5 of the width of the item. Once triggered side menu will continue to stay open, <see cref="SwipeListViewItem"/> state is not restored.
/// </summary>
Persist,

/// <summary>
/// Swipe is disabled.
/// </summary>
Expand Down
53 changes: 53 additions & 0 deletions Runtime/Universal.UI.Xaml.Controls/SwipeListViewItem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -229,13 +229,17 @@ 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);
}
else if (_direction == SwipeListDirection.Right && ContentDragTransform.X <= -target)
{
if (RightBehavior == SwipeListBehavior.Collapse)
currentAnim = CollapseAnimation(SwipeListDirection.Right, true);
else if (RightBehavior == SwipeListBehavior.Persist)
currentAnim = PersistAnimation(SwipeListDirection.Right, target);
else
currentAnim = ExpandAnimation(SwipeListDirection.Right);
}
Expand Down Expand Up @@ -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();
Expand All @@ -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();
}

/// <summary>
/// Occurs when the item is swiped from left or right.
/// </summary>
Expand Down