diff --git a/SwipeCards.Controls/Arguments/DraggingEventArgs.cs b/SwipeCards.Controls/Arguments/DraggingEventArgs.cs
index 60d1a59..5679588 100644
--- a/SwipeCards.Controls/Arguments/DraggingEventArgs.cs
+++ b/SwipeCards.Controls/Arguments/DraggingEventArgs.cs
@@ -1,14 +1,16 @@
using System;
-namespace SwipeCards.Controls.Arguments
+namespace SwipeCards
{
- public class DraggingEventArgs : EventArgs
- {
- public readonly object Item;
+ public class DraggingEventArgs : EventArgs
+ {
+ public object Item { get; private set; }
+ public double Distance { get; private set; }
- public DraggingEventArgs(object item)
- {
- this.Item = item;
- }
- }
+ public DraggingEventArgs(object item, double distance)
+ {
+ Item = item;
+ Distance = distance;
+ }
+ }
}
diff --git a/SwipeCards.Controls/Arguments/SwipedEventArgs.cs b/SwipeCards.Controls/Arguments/SwipedEventArgs.cs
index 20814bc..27592ab 100644
--- a/SwipeCards.Controls/Arguments/SwipedEventArgs.cs
+++ b/SwipeCards.Controls/Arguments/SwipedEventArgs.cs
@@ -1,21 +1,22 @@
using System;
-namespace SwipeCards.Controls.Arguments
+namespace SwipeCards
{
- public class SwipedEventArgs : EventArgs
- {
- public readonly object Item;
- public readonly SwipeDirection Direction;
+ public class SwipedEventArgs : EventArgs
+ {
+ public object Item { get; private set; }
+ public SwipeDirection Direction { get; private set; }
- public SwipedEventArgs(object item, SwipeDirection direction)
- {
- this.Item = item;
- this.Direction = direction;
- }
- }
+ public SwipedEventArgs(object item, SwipeDirection direction)
+ {
+ Item = item;
+ Direction = direction;
+ }
+ }
- public enum SwipeDirection
- {
- Left, Right
- }
+ public enum SwipeDirection
+ {
+ Left,
+ Right
+ }
}
diff --git a/SwipeCards.Controls/SwipeCards.Controls.csproj b/SwipeCards.Controls/SwipeCards.Controls.csproj
index 6de94d1..6414182 100644
--- a/SwipeCards.Controls/SwipeCards.Controls.csproj
+++ b/SwipeCards.Controls/SwipeCards.Controls.csproj
@@ -13,6 +13,7 @@
SwipeCards for Xamarin.Forms
true
Add methods for programmatic swiping.
+ netstandard1.6
@@ -32,10 +33,13 @@
10.0.16299.0
10.0.10240.0
+
+
+
-
-
+
+
\ No newline at end of file
diff --git a/SwipeCards.Controls/Views/CardStackView.xaml b/SwipeCards.Controls/Views/CardStackView.xaml
index 0ea6d56..be477dc 100644
--- a/SwipeCards.Controls/Views/CardStackView.xaml
+++ b/SwipeCards.Controls/Views/CardStackView.xaml
@@ -1,21 +1,6 @@
-
+
-
-
-
-
-
-
+
diff --git a/SwipeCards.Controls/Views/CardStackView.xaml.cs b/SwipeCards.Controls/Views/CardStackView.xaml.cs
index 3025312..1df532a 100644
--- a/SwipeCards.Controls/Views/CardStackView.xaml.cs
+++ b/SwipeCards.Controls/Views/CardStackView.xaml.cs
@@ -1,382 +1,361 @@
using System;
-using System.Collections.Generic;
+using System.Linq;
using Xamarin.Forms;
using System.Collections;
using System.Threading.Tasks;
using System.Windows.Input;
-using System.Collections.ObjectModel;
using System.Collections.Specialized;
-using Xamarin.Forms.Internals;
-using SwipeCards.Controls.Arguments;
-using Xamarin.Forms.Xaml;
-using System.Reflection;
-
-namespace SwipeCards.Controls
-{
- public partial class CardStackView : ContentView
- {
- #region ItemsSource Property
-
- public static readonly BindableProperty ItemsSourceProperty =
- BindableProperty.Create(
- nameof(ItemsSource), typeof(IList),
- typeof(CardStackView),
- null,
- BindingMode.TwoWay,
- propertyChanged: OnItemsSourcePropertyChanged);
-
- private static NotifyCollectionChangedEventHandler CollectionChangedEventHandler;
- private static void OnItemsSourcePropertyChanged(BindableObject bindable, object oldValue, object newValue)
- {
- // (Re-)subscribe to source changes
- if (newValue is INotifyCollectionChanged)
- {
- // If ItemSource is INotifyCollectionChanged, it can notify us about collection changes
- // In this case, we can use this, as a trigger for Setup()
-
- // Unsubscibe before
- if (CollectionChangedEventHandler != null)
- ((INotifyCollectionChanged)newValue).CollectionChanged -= CollectionChangedEventHandler;
-
- // Subscribe event handler
- CollectionChangedEventHandler = (sender, e) => ItemsSource_CollectionChanged(sender, e, (CardStackView)bindable);
- ((INotifyCollectionChanged)newValue).CollectionChanged += CollectionChangedEventHandler;
- }
-
- // Even if ItemsSource is not INotifyCollectionChanged, we need to
- // call Setup() whenever the whole collection changes
- ((CardStackView)bindable).Setup();
- }
+using System.Diagnostics;
+
+namespace SwipeCards
+{
+ public partial class CardStackView : ContentView
+ {
+ private static NotifyCollectionChangedEventHandler CollectionChangedEventHandler;
+
+ private const int NumberOfCards = 2;
+ private const int DefaultAnimationLength = 250;
+ private float _defaultSubcardScale = 0.9f;
+ private float _defaultSubcardTranslationX = -30;
+ private float _defaultSubcardOpacity = .6f;
+ private float _cardDistance;
+ private int _itemIndex;
+
+ public static BindableProperty SwipedRightCommandProperty = BindableProperty.Create(nameof(SwipedRightCommand), typeof(ICommand), typeof(CardStackView), null);
+ public static BindableProperty SwipedLeftCommandProperty = BindableProperty.Create(nameof(SwipedLeftCommand), typeof(ICommand), typeof(CardStackView), null);
+ public static readonly BindableProperty ItemsSourceProperty = BindableProperty.Create(nameof(ItemsSource), typeof(IList), typeof(CardStackView), null, BindingMode.TwoWay, propertyChanged: OnItemsSourcePropertyChanged);
+ public static readonly BindableProperty CardMoveDistanceProperty = BindableProperty.Create(nameof(CardMoveDistance), typeof(int), typeof(CardStackView), -1);
+ public static readonly BindableProperty ItemTemplateProperty = BindableProperty.Create(nameof(ItemTemplate), typeof(DataTemplate), typeof(CardStackView));
- static void ItemsSource_CollectionChanged(object sender, NotifyCollectionChangedEventArgs e, CardStackView cardStackView)
- {
- cardStackView.Setup();
- }
-
public IList ItemsSource
{
get { return (IList)GetValue(ItemsSourceProperty); }
set { SetValue(ItemsSourceProperty, value); }
- }
-
- #endregion
-
- #region ItemTemplate Property
-
- public static readonly BindableProperty ItemTemplateProperty =
- BindableProperty.Create(
- nameof(ItemTemplate),
- typeof(DataTemplate),
- typeof(CardStackView),
- new DataTemplate(() =>
- {
- var label = new Label { VerticalOptions = LayoutOptions.Center, HorizontalOptions = LayoutOptions.Center };
- label.SetBinding(Label.TextProperty, "Binding");
- return new ViewCell { View = label };
- }),
- propertyChanged: OnItemTemplatePropertyChanged);
+ }
- private static void OnItemTemplatePropertyChanged(BindableObject bindable, object oldValue, object newValue)
- {
- ((CardStackView)bindable).Setup();
- }
-
public DataTemplate ItemTemplate
{
get { return (DataTemplate)GetValue(ItemTemplateProperty); }
set { SetValue(ItemTemplateProperty, value); }
}
- #endregion
-
- #region Misc Properties
+ public int CardMoveDistance
+ {
+ get { return (int)GetValue(CardMoveDistanceProperty); }
+ set { SetValue(CardMoveDistanceProperty, value); }
+ }
- public static readonly BindableProperty CardMoveDistanceProperty = BindableProperty.Create(nameof(CardMoveDistance), typeof(int), typeof(CardStackView), -1);
-
- ///
- /// Distance, that a card has to be dragged into one direction to trigger the flip
- ///
- /// The card move distance.
- public int CardMoveDistance
- {
- get { return (int)GetValue(CardMoveDistanceProperty); }
- set { SetValue(CardMoveDistanceProperty, value); }
- }
-
- public static BindableProperty SwipedRightCommandProperty = BindableProperty.Create(nameof(SwipedRightCommand), typeof(ICommand), typeof(CardStackView), null);
- public ICommand SwipedRightCommand
- {
- get { return (ICommand)GetValue(SwipedRightCommandProperty); }
- set { SetValue(SwipedRightCommandProperty, value); }
- }
-
- public static BindableProperty SwipedLeftCommandProperty = BindableProperty.Create(nameof(SwipedLeftCommand), typeof(ICommand), typeof(CardStackView), null);
- public ICommand SwipedLeftCommand
- {
- get { return (ICommand)GetValue(SwipedLeftCommandProperty); }
- set { SetValue(SwipedLeftCommandProperty, value); }
+ public ICommand SwipedRightCommand
+ {
+ get { return (ICommand)GetValue(SwipedRightCommandProperty); }
+ set { SetValue(SwipedRightCommandProperty, value); }
}
- //public static readonly BindableProperty HasShadowProperty = BindableProperty.Create(nameof(HasShadow), typeof(bool), typeof(CardStackView), false);
- //public bool HasShadow
- //{
- // get { return (bool)GetValue(HasShadowProperty); }
- // set { SetValue(HasShadowProperty, value); }
- //}
+ public ICommand SwipedLeftCommand
+ {
+ get { return (ICommand)GetValue(SwipedLeftCommandProperty); }
+ set { SetValue(SwipedLeftCommandProperty, value); }
+ }
- #endregion
-
public event EventHandler Swiped;
- public event EventHandler StartedDragging;
- public event EventHandler FinishedDragging;
-
- private const int numberOfCards = 2;
- private const int defaultAnimationLength = 250;
- private float defaultSubcardScale = 0.8f;
- private float cardDistance = 0;
- private int itemIndex = 0;
+ public event EventHandler StartedDragging;
+ public event EventHandler Dragging;
+ public event EventHandler FinishedDragging;
+ public event EventHandler NoMoreCards;
+
+ public CardStackView()
+ {
+ InitializeComponent();
- public CardStackView()
- {
- InitializeComponent();
+ if (Device.RuntimePlatform == Device.iOS)
+ {
+ var panGesture = new PanGestureRecognizer();
+ panGesture.PanUpdated += OnPanUpdated;
+ CardStack.GestureRecognizers.Add(panGesture);
+ }
+
+ //MessagingCenter.Subscribe