Skip to content
This repository has been archived by the owner on Aug 30, 2023. It is now read-only.

Commit

Permalink
Backport MDMTransitionWithFeasibility from the v4.0.0 release for v3.…
Browse files Browse the repository at this point in the history
…1 clients.
  • Loading branch information
Jeff Verkoeyen committed Oct 2, 2017
1 parent a5d56f7 commit 1f994d0
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
20 changes: 20 additions & 0 deletions src/MDMTransition.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 <MDMTransition>

/**
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<MDMTransitionContext>)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
Expand Down
10 changes: 9 additions & 1 deletion src/private/MDMViewControllerTransitionContext.m
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,15 @@ - (nonnull instancetype)initWithTransition:(nonnull id<MDMTransition>)transition

_completionBlocks = [NSMutableArray array];

_transition = [self fallbackForTransition:_transition];
if ([_transition respondsToSelector:@selector(canPerformTransitionWithContext:)]) {
id<MDMTransitionWithFeasibility> withFeasibility = (id<MDMTransitionWithFeasibility>)_transition;
if (![withFeasibility canPerformTransitionWithContext:self]) {
_transition = nil;
}
} else {
_transition = [self fallbackForTransition:_transition];
}

if (!_transition) {
return nil;
}
Expand Down

0 comments on commit 1f994d0

Please sign in to comment.