From df93b6b33dd243247c8ef9b3c74c3233b74acc78 Mon Sep 17 00:00:00 2001 From: Josip Caleta Date: Mon, 19 Aug 2019 20:39:11 +0200 Subject: [PATCH] Fix animation repeating code --- .../Shared/Controls/MonthDaysView.xaml.cs | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/src/Calendar.Plugin/Shared/Controls/MonthDaysView.xaml.cs b/src/Calendar.Plugin/Shared/Controls/MonthDaysView.xaml.cs index 22e6921..0b8d3b2 100644 --- a/src/Calendar.Plugin/Shared/Controls/MonthDaysView.xaml.cs +++ b/src/Calendar.Plugin/Shared/Controls/MonthDaysView.xaml.cs @@ -193,6 +193,7 @@ public Style DaysTitleLabelStyle private readonly List _dayViews = new List(); private DayModel _selectedDay; private bool _animating; + private DateTime _lastAnimationTime; internal MonthDaysView() { @@ -269,7 +270,7 @@ internal void UpdateDays() Animate(() => daysControl.FadeTo(0, 50), () => daysControl.FadeTo(1, 200), () => LoadDays(), - () => Year * 100 + Month, + _lastAnimationTime = DateTime.UtcNow, () => UpdateDays()); } @@ -372,8 +373,6 @@ private void LoadDays() foreach (var dayView in _dayViews) { var currentDate = monthStart.AddDays(addDays++); - - // TODO: add indicator for current date (outline circle) var dayModel = dayView.BindingContext as DayModel; dayModel.Date = currentDate.Date; @@ -390,7 +389,7 @@ private void Animate( Func animationIn, Func animationOut, Action afterFirstAnimation, - Func stateGetter, + DateTime animationTime, Action callAgain) { if (_animating) @@ -400,14 +399,13 @@ private void Animate( animationIn().ContinueWith(aIn => { - var prevState = stateGetter(); afterFirstAnimation(); animationOut().ContinueWith(aOut => { _animating = false; - if (stateGetter() != prevState) + if (animationTime != _lastAnimationTime) callAgain(); }, TaskScheduler.FromCurrentSynchronizationContext()); }, TaskScheduler.FromCurrentSynchronizationContext());