From 579de8fdb41e7f503258b579d26cc823a094f8af Mon Sep 17 00:00:00 2001 From: Andrei Misiukevich Date: Fri, 2 Feb 2018 13:58:06 +0300 Subject: [PATCH] Opened properties for customizing animations --- PanCardView.Droid/CardsViewRenderer.cs | 3 ++ PanCardView.nuspec | 38 +++++++++---------- PanCardView/CardsView.cs | 14 +++++-- PanCardView/CarouselView.cs | 1 + PanCardView/PanCardView.csproj | 1 + .../Processors/BaseCardBackViewProcessor.cs | 17 ++++----- .../Processors/BaseCardFrontViewProcessor.cs | 11 +++--- .../BaseCarouselBackViewProcessor.cs | 4 +- .../BaseCarouselFrontViewProcessor.cs | 4 +- PanCardView/Processors/Constants.cs | 8 ++++ PanCardViewSample/Droid/MainActivity.cs | 8 +--- 11 files changed, 61 insertions(+), 48 deletions(-) create mode 100644 PanCardView/Processors/Constants.cs diff --git a/PanCardView.Droid/CardsViewRenderer.cs b/PanCardView.Droid/CardsViewRenderer.cs index 4f7bf00..c6f4e58 100644 --- a/PanCardView.Droid/CardsViewRenderer.cs +++ b/PanCardView.Droid/CardsViewRenderer.cs @@ -5,10 +5,12 @@ using PanCardView.Droid; using PanCardView; using Android.Views; +using Android.Runtime; [assembly: ExportRenderer(typeof(CardsView), typeof(CardsViewRenderer))] namespace PanCardView.Droid { + [Preserve(AllMembers = true)] public class CardsViewRenderer : VisualElementRenderer { private bool _panStarted; @@ -17,6 +19,7 @@ public CardsViewRenderer(Context context) : base(context) { } + [Obsolete("You needn't have to call this method. Now, Cards ViewRenderer is marked by Preserve attribute")] public static void Init() { var now = DateTime.Now; diff --git a/PanCardView.nuspec b/PanCardView.nuspec index 71c856c..085255f 100644 --- a/PanCardView.nuspec +++ b/PanCardView.nuspec @@ -2,7 +2,7 @@ CardsView - 1.2.5 + 1.2.6 CardsView Andrei Misiukevich Andrei Misiukevich @@ -11,7 +11,7 @@ https://cdn3.iconfinder.com/data/icons/google-material-design-icons/48/ic_view_carousel_48px-256.png Cards View This package provides opportunity to create swipeable CardsView like in Tinder app has - xamarin, carouselview, cardsview, forms, carousel, xamarin.forms, android, ios, card, cards, cardview, panView, pan + xamarin, carouselview, cardsview, forms, carousel, xamarin.forms, android, card, cards, cardview, panView, pan, swipeview, swiperview, swipe @@ -19,29 +19,29 @@ - - + + - - + + - - - + + + - - + + - - + + - - + + - - + + - - + + \ No newline at end of file diff --git a/PanCardView/CardsView.cs b/PanCardView/CardsView.cs index 596b01a..afb48fb 100644 --- a/PanCardView/CardsView.cs +++ b/PanCardView/CardsView.cs @@ -58,6 +58,8 @@ public class CardsView : AbsoluteLayout public static readonly BindableProperty MoveDistanceProperty = BindableProperty.Create(nameof(MoveDistance), typeof(double), typeof(CardsView), -1.0); + public static readonly BindableProperty MoveWidthPercentageProperty = BindableProperty.Create(nameof(MoveWidthPercentage), typeof(double), typeof(CardsView), .32); + public static readonly BindableProperty IsOnlyForwardDirectionProperty = BindableProperty.Create(nameof(IsOnlyForwardDirection), typeof(bool), typeof(CardsView), false); public static readonly BindableProperty PanDelayProperty = BindableProperty.Create(nameof(PanDelay), typeof(int), typeof(CardsView), 200); @@ -68,9 +70,9 @@ public class CardsView : AbsoluteLayout public static readonly BindableProperty IsAutoNavigatingProperty = BindableProperty.Create(nameof(IsAutoNavigating), typeof(bool), typeof(CardsView), false, BindingMode.OneWayToSource); - public static readonly BindableProperty MaxChildrenCountProperty = BindableProperty.Create(nameof(MaxChildrenCount), typeof(int), typeof(CardsView), 18); + public static readonly BindableProperty MaxChildrenCountProperty = BindableProperty.Create(nameof(MaxChildrenCount), typeof(int), typeof(CardsView), 12); - public static readonly BindableProperty DesiredMaxChildrenCountProperty = BindableProperty.Create(nameof(DesiredMaxChildrenCount), typeof(int), typeof(CardsView), 9); + public static readonly BindableProperty DesiredMaxChildrenCountProperty = BindableProperty.Create(nameof(DesiredMaxChildrenCount), typeof(int), typeof(CardsView), 6); public static readonly BindableProperty PanStartedCommandProperty = BindableProperty.Create(nameof(PanStartedCommand), typeof(ICommand), typeof(CardsView), null); @@ -181,11 +183,17 @@ public double MoveDistance var dist = (double)GetValue(MoveDistanceProperty); return dist > 0 ? dist - : Width * 0.35; + : Width * MoveWidthPercentage; } set => SetValue(MoveDistanceProperty, value); } + public double MoveWidthPercentage + { + get => (double)GetValue(MoveWidthPercentageProperty); + set => SetValue(MoveWidthPercentageProperty, value); + } + public int PanDelay { get => IsPanInCourse ? _inCoursePanDelay : (int)GetValue(PanDelayProperty); diff --git a/PanCardView/CarouselView.cs b/PanCardView/CarouselView.cs index 69f49d2..6342587 100644 --- a/PanCardView/CarouselView.cs +++ b/PanCardView/CarouselView.cs @@ -12,6 +12,7 @@ public CarouselView(ICardProcessor frontViewProcessor, ICardProcessor backViewPr { IsClippedToBounds = true; IsRecycled = true; + MoveWidthPercentage = 0.3; } } } diff --git a/PanCardView/PanCardView.csproj b/PanCardView/PanCardView.csproj index f31b140..ec84ceb 100644 --- a/PanCardView/PanCardView.csproj +++ b/PanCardView/PanCardView.csproj @@ -40,6 +40,7 @@ + diff --git a/PanCardView/Processors/BaseCardBackViewProcessor.cs b/PanCardView/Processors/BaseCardBackViewProcessor.cs index e6a4792..88be921 100644 --- a/PanCardView/Processors/BaseCardBackViewProcessor.cs +++ b/PanCardView/Processors/BaseCardBackViewProcessor.cs @@ -2,26 +2,25 @@ using Xamarin.Forms; using System.Threading.Tasks; using PanCardView.Enums; +using static PanCardView.Processors.Constants; namespace PanCardView.Processors { public class BaseCardBackViewProcessor : ICardProcessor { - private const double Rad = 57.2958; + public double InitialScale { get; set; } = 0.8; - protected double InitialScale { get; set; } = 0.8; + public uint ApplyAnimationLength { get; set; } = 200; - protected uint ApplyAnimationLength { get; set; } = 200; + public uint ResetAnimationLength { get; set; } = 150; - protected uint ResetAnimationLength { get; set; } = 150; + public uint AutoNavigateAnimationLength { get; set; } = 150; - protected uint AutoNavigateAnimationLength { get; set; } = 150; + public Easing ApplyEasing { get; set; } = Easing.Linear; - protected Easing ApplyEasing { get; set; } = Easing.SinOut; + public Easing ResetEasing { get; set; } = Easing.CubicInOut; - protected Easing ResetEasing { get; set; } = Easing.SinIn; - - protected Easing AutoNavigateEasing { get; set; } = Easing.Linear; + public Easing AutoNavigateEasing { get; set; } = Easing.Linear; public virtual void InitView(View view, CardsView cardsView, PanItemPosition panItemPosition) { diff --git a/PanCardView/Processors/BaseCardFrontViewProcessor.cs b/PanCardView/Processors/BaseCardFrontViewProcessor.cs index 28edbc1..e388366 100644 --- a/PanCardView/Processors/BaseCardFrontViewProcessor.cs +++ b/PanCardView/Processors/BaseCardFrontViewProcessor.cs @@ -2,20 +2,19 @@ using Xamarin.Forms; using System.Threading.Tasks; using PanCardView.Enums; +using static PanCardView.Processors.Constants; namespace PanCardView.Processors { public class BaseCardFrontViewProcessor : ICardProcessor { - private const double Rad = 57.2958; + public uint ResetAnimationLength { get; set; } = 150; - protected uint ResetAnimationLength { get; set; } = 150; + public uint AutoNavigateAnimationLength { get; set; } = 150; - protected uint AutoNavigateAnimationLength { get; set; } = 150; + public Easing ResetEasing { get; set; } = Easing.CubicInOut; - protected Easing ResetEasing { get; set; } = Easing.SinIn; - - protected Easing AutoNavigateEasing { get; set; } = Easing.Linear; + public Easing AutoNavigateEasing { get; set; } = Easing.Linear; public virtual void InitView(View view, CardsView cardsView, PanItemPosition panItemPosition) => ResetInitialState(view); diff --git a/PanCardView/Processors/BaseCarouselBackViewProcessor.cs b/PanCardView/Processors/BaseCarouselBackViewProcessor.cs index 3225f5a..9dbb972 100644 --- a/PanCardView/Processors/BaseCarouselBackViewProcessor.cs +++ b/PanCardView/Processors/BaseCarouselBackViewProcessor.cs @@ -7,9 +7,9 @@ namespace PanCardView.Processors { public class BaseCarouselBackViewProcessor : ICardProcessor { - protected uint AnimationLength { get; set; } = 250; + public uint AnimationLength { get; set; } = 300; - protected Easing AnimEasing { get; set; } = Easing.SinIn; + public Easing AnimEasing { get; set; } = Easing.CubicInOut; public virtual void InitView(View view, CardsView cardsView, PanItemPosition panItemPosition) { diff --git a/PanCardView/Processors/BaseCarouselFrontViewProcessor.cs b/PanCardView/Processors/BaseCarouselFrontViewProcessor.cs index 5b03b67..d632425 100644 --- a/PanCardView/Processors/BaseCarouselFrontViewProcessor.cs +++ b/PanCardView/Processors/BaseCarouselFrontViewProcessor.cs @@ -7,9 +7,9 @@ namespace PanCardView.Processors { public class BaseCarouselFrontViewProcessor : ICardProcessor { - protected uint AnimationLength { get; set; } = 250; + public uint AnimationLength { get; set; } = 300; - protected Easing AnimEasing { get; set; } = Easing.SinIn; + public Easing AnimEasing { get; set; } = Easing.CubicInOut; public virtual void InitView(View view, CardsView cardsView, PanItemPosition panItemPosition) { diff --git a/PanCardView/Processors/Constants.cs b/PanCardView/Processors/Constants.cs new file mode 100644 index 0000000..7be6643 --- /dev/null +++ b/PanCardView/Processors/Constants.cs @@ -0,0 +1,8 @@ + +namespace PanCardView.Processors +{ + public static class Constants + { + public const double Rad = 57.2958; + } +} diff --git a/PanCardViewSample/Droid/MainActivity.cs b/PanCardViewSample/Droid/MainActivity.cs index 98601cf..7eae843 100644 --- a/PanCardViewSample/Droid/MainActivity.cs +++ b/PanCardViewSample/Droid/MainActivity.cs @@ -1,14 +1,8 @@ -using System; - + using Android.App; -using Android.Content; using Android.Content.PM; -using Android.Runtime; -using Android.Views; -using Android.Widget; using Android.OS; using Xamarin.Forms; -using PanCardView.Droid; using FFImageLoading.Forms.Droid; namespace PanCardViewSample.Droid