From 1f994d03c7971001cc8faafe61b3ed2f55bca118 Mon Sep 17 00:00:00 2001 From: Jeff Verkoeyen Date: Mon, 2 Oct 2017 14:54:08 -0400 Subject: [PATCH] Backport MDMTransitionWithFeasibility from the v4.0.0 release for v3.1 clients. --- src/MDMTransition.h | 20 +++++++++++++++++++ .../MDMViewControllerTransitionContext.m | 10 +++++++++- 2 files changed, 29 insertions(+), 1 deletion(-) diff --git a/src/MDMTransition.h b/src/MDMTransition.h index a1ed123..cc09681 100644 --- a/src/MDMTransition.h +++ b/src/MDMTransition.h @@ -72,6 +72,26 @@ NS_SWIFT_NAME(TransitionWithFallback) @end +/** + A transition with feasibility can indicate whether it's capable of handling a given context. + */ +NS_SWIFT_NAME(TransitionWithFeasibility) +@protocol MDMTransitionWithFeasibility + +/** + Asks the receiver whether it's capable of performing the transition with the given context. + + If NO is returned, the receiver's startWithContext: will not be invoked. + If the transition is infeasible, then a default UIKit transition will be performed instead. + + If YES is returned, the receiver's startWithContext: will be invoked. + + The context's containerView will be nil during this call. + */ +- (BOOL)canPerformTransitionWithContext:(nonnull id)context; + +@end + /** A transition with presentation is able to customize the overall presentation of the transition, including adding temporary views and changing the destination frame of the presented view diff --git a/src/private/MDMViewControllerTransitionContext.m b/src/private/MDMViewControllerTransitionContext.m index c5974cb..ff617e9 100644 --- a/src/private/MDMViewControllerTransitionContext.m +++ b/src/private/MDMViewControllerTransitionContext.m @@ -46,7 +46,15 @@ - (nonnull instancetype)initWithTransition:(nonnull id)transition _completionBlocks = [NSMutableArray array]; - _transition = [self fallbackForTransition:_transition]; + if ([_transition respondsToSelector:@selector(canPerformTransitionWithContext:)]) { + id withFeasibility = (id)_transition; + if (![withFeasibility canPerformTransitionWithContext:self]) { + _transition = nil; + } + } else { + _transition = [self fallbackForTransition:_transition]; + } + if (!_transition) { return nil; }