Skip to content

Commit

Permalink
Fix animation repeating code
Browse files Browse the repository at this point in the history
  • Loading branch information
PenguinPero committed Aug 19, 2019
1 parent 3619d99 commit df93b6b
Showing 1 changed file with 4 additions and 6 deletions.
10 changes: 4 additions & 6 deletions src/Calendar.Plugin/Shared/Controls/MonthDaysView.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,7 @@ public Style DaysTitleLabelStyle
private readonly List<DayView> _dayViews = new List<DayView>();
private DayModel _selectedDay;
private bool _animating;
private DateTime _lastAnimationTime;

internal MonthDaysView()
{
Expand Down Expand Up @@ -269,7 +270,7 @@ internal void UpdateDays()
Animate(() => daysControl.FadeTo(0, 50),
() => daysControl.FadeTo(1, 200),
() => LoadDays(),
() => Year * 100 + Month,
_lastAnimationTime = DateTime.UtcNow,
() => UpdateDays());
}

Expand Down Expand Up @@ -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;
Expand All @@ -390,7 +389,7 @@ private void Animate(
Func<Task> animationIn,
Func<Task> animationOut,
Action afterFirstAnimation,
Func<int> stateGetter,
DateTime animationTime,
Action callAgain)
{
if (_animating)
Expand All @@ -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());
Expand Down

0 comments on commit df93b6b

Please sign in to comment.