From 0685e9aaaad8c2d22941f87bda3aad208b657aad Mon Sep 17 00:00:00 2001
From: Shaw <cuzval@gmail.com>
Date: Fri, 5 Jan 2018 14:36:06 +0800
Subject: [PATCH] Re-implement UINavigationControllerDelegate;

---
 CHANGELOG.md                                  |   7 +-
 README.md                                     |   2 +-
 RRNavigationBar.podspec                       |   2 +-
 RRNavigationBar.xcodeproj/project.pbxproj     |  16 ++-
 Sources/RRNavigationBar.h                     |   3 +-
 Sources/RRNavigationControllerDelegate.h      |  39 -------
 .../UINavigationController+RRNavigationBar.h  |   5 +-
 .../UINavigationController+RRNavigationBar.m  | 108 +++++-------------
 ...ationController+RRNavigationBar_Internal.h |  31 +++++
 Sources/_RRNavigationControllerDelegateImpl.h |  15 +++
 Sources/_RRNavigationControllerDelegateImpl.m |  79 +++++++++++++
 11 files changed, 175 insertions(+), 132 deletions(-)
 delete mode 100644 Sources/RRNavigationControllerDelegate.h
 create mode 100644 Sources/UINavigationController+RRNavigationBar_Internal.h
 create mode 100644 Sources/_RRNavigationControllerDelegateImpl.h
 create mode 100644 Sources/_RRNavigationControllerDelegateImpl.m

diff --git a/CHANGELOG.md b/CHANGELOG.md
index 5e15244..b6a61fe 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -37,4 +37,9 @@
 
 ### 0.4.0
 
-- `RRNavigationControllerDelegate`
\ No newline at end of file
+- `RRNavigationControllerDelegate`
+
+### 0.4.1
+
+- Remove `RRNavigationControllerDelegate`
+- Re-implement `UINavigationControllerDelegate`
\ No newline at end of file
diff --git a/README.md b/README.md
index 8b0673c..97dd6fa 100644
--- a/README.md
+++ b/README.md
@@ -1,5 +1,5 @@
 [![License](https://img.shields.io/badge/license-MIT-lightgrey.svg)](https://github.com/cuzv/RRNavigationBar/blob/master/LICENSE)
-[![CocoaPods Compatible](https://img.shields.io/badge/CocoaPods-v0.3.3-green.svg)](https://github.com/CocoaPods/CocoaPods)
+[![CocoaPods Compatible](https://img.shields.io/badge/CocoaPods-v0.4.1-green.svg)](https://github.com/CocoaPods/CocoaPods)
 [![Weibo](https://img.shields.io/badge/Weibo-cuzval-yellowgreen.svg)](https://weibo.com/cuzval/)
 [![Twitter](https://img.shields.io/twitter/url/http/shields.io.svg?style=social)](https://twitter.com/cuzval)
 
diff --git a/RRNavigationBar.podspec b/RRNavigationBar.podspec
index 527ba0d..4f2876c 100644
--- a/RRNavigationBar.podspec
+++ b/RRNavigationBar.podspec
@@ -1,6 +1,6 @@
 Pod::Spec.new do |s|
   s.name         = "RRNavigationBar"
-  s.version      = "0.4.0"
+  s.version      = "0.4.1"
   s.summary      = "bring `UINavigationBar` to` UIViewController`"
 
   s.homepage     = "https://github.com/cuzv/RRNavigationBar.git"
diff --git a/RRNavigationBar.xcodeproj/project.pbxproj b/RRNavigationBar.xcodeproj/project.pbxproj
index b209f47..396ff3c 100644
--- a/RRNavigationBar.xcodeproj/project.pbxproj
+++ b/RRNavigationBar.xcodeproj/project.pbxproj
@@ -33,6 +33,7 @@
 		46F46E0B1E7AEEB9000C8011 /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 46F46E001E7AEEB9000C8011 /* LaunchScreen.storyboard */; };
 		46F46E0D1E7AEEB9000C8011 /* AppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 46F46E051E7AEEB9000C8011 /* AppDelegate.m */; };
 		46F46E0F1E7AEEB9000C8011 /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 46F46E071E7AEEB9000C8011 /* main.m */; };
+		B45BD4411FFF46DA009280A5 /* _RRNavigationControllerDelegateImpl.m in Sources */ = {isa = PBXBuildFile; fileRef = B45BD4401FFF46DA009280A5 /* _RRNavigationControllerDelegateImpl.m */; };
 /* End PBXBuildFile section */
 
 /* Begin PBXFileReference section */
@@ -88,7 +89,9 @@
 		46F46E051E7AEEB9000C8011 /* AppDelegate.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = AppDelegate.m; sourceTree = "<group>"; };
 		46F46E061E7AEEB9000C8011 /* Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
 		46F46E071E7AEEB9000C8011 /* main.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = main.m; sourceTree = "<group>"; };
-		B40F69961FFE2E98007C1237 /* RRNavigationControllerDelegate.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = RRNavigationControllerDelegate.h; sourceTree = "<group>"; };
+		B45BD43F1FFF46DA009280A5 /* _RRNavigationControllerDelegateImpl.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = _RRNavigationControllerDelegateImpl.h; sourceTree = "<group>"; };
+		B45BD4401FFF46DA009280A5 /* _RRNavigationControllerDelegateImpl.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = _RRNavigationControllerDelegateImpl.m; sourceTree = "<group>"; };
+		B48E82781FFF4AC300A90F38 /* UINavigationController+RRNavigationBar_Internal.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "UINavigationController+RRNavigationBar_Internal.h"; sourceTree = "<group>"; };
 /* End PBXFileReference section */
 
 /* Begin PBXFrameworksBuildPhase section */
@@ -198,21 +201,23 @@
 				4625A81F1E8918070092247A /* RRNavigationBar.h */,
 				460410F21E82BF9200FC3E2B /* UIViewController+RRNavigationBar.h */,
 				460410F31E82BF9200FC3E2B /* UIViewController+RRNavigationBar.m */,
+				B48E82781FFF4AC300A90F38 /* UINavigationController+RRNavigationBar_Internal.h */,
 				465E1C291E8662830082389A /* UINavigationController+RRNavigationBar.h */,
 				465E1C2A1E8662830082389A /* UINavigationController+RRNavigationBar.m */,
 				4625A81E1E8917C20092247A /* UINavigationBar+RRNavigationBar_Internal.h */,
 				465FE9D41E87E92A000654C1 /* UINavigationBar+RRNavigationBar.h */,
 				465FE9D51E87E92A000654C1 /* UINavigationBar+RRNavigationBar.m */,
+				46C3CF1F1F6E884100FF682B /* UIView+RRNavigationBar_internal.h */,
+				46C3CF201F6E925E00FF682B /* UIView+RRNavigationBar.h */,
+				46C3CF1D1F6E870200FF682B /* UIView+RRNavigationBar.m */,
 				4625A8191E88F4B40092247A /* _RRNavigationBar.h */,
 				4625A81A1E88F4B40092247A /* _RRNavigationBar.m */,
 				46C646F61E8A377500A3349A /* _RRWeakAssociatedObjectWrapper.h */,
 				46C646F71E8A377500A3349A /* _RRWeakAssociatedObjectWrapper.m */,
+				B45BD43F1FFF46DA009280A5 /* _RRNavigationControllerDelegateImpl.h */,
+				B45BD4401FFF46DA009280A5 /* _RRNavigationControllerDelegateImpl.m */,
 				465E1C2C1E8662CF0082389A /* RRUtils.h */,
 				465E1C2D1E8662CF0082389A /* RRUtils.m */,
-				46C3CF1F1F6E884100FF682B /* UIView+RRNavigationBar_internal.h */,
-				46C3CF201F6E925E00FF682B /* UIView+RRNavigationBar.h */,
-				46C3CF1D1F6E870200FF682B /* UIView+RRNavigationBar.m */,
-				B40F69961FFE2E98007C1237 /* RRNavigationControllerDelegate.h */,
 			);
 			path = Sources;
 			sourceTree = "<group>";
@@ -303,6 +308,7 @@
 				465E1C2B1E8662830082389A /* UINavigationController+RRNavigationBar.m in Sources */,
 				4625A8311E8938A60092247A /* Helper.m in Sources */,
 				46C3CF1E1F6E870200FF682B /* UIView+RRNavigationBar.m in Sources */,
+				B45BD4411FFF46DA009280A5 /* _RRNavigationControllerDelegateImpl.m in Sources */,
 				466E980F1F7543F900B9BD91 /* NoneTranslucentNextViewController.m in Sources */,
 				4625A81B1E88F4B40092247A /* _RRNavigationBar.m in Sources */,
 				466E980C1F7542CA00B9BD91 /* NoneTranslucentViewController.m in Sources */,
diff --git a/Sources/RRNavigationBar.h b/Sources/RRNavigationBar.h
index 81f7603..fddbd42 100644
--- a/Sources/RRNavigationBar.h
+++ b/Sources/RRNavigationBar.h
@@ -10,9 +10,8 @@
 #define RRNavigationBar_h
 
 #import "UIViewController+RRNavigationBar.h"
-#import "UINavigationController+RRNavigationBar.h"
 #import "UINavigationBar+RRNavigationBar.h"
+#import "UINavigationController+RRNavigationBar.h"
 #import "RRUtils.h"
-#import "RRNavigationControllerDelegate.h"
 
 #endif /* RRNavigationBar_h */
diff --git a/Sources/RRNavigationControllerDelegate.h b/Sources/RRNavigationControllerDelegate.h
deleted file mode 100644
index fdbc8bf..0000000
--- a/Sources/RRNavigationControllerDelegate.h
+++ /dev/null
@@ -1,39 +0,0 @@
-//
-//  RRNavigationControllerDelegate.h
-//  RRNavigationBar
-//
-//  Created by Roy Shaw on 1/4/18.
-//  Copyright © 2018 RedRain. All rights reserved.
-//
-
-#ifndef RRNavigationControllerDelegate_h
-#define RRNavigationControllerDelegate_h
-
-#import <UIKit/UIKit.h>
-
-NS_ASSUME_NONNULL_BEGIN
-
-@protocol RRNavigationControllerDelegate <NSObject>
-
-@optional
-
-// Called when the navigation controller shows a new top view controller via a push, pop or setting of the view controller stack.
-- (void)rr_navigationController:(UINavigationController *)navigationController willShowViewController:(UIViewController *)viewController animated:(BOOL)animated;
-- (void)rr_navigationController:(UINavigationController *)navigationController didShowViewController:(UIViewController *)viewController animated:(BOOL)animated;
-
-- (UIInterfaceOrientationMask)rr_navigationControllerSupportedInterfaceOrientations:(UINavigationController *)navigationController NS_AVAILABLE_IOS(7_0) __TVOS_PROHIBITED;
-- (UIInterfaceOrientation)rr_navigationControllerPreferredInterfaceOrientationForPresentation:(UINavigationController *)navigationController NS_AVAILABLE_IOS(7_0) __TVOS_PROHIBITED;
-
-- (nullable id <UIViewControllerInteractiveTransitioning>)rr_navigationController:(UINavigationController *)navigationController
-                                   interactionControllerForAnimationController:(id <UIViewControllerAnimatedTransitioning>) animationController NS_AVAILABLE_IOS(7_0);
-
-- (nullable id <UIViewControllerAnimatedTransitioning>)rr_navigationController:(UINavigationController *)navigationController
-                                            animationControllerForOperation:(UINavigationControllerOperation)operation
-                                                         fromViewController:(UIViewController *)fromVC
-                                                           toViewController:(UIViewController *)toVC  NS_AVAILABLE_IOS(7_0);
-
-@end
-
-NS_ASSUME_NONNULL_END
-
-#endif /* RRNavigationControllerDelegate_h */
diff --git a/Sources/UINavigationController+RRNavigationBar.h b/Sources/UINavigationController+RRNavigationBar.h
index f76a5a8..67bfe86 100644
--- a/Sources/UINavigationController+RRNavigationBar.h
+++ b/Sources/UINavigationController+RRNavigationBar.h
@@ -8,10 +8,9 @@
 
 #import <UIKit/UIKit.h>
 
-@protocol RRNavigationControllerDelegate;
-
 @interface UINavigationController (RRNavigationBar)
 
-@property(nullable, nonatomic, weak) id<RRNavigationControllerDelegate> rr_delegate;
+/// Acquire the `UINavigationControllerDelegate` you set before.
+@property(nullable, nonatomic, weak, readonly) id<UINavigationControllerDelegate> rr_delegate;
 
 @end
diff --git a/Sources/UINavigationController+RRNavigationBar.m b/Sources/UINavigationController+RRNavigationBar.m
index bc90e3f..eb50d1a 100644
--- a/Sources/UINavigationController+RRNavigationBar.m
+++ b/Sources/UINavigationController+RRNavigationBar.m
@@ -6,6 +6,8 @@
 //  Copyright © 2017 RedRain. All rights reserved.
 //
 
+#import "UINavigationController+RRNavigationBar.h"
+#import "UINavigationController+RRNavigationBar_Internal.h"
 #import "UINavigationBar+RRNavigationBar.h"
 #import "UINavigationBar+RRNavigationBar_Internal.h"
 #import <objc/runtime.h>
@@ -13,7 +15,7 @@
 #import "RRUtils.h"
 #import "_RRWeakAssociatedObjectWrapper.h"
 #import "UIView+RRNavigationBar_internal.h"
-#import "RRNavigationControllerDelegate.h"
+#import "_RRNavigationControllerDelegateImpl.h"
 
 #ifndef RRRecoverObject
 #   define RRRecoverObject(from, to, info, property) (to.property = info[@#property] ?: from.property)
@@ -31,19 +33,6 @@
 #   define RRRecoverDobule(from, to, info, property) (to.property = info[@#property] ? [info[@#property] doubleValue] : from.property)
 #endif
 
-#ifndef RRExcludeImpactBehaviorFor
-#   define RRExcludeImpactBehaviorFor(instance) \
-        for (Class clazz in _excludeNVCClassess) { \
-            if ([instance isKindOfClass:clazz]) { return; } \
-        } \
-        for (UINavigationController *nvc in _excludeNVCInstance) { \
-            if ([instance isEqual:nvc]) { return; } \
-        }
-#endif
-
-static NSMutableSet *_excludeNVCClassess;
-static NSMutableSet *_excludeNVCInstance;
-
 void RRNavigationBarExcludeImpactBehaviorForClass(Class _Nonnull nvcClass) {
     if (![nvcClass isSubclassOfClass:UINavigationController.class]) {
         return;
@@ -60,9 +49,10 @@ void RRNavigationBarExcludeImpactBehaviorForInstance(__kindof UINavigationContro
     [_excludeNVCInstance addObject:nvc];
 }
 
-@interface UINavigationController ()<UINavigationControllerDelegate, UIGestureRecognizerDelegate>
+@interface UINavigationController ()<UIGestureRecognizerDelegate>
 @property (nonatomic, weak, nullable) UIViewController *_visibleTopViewController;
 @property (nonatomic, assign) BOOL _navigationBarInitialized;
+@property (nonatomic, retain, nullable) _RRNavigationControllerDelegateImpl *_delegateImpl;
 @end
 
 @implementation UINavigationController (RRNavigationBar)
@@ -73,6 +63,7 @@ + (void)load {
         RRSwizzleInstanceMethod(self.class, @selector(viewDidLoad), @selector(_rr_nvc_viewDidLoad));
         RRSwizzleInstanceMethod(self.class, @selector(viewWillLayoutSubviews), @selector(_rr_nvc_viewWillLayoutSubviews));
         RRSwizzleInstanceMethod(self.class, @selector(preferredStatusBarStyle), @selector(_rr_nvc_preferredStatusBarStyle));
+        RRSwizzleInstanceMethod(self.class, @selector(setDelegate:), @selector(_rr_setDelegate:));
     });
 }
 
@@ -88,8 +79,8 @@ - (void)_rr_nvc_viewDidLoad {
     });
     
     RRExcludeImpactBehaviorFor(self);
-    
-    self.delegate = self;
+    self._delegateImpl = [_RRNavigationControllerDelegateImpl new];
+    self.delegate = self._delegateImpl;
     self.interactivePopGestureRecognizer.delegate = self;
 }
 
@@ -137,6 +128,14 @@ - (UIStatusBarStyle)_rr_nvc_preferredStatusBarStyle {
     return self._rr_nvc_preferredStatusBarStyle;
 }
 
+- (void)_rr_setDelegate:(nonnull id<UINavigationControllerDelegate>)delegate {
+    [self _rr_setDelegate:self._delegateImpl];
+    
+    if (delegate != self._delegateImpl) {
+        self._delegateImpl.delegate = delegate;
+    }
+}
+
 #pragma mark - Private
 
 - (nullable UIViewController *)_visibleTopViewController {
@@ -156,6 +155,18 @@ - (void)set_navigationBarInitialized:(BOOL)_navigationBarInitialized {
     objc_setAssociatedObject(self, @selector(_navigationBarInitialized), @(_navigationBarInitialized), OBJC_ASSOCIATION_RETAIN_NONATOMIC);
 }
 
+- (_RRNavigationControllerDelegateImpl *)_delegateImpl {
+    return objc_getAssociatedObject(self, _cmd);
+}
+
+- (void)set_delegateImpl:(_RRNavigationControllerDelegateImpl *)_delegateImpl {
+    objc_setAssociatedObject(self, @selector(_delegateImpl), _delegateImpl, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
+}
+
+- (id<UINavigationControllerDelegate>)rr_delegate {
+    return self._delegateImpl.delegate;
+}
+
 #pragma mark -
 
 - (void)_handleWillShowViewController:(UIViewController *)viewController {
@@ -309,69 +320,6 @@ - (void)_rr_restoreContentInsetAdjustmentBehaviorIfNeededForViewController:(UIVi
 
 #endif
 
-#pragma mark - UINavigationControllerDelegate
-
-- (nullable id <RRNavigationControllerDelegate>)rr_delegate {
-    return ((_RRWeakAssociatedObjectWrapper *)objc_getAssociatedObject(self, _cmd)).object;
-}
-
-- (void)setRr_delegate:(id <RRNavigationControllerDelegate>)rr_delegate {
-    _RRWeakAssociatedObjectWrapper *wrapper = [[_RRWeakAssociatedObjectWrapper alloc] initWithObject:rr_delegate];
-    objc_setAssociatedObject(self, @selector(rr_delegate), wrapper, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
-}
-
-#pragma mark -
-
-- (void)navigationController:(UINavigationController *)navigationController willShowViewController:(UIViewController *)viewController animated:(BOOL)animated {
-    if (self.rr_delegate && [self.rr_delegate respondsToSelector:@selector(rr_navigationController:willShowViewController:animated:)]) {
-        [self.rr_delegate rr_navigationController:navigationController willShowViewController:viewController animated:animated];
-    }
-    
-    RRExcludeImpactBehaviorFor(navigationController);
-    [self _handleWillShowViewController:viewController];
-}
-
-- (void)navigationController:(UINavigationController *)navigationController didShowViewController:(UIViewController *)viewController animated:(BOOL)animated {
-    if (self.rr_delegate && [self.rr_delegate respondsToSelector:@selector(rr_navigationController:didShowViewController:animated:)]) {
-        [self.rr_delegate rr_navigationController:navigationController didShowViewController:viewController animated:animated];
-    }
-    
-    RRExcludeImpactBehaviorFor(navigationController);
-    [self _handleDidShowViewController:viewController];
-}
-
-- (UIInterfaceOrientationMask)navigationControllerSupportedInterfaceOrientations:(UINavigationController *)navigationController {
-    if (self.rr_delegate && [self.rr_delegate respondsToSelector:@selector(rr_navigationControllerSupportedInterfaceOrientations:)]) {
-        return [self.rr_delegate rr_navigationControllerSupportedInterfaceOrientations:navigationController];
-    }
-    return UIInterfaceOrientationMaskAll;
-}
-
-- (UIInterfaceOrientation)navigationControllerPreferredInterfaceOrientationForPresentation:(UINavigationController *)navigationController {
-    if (self.rr_delegate && [self.rr_delegate respondsToSelector:@selector(rr_navigationControllerPreferredInterfaceOrientationForPresentation:)]) {
-        return [self.rr_delegate rr_navigationControllerPreferredInterfaceOrientationForPresentation:navigationController];
-    }
-    return UIInterfaceOrientationUnknown;
-}
-
-- (nullable id <UIViewControllerInteractiveTransitioning>)navigationController:(UINavigationController *)navigationController
-                                   interactionControllerForAnimationController:(id <UIViewControllerAnimatedTransitioning>) animationController {
-    if (self.rr_delegate && [self.rr_delegate respondsToSelector:@selector(rr_navigationController:interactionControllerForAnimationController:)]) {
-        return [self.rr_delegate rr_navigationController:navigationController interactionControllerForAnimationController:animationController];
-    }
-    return nil;
-}
-
-- (nullable id <UIViewControllerAnimatedTransitioning>)navigationController:(UINavigationController *)navigationController
-                                            animationControllerForOperation:(UINavigationControllerOperation)operation
-                                                         fromViewController:(UIViewController *)fromVC
-                                                           toViewController:(UIViewController *)toVC  {
-    if (self.rr_delegate && [self.rr_delegate respondsToSelector:@selector(rr_navigationController:animationControllerForOperation:fromViewController:toViewController:)]) {
-        return [self.rr_delegate rr_navigationController:navigationController animationControllerForOperation:operation fromViewController:fromVC toViewController:toVC];
-    }
-    return nil;
-}
-
 #pragma mark - UIGestureRecognizerDelegate
 
 - (BOOL)gestureRecognizerShouldBegin:(UIGestureRecognizer *)gestureRecognizer {
diff --git a/Sources/UINavigationController+RRNavigationBar_Internal.h b/Sources/UINavigationController+RRNavigationBar_Internal.h
new file mode 100644
index 0000000..e36c767
--- /dev/null
+++ b/Sources/UINavigationController+RRNavigationBar_Internal.h
@@ -0,0 +1,31 @@
+//
+//  UINavigationController+RRNavigationBar_Internal.h
+//  RRNavigationBar
+//
+//  Created by Roy Shaw on 1/5/18.
+//  Copyright © 2018 RedRain. All rights reserved.
+//
+
+NS_ASSUME_NONNULL_BEGIN
+
+static NSMutableSet *_excludeNVCClassess;
+static NSMutableSet *_excludeNVCInstance;
+
+#ifndef RRExcludeImpactBehaviorFor
+#   define RRExcludeImpactBehaviorFor(instance) \
+        for (Class clazz in _excludeNVCClassess) { \
+            if ([instance isKindOfClass:clazz]) { return; } \
+        } \
+        for (UINavigationController *nvc in _excludeNVCInstance) { \
+            if ([instance isEqual:nvc]) { return; } \
+        }
+#endif
+
+@interface UINavigationController (RRNavigationBar_Internal)
+
+- (void)_handleWillShowViewController:(UIViewController *)viewController;
+- (void)_handleDidShowViewController:(UIViewController *)viewController;
+
+@end
+
+NS_ASSUME_NONNULL_END
diff --git a/Sources/_RRNavigationControllerDelegateImpl.h b/Sources/_RRNavigationControllerDelegateImpl.h
new file mode 100644
index 0000000..503293f
--- /dev/null
+++ b/Sources/_RRNavigationControllerDelegateImpl.h
@@ -0,0 +1,15 @@
+//
+//  _RRNavigationControllerDelegateImpl.h
+//  RRNavigationBar
+//
+//  Created by Roy Shaw on 1/5/18.
+//  Copyright © 2018 RedRain. All rights reserved.
+//
+
+#import <UIKit/UIKit.h>
+
+@interface _RRNavigationControllerDelegateImpl : NSObject <UINavigationControllerDelegate>
+
+@property(nullable, nonatomic, weak) id<UINavigationControllerDelegate> delegate;
+
+@end
diff --git a/Sources/_RRNavigationControllerDelegateImpl.m b/Sources/_RRNavigationControllerDelegateImpl.m
new file mode 100644
index 0000000..2626479
--- /dev/null
+++ b/Sources/_RRNavigationControllerDelegateImpl.m
@@ -0,0 +1,79 @@
+//
+//  _RRNavigationControllerDelegateImpl.m
+//  RRNavigationBar
+//
+//  Created by Roy Shaw on 1/5/18.
+//  Copyright © 2018 RedRain. All rights reserved.
+//
+
+#import "_RRNavigationControllerDelegateImpl.h"
+#import "UINavigationController+RRNavigationBar_Internal.h"
+
+@implementation _RRNavigationControllerDelegateImpl
+
+#pragma mark -
+
+- (void)navigationController:(UINavigationController *)navigationController willShowViewController:(UIViewController *)viewController animated:(BOOL)animated {
+    if (self.delegate && [self.delegate respondsToSelector:@selector(navigationController:willShowViewController:animated:)]) {
+        [self.delegate navigationController:navigationController willShowViewController:viewController animated:animated];
+    }
+    
+    RRExcludeImpactBehaviorFor(navigationController);
+    [navigationController _handleWillShowViewController:viewController];
+}
+
+- (void)navigationController:(UINavigationController *)navigationController didShowViewController:(UIViewController *)viewController animated:(BOOL)animated {
+    if (self.delegate && [self.delegate respondsToSelector:@selector(navigationController:didShowViewController:animated:)]) {
+        [self.delegate navigationController:navigationController didShowViewController:viewController animated:animated];
+    }
+    
+    RRExcludeImpactBehaviorFor(navigationController);
+    [navigationController _handleDidShowViewController:viewController];
+}
+
+- (UIInterfaceOrientationMask)navigationControllerSupportedInterfaceOrientations:(UINavigationController *)navigationController {
+    if (self.delegate && [self.delegate respondsToSelector:@selector(navigationControllerSupportedInterfaceOrientations:)]) {
+        return [self.delegate navigationControllerSupportedInterfaceOrientations:navigationController];
+    }
+    return UIInterfaceOrientationMaskAll;
+}
+
+- (UIInterfaceOrientation)navigationControllerPreferredInterfaceOrientationForPresentation:(UINavigationController *)navigationController {
+    if (self.delegate && [self.delegate respondsToSelector:@selector(navigationControllerPreferredInterfaceOrientationForPresentation:)]) {
+        return [self.delegate navigationControllerPreferredInterfaceOrientationForPresentation:navigationController];
+    }
+    
+    switch (UIDevice.currentDevice.orientation) {
+        case UIDeviceOrientationUnknown:
+        case UIDeviceOrientationFaceUp:
+        case UIDeviceOrientationFaceDown:
+        case UIDeviceOrientationPortrait:
+            return UIInterfaceOrientationPortrait;
+        case UIDeviceOrientationLandscapeLeft:
+            return UIInterfaceOrientationLandscapeLeft;
+        case UIDeviceOrientationLandscapeRight:
+            return UIInterfaceOrientationLandscapeRight;
+        case UIDeviceOrientationPortraitUpsideDown:
+            return UIInterfaceOrientationPortraitUpsideDown;
+    }
+}
+
+- (nullable id <UIViewControllerInteractiveTransitioning>)navigationController:(UINavigationController *)navigationController
+                                   interactionControllerForAnimationController:(id <UIViewControllerAnimatedTransitioning>) animationController {
+    if (self.delegate && [self.delegate respondsToSelector:@selector(navigationController:interactionControllerForAnimationController:)]) {
+        return [self.delegate navigationController:navigationController interactionControllerForAnimationController:animationController];
+    }
+    return nil;
+}
+
+- (nullable id <UIViewControllerAnimatedTransitioning>)navigationController:(UINavigationController *)navigationController
+                                            animationControllerForOperation:(UINavigationControllerOperation)operation
+                                                         fromViewController:(UIViewController *)fromVC
+                                                           toViewController:(UIViewController *)toVC  {
+    if (self.delegate && [self.delegate respondsToSelector:@selector(navigationController:animationControllerForOperation:fromViewController:toViewController:)]) {
+        return [self.delegate navigationController:navigationController animationControllerForOperation:operation fromViewController:fromVC toViewController:toVC];
+    }
+    return nil;
+}
+
+@end