Skip to content

Commit

Permalink
Navigation controller delegate injection support (#10)
Browse files Browse the repository at this point in the history
  • Loading branch information
aronbalog committed Nov 2, 2016
1 parent b3f8fd2 commit d97215c
Show file tree
Hide file tree
Showing 11 changed files with 82 additions and 8 deletions.
4 changes: 2 additions & 2 deletions ARoute.podspec
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Pod::Spec.new do |s|

s.name = "ARoute"
s.version = "0.0.12"
s.version = "0.0.13"
s.summary = "ARoute"

s.description = <<-DESC
Expand All @@ -14,7 +14,7 @@ Pod::Spec.new do |s|
s.platform = :ios
s.platform = :ios, "8.0"

s.source = { :git => "https://github.com/aronbalog/ARoute.git", :tag => "0.0.12" }
s.source = { :git => "https://github.com/aronbalog/ARoute.git", :tag => "0.0.13" }
s.source_files = "ARoute", "ARoute/**/*.{h,m}"
s.public_header_files = "ARoute/Classes/Public/**/*.h"
s.requires_arc = true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,6 @@
@interface UIViewController (TransitioningDelegate)

@property (strong, nonatomic, nullable) id <UIViewControllerTransitioningDelegate> aroute_transitioningDelegate;
@property (strong, nonatomic, nullable) id <UINavigationControllerDelegate> aroute_navigationControllerDelegate;

@end
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
@implementation UIViewController (TransitioningDelegate)

@dynamic aroute_transitioningDelegate;
@dynamic aroute_navigationControllerDelegate;

- (void)setAroute_transitioningDelegate:(id<UIViewControllerTransitioningDelegate>)aroute_transitioningDelegate
{
Expand All @@ -23,4 +24,14 @@ - (void)setAroute_transitioningDelegate:(id<UIViewControllerTransitioningDelegat
return objc_getAssociatedObject(self, @selector(aroute_transitioningDelegate));
}

- (void)setAroute_navigationControllerDelegate:(id<UINavigationControllerDelegate>)aroute_navigationControllerDelegate
{
objc_setAssociatedObject(self, @selector(aroute_navigationControllerDelegate), aroute_navigationControllerDelegate, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
}

- (id<UINavigationControllerDelegate>)aroute_navigationControllerDelegate
{
return objc_getAssociatedObject(self, @selector(aroute_navigationControllerDelegate));
}

@end
30 changes: 30 additions & 0 deletions ARoute/Classes/Private/Request/ARouteRequest.m
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,15 @@ - (void)push

- (void)push:(void (^)(ARouteResponse * _Nonnull))routeResponse
{
[self push:nil routeResponse:routeResponse];
}

- (void)push:(id<UINavigationControllerDelegate> _Nullable (^)())navigationControllerDelegate routeResponse:(void (^)(ARouteResponse * _Nonnull))routeResponse
{
if (navigationControllerDelegate) {
self.configuration.navigationViewControllerDelegateBlock = navigationControllerDelegate;
}

[self.executor pushRouteRequest:self routeResponse:routeResponse];
}

Expand All @@ -216,6 +225,27 @@ - (UIViewController *)embeddingViewController
return [self.executor embeddingViewControllerForRouteRequest:self];
}

- (void)pop:(BOOL)animated
{
[self pop:animated navigationControllerDelegate:nil];
}

- (void)pop:(BOOL)animated navigationControllerDelegate:(id<UINavigationControllerDelegate> _Nullable (^ _Nullable)())navigationControllerDelegate
{
UIViewController *currentViewController = [UIViewController visibleViewController:nil];
UINavigationController *navigationController = currentViewController.navigationController;
if (!navigationController) {
navigationController = [currentViewController isKindOfClass:[UINavigationController class]] ? (UINavigationController *)currentViewController : nil;
}

if ([navigationController isKindOfClass:[UINavigationController class]]) {
if (navigationControllerDelegate) {
navigationController.delegate = navigationControllerDelegate();
}
[navigationController popViewControllerAnimated:animated];
}
}

#pragma mark - Private

- (ARouteRequestConfiguration *)configuration
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
@property (strong, nonatomic, nullable) BOOL (^protectBlock)(ARouteResponse * _Nonnull routeResponse, NSError * __autoreleasing _Nullable * _Nullable errorPtr);
@property (strong, nonatomic, nullable) NSDictionary <id, id> * _Nullable(^parametersBlock)();
@property (strong, nonatomic, nullable) id <UIViewControllerTransitioningDelegate> _Nullable(^transitioningDelegateBlock)();
@property (strong, nonatomic, nullable) id <UINavigationControllerDelegate> _Nullable(^navigationViewControllerDelegateBlock)();
@property (assign, nonatomic) ARouteEmbeddingType embeddingType;
@property (strong, nonatomic, nonnull) NSArray *_Nullable(^ previousViewControllersBlock)(ARouteResponse * _Nonnull routeResponse);
@property (strong, nonatomic, nullable) Class _Nullable(^ navigationControllerClassBlock)(ARouteResponse * _Nonnull routeResponse);
Expand Down
10 changes: 10 additions & 0 deletions ARoute/Classes/Private/RequestExecutor/ARouteRequestExecutor.m
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,16 @@ - (void)pushRouteRequest:(ARouteRequest *)routeRequest routeResponse:(void (^)(A
}

if (navigationController) {
id <UINavigationControllerDelegate> delegate;
if (routeRequest.configuration.navigationViewControllerDelegateBlock) {
delegate = routeRequest.configuration.navigationViewControllerDelegateBlock();
}

if (delegate) {
navigationController.aroute_navigationControllerDelegate = delegate;
navigationController.delegate = navigationController.aroute_navigationControllerDelegate;
}

[navigationController pushViewController:destinationViewController animated:animated];
if (routeRequest.configuration.completionBlock) {
routeRequest.configuration.completionBlock(routeResponse);
Expand Down
3 changes: 3 additions & 0 deletions ARoute/Classes/Public/Protocols/ARouteRequestExecutable.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,11 @@
- (void)execute;
- (void)execute:(void(^ _Nullable)(ARouteResponse * _Nonnull routeResponse))routeResponse;
- (void)push;
- (void)push:(id <UINavigationControllerDelegate> _Nullable (^ _Nullable)())navigationControllerDelegate routeResponse:(void(^ _Nullable)(ARouteResponse * _Nonnull routeResponse))routeResponse;
- (void)push:(void(^ _Nullable)(ARouteResponse * _Nonnull routeResponse))routeResponse;
- (nullable __kindof UIViewController *)viewController;
- (nullable __kindof UIViewController *)embeddingViewController;
- (void)pop:(BOOL)animated;
- (void)pop:(BOOL)animated navigationControllerDelegate:(id <UINavigationControllerDelegate> _Nullable (^ _Nullable)())navigationControllerDelegate;

@end
12 changes: 11 additions & 1 deletion Example/ARoute.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -355,7 +355,7 @@
isa = PBXProject;
attributes = {
CLASSPREFIX = ARoute;
LastUpgradeCheck = 0720;
LastUpgradeCheck = 0800;
ORGANIZATIONNAME = "Aron Balog";
TargetAttributes = {
6003F589195388D20070C39A = {
Expand Down Expand Up @@ -580,14 +580,19 @@
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
CLANG_WARN_EMPTY_BODY = YES;
CLANG_WARN_ENUM_CONVERSION = YES;
CLANG_WARN_INFINITE_RECURSION = YES;
CLANG_WARN_INT_CONVERSION = YES;
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
CLANG_WARN_SUSPICIOUS_MOVE = YES;
CLANG_WARN_UNREACHABLE_CODE = YES;
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
COPY_PHASE_STRIP = NO;
ENABLE_STRICT_OBJC_MSGSEND = YES;
ENABLE_TESTABILITY = YES;
GCC_C_LANGUAGE_STANDARD = gnu99;
GCC_DYNAMIC_NO_PIC = NO;
GCC_NO_COMMON_BLOCKS = YES;
GCC_OPTIMIZATION_LEVEL = 0;
GCC_PREPROCESSOR_DEFINITIONS = (
"DEBUG=1",
Expand Down Expand Up @@ -620,13 +625,18 @@
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
CLANG_WARN_EMPTY_BODY = YES;
CLANG_WARN_ENUM_CONVERSION = YES;
CLANG_WARN_INFINITE_RECURSION = YES;
CLANG_WARN_INT_CONVERSION = YES;
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
CLANG_WARN_SUSPICIOUS_MOVE = YES;
CLANG_WARN_UNREACHABLE_CODE = YES;
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
COPY_PHASE_STRIP = YES;
ENABLE_NS_ASSERTIONS = NO;
ENABLE_STRICT_OBJC_MSGSEND = YES;
GCC_C_LANGUAGE_STANDARD = gnu99;
GCC_NO_COMMON_BLOCKS = YES;
GCC_WARN_64_TO_32_BIT_CONVERSION = YES;
GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR;
GCC_WARN_UNDECLARED_SELECTOR = YES;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "0720"
LastUpgradeVersion = "0800"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
Expand Down
10 changes: 9 additions & 1 deletion Example/Pods/Pods.xcodeproj/project.pbxproj

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit d97215c

Please sign in to comment.