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

Added possibility to respond to when the sidepanels move/pan #173

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
3 changes: 3 additions & 0 deletions JASidePanels/Source/JASidePanelController.h
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,9 @@ typedef enum _JASidePanelState {
// by default applies rounded corners to the panel. override in sublcass to change
- (void)stylePanel:(UIView *)panel;

// This method will be called whenever the sidepanel visible amount change. Subclass this method to react to changes of how much of the center panel / side panels are visible
- (void)willPanToSidePanelVisiblePercent:(CGFloat)percent duration:(CGFloat)duration;

#pragma mark - Animation

// the minimum % of total screen width the centerPanel.view must move for panGesture to succeed
Expand Down
13 changes: 11 additions & 2 deletions JASidePanels/Source/JASidePanelController.m
Original file line number Diff line number Diff line change
Expand Up @@ -516,8 +516,10 @@ - (void)_handlePan:(UIGestureRecognizer *)sender {
if (self.style == JASidePanelMultipleActive || self.pushesSidePanels) {
[self _layoutSideContainers:NO duration:0];
}

if (sender.state == UIGestureRecognizerStateEnded) {
if(sender.state == UIGestureRecognizerStateChanged) {
CGFloat fullyVisibleWidth = frame.origin.x > 0.0f ? self.leftVisibleWidth : -self.rightVisibleWidth;
[self willPanToSidePanelVisiblePercent:(frame.origin.x / fullyVisibleWidth) duration:0.0f];
} else if (sender.state == UIGestureRecognizerStateEnded) {
CGFloat deltaX = frame.origin.x - _locationBeforePan.x;
if ([self _validateThreshold:deltaX]) {
[self _completePan:deltaX];
Expand Down Expand Up @@ -567,6 +569,8 @@ - (void)_undoPan {
}
}

- (void)willPanToSidePanelVisiblePercent:(CGFloat)percent duration:(CGFloat)duration {}

#pragma mark - Tap Gesture

- (void)setTapView:(UIView *)tapView {
Expand Down Expand Up @@ -738,6 +742,8 @@ - (void)_animateCenterPanel:(BOOL)shouldBounce completion:(void (^)(BOOL finishe
}

CGFloat duration = [self _calculatedDuration];
CGFloat sidePanelVisiblePercent = _centerPanelRestingFrame.origin.x == 0.0f ? 0.0f : 1.0f;
[self willPanToSidePanelVisiblePercent:sidePanelVisiblePercent duration:duration];
[UIView animateWithDuration:duration delay:0.0f options:UIViewAnimationOptionCurveLinear|UIViewAnimationOptionLayoutSubviews animations:^{
self.centerPanelContainer.frame = _centerPanelRestingFrame;
[self styleContainer:self.centerPanelContainer animate:YES duration:duration];
Expand Down Expand Up @@ -829,6 +835,7 @@ - (void)_showLeftPanel:(BOOL)animated bounce:(BOOL)shouldBounce {
if (animated) {
[self _animateCenterPanel:shouldBounce completion:nil];
} else {
[self willPanToSidePanelVisiblePercent:1.0f duration:0.0f];
self.centerPanelContainer.frame = _centerPanelRestingFrame;
[self styleContainer:self.centerPanelContainer animate:NO duration:0.0f];
if (self.style == JASidePanelMultipleActive || self.pushesSidePanels) {
Expand All @@ -851,6 +858,7 @@ - (void)_showRightPanel:(BOOL)animated bounce:(BOOL)shouldBounce {
if (animated) {
[self _animateCenterPanel:shouldBounce completion:nil];
} else {
[self willPanToSidePanelVisiblePercent:1.0f duration:0.0f];
self.centerPanelContainer.frame = _centerPanelRestingFrame;
[self styleContainer:self.centerPanelContainer animate:NO duration:0.0f];
if (self.style == JASidePanelMultipleActive || self.pushesSidePanels) {
Expand All @@ -876,6 +884,7 @@ - (void)_showCenterPanel:(BOOL)animated bounce:(BOOL)shouldBounce {
[self _unloadPanels];
}];
} else {
[self willPanToSidePanelVisiblePercent:0.0f duration:0.0f];
self.centerPanelContainer.frame = _centerPanelRestingFrame;
[self styleContainer:self.centerPanelContainer animate:NO duration:0.0f];
if (self.style == JASidePanelMultipleActive || self.pushesSidePanels) {
Expand Down