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

add fd_fullscreenPopGestureRecognizerDelegate #30

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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@

/// The gesture recognizer that actually handles interactive pop.
@property (nonatomic, strong, readonly) UIPanGestureRecognizer *fd_fullscreenPopGestureRecognizer;

/// Don't set gestureRecognizer delegate directly. Use this property instead.
@property (nonatomic, weak) id<UIGestureRecognizerDelegate> fd_fullscreenPopGestureRecognizerDelegate;
/// A view controller is able to control navigation bar's appearance by itself,
/// rather than a global way, checking "fd_prefersNavigationBarHidden" property.
/// Default to YES, disable it if you don't want so.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,20 @@
@interface _FDFullscreenPopGestureRecognizerDelegate : NSObject <UIGestureRecognizerDelegate>

@property (nonatomic, weak) UINavigationController *navigationController;

@property (nonatomic, weak) id<UIGestureRecognizerDelegate> delegate;
@end

@implementation _FDFullscreenPopGestureRecognizerDelegate

- (BOOL)gestureRecognizerShouldBegin:(UIPanGestureRecognizer *)gestureRecognizer
{
if (self.delegate && [self.delegate respondsToSelector:@selector(gestureRecognizerShouldBegin:)]) {
BOOL shouldBegin = [self.delegate gestureRecognizerShouldBegin:gestureRecognizer];
if (shouldBegin == NO) {
return shouldBegin;
}
}

// Ignore when no view controller is pushed into the navigation stack.
if (self.navigationController.viewControllers.count <= 1) {
return NO;
Expand Down Expand Up @@ -65,6 +72,46 @@ - (BOOL)gestureRecognizerShouldBegin:(UIPanGestureRecognizer *)gestureRecognizer
return YES;
}

- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer
{
if (self.delegate &&
[self.delegate respondsToSelector:@selector(gestureRecognizer:shouldRecognizeSimultaneouslyWithGestureRecognizer:)]) {
return [self.delegate gestureRecognizer:gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:otherGestureRecognizer];
}

return NO;
}

- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRequireFailureOfGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer
{
if (self.delegate &&
[self.delegate respondsToSelector:@selector(gestureRecognizer:shouldRequireFailureOfGestureRecognizer:)]) {
return [self.delegate gestureRecognizer:gestureRecognizer shouldRequireFailureOfGestureRecognizer:otherGestureRecognizer];
}

return NO;
}

- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldBeRequiredToFailByGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer
{
if (self.delegate &&
[self.delegate respondsToSelector:@selector(gestureRecognizer:shouldBeRequiredToFailByGestureRecognizer:)]) {
return [self.delegate gestureRecognizer:gestureRecognizer shouldBeRequiredToFailByGestureRecognizer:otherGestureRecognizer];
}

return NO;
}

- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch
{
if (self.delegate &&
[self.delegate respondsToSelector:@selector(gestureRecognizer:shouldReceiveTouch:)]) {
return [self.delegate gestureRecognizer:gestureRecognizer shouldReceiveTouch:touch];
}

return YES;
}

@end

typedef void (^_FDViewControllerWillAppearInjectBlock)(UIViewController *viewController, BOOL animated);
Expand Down Expand Up @@ -237,6 +284,16 @@ - (void)setFd_viewControllerBasedNavigationBarAppearanceEnabled:(BOOL)enabled
objc_setAssociatedObject(self, key, @(enabled), OBJC_ASSOCIATION_RETAIN_NONATOMIC);
}

- (id<UIGestureRecognizerDelegate>)fd_fullscreenPopGestureRecognizerDelegate
{
return self.fd_popGestureRecognizerDelegate.delegate;
}

- (void)setFd_fullscreenPopGestureRecognizerDelegate:(id<UIGestureRecognizerDelegate>)fd_fullscreenPopGestureRecognizerDelegate
{
self.fd_popGestureRecognizerDelegate.delegate = fd_fullscreenPopGestureRecognizerDelegate;
}

@end

@implementation UIViewController (FDFullscreenPopGesture)
Expand Down