Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix logic to determine final state (week view or month view) when releasing gesture. #1344

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
36 changes: 26 additions & 10 deletions FSCalendar/FSCalendarTransitionCoordinator.m
Original file line number Diff line number Diff line change
Expand Up @@ -148,21 +148,37 @@ - (void)scopeTransitionDidEnd:(UIPanGestureRecognizer *)panGesture
if (self.state != FSCalendarTransitionStateChanging) return;

self.state = FSCalendarTransitionStateFinishing;


// Our initial intention on what kind of view we want. +ve means we want month view initially. -ve means we want
// week view initially.
CGFloat translation = [panGesture translationInView:panGesture.view].y;

// Our current gesture movement direction. +ve means we are moving toward month view direction. -ve means we are
// moving toward week view direction.
CGFloat velocity = [panGesture velocityInView:panGesture.view].y;

CGFloat progress = ({
CGFloat maxTranslation = CGRectGetHeight(self.transitionAttributes.targetBounds) - CGRectGetHeight(self.transitionAttributes.sourceBounds);
translation = MAX(0, translation);
translation = MIN(maxTranslation, translation);
CGFloat progress = translation/maxTranslation;
progress;
});
if (velocity * translation < 0) {
// Please cross check in scopeTransitionDidUpdate, to understand what is scrolling "overflow".
bool scrollingOverflowRevertRequired = false;

switch (self.calendar.scope) {
case FSCalendarScopeMonth: {
if (translation > 0) {
scrollingOverflowRevertRequired = true;
}
break;
}
case FSCalendarScopeWeek: {
if (translation < 0) {
scrollingOverflowRevertRequired = true;
}
break;
}
}

if (velocity * translation < 0 || scrollingOverflowRevertRequired) {
[self.transitionAttributes revert];
}
[self performTransition:self.transitionAttributes.targetScope fromProgress:progress toProgress:1.0 animated:YES];
[self performTransition:self.transitionAttributes.targetScope fromProgress:-1 toProgress:1.0 animated:YES];
}

#pragma mark - Public methods
Expand Down