diff --git a/MVMCore/MVMCore/LoadHandling/MVMCoreLoadRequestOperation.m b/MVMCore/MVMCore/LoadHandling/MVMCoreLoadRequestOperation.m index e989287..dca4a10 100644 --- a/MVMCore/MVMCore/LoadHandling/MVMCoreLoadRequestOperation.m +++ b/MVMCore/MVMCore/LoadHandling/MVMCoreLoadRequestOperation.m @@ -867,6 +867,14 @@ } } +- (id )navigationController:(UINavigationController *)navigationController interactionControllerForAnimationController:(id)animationController { + if (self.delegate && [self.delegate respondsToSelector:@selector(navigationController:interactionControllerForAnimationController:)]) { + return [self.delegate navigationController:navigationController interactionControllerForAnimationController:animationController]; + } else { + return nil; + } +} + - (void)viewController:(UIViewController *)presentingViewController willPresentViewController:(UIViewController *)presentedViewController { if ([self.delegate respondsToSelector:@selector(viewController:willPresentViewController:)]) { diff --git a/MVMCore/MVMCore/PresentationHandling/MVMCoreNavigationHandler.m b/MVMCore/MVMCore/PresentationHandling/MVMCoreNavigationHandler.m index b6aa0aa..f46368c 100644 --- a/MVMCore/MVMCore/PresentationHandling/MVMCoreNavigationHandler.m +++ b/MVMCore/MVMCore/PresentationHandling/MVMCoreNavigationHandler.m @@ -193,6 +193,8 @@ MVMCoreNavigationObject *navigationObject = [[MVMCoreNavigationObject alloc] initWithViewController:viewController navigationController:navigationController viewControllers:nil animated:animated tryToReplaceFirst:replaceInStack navigationType:NavigationTypeReplaceTop]; [self startNavigationWithNavigationObject:navigationObject delegate:delegate completionHandler:completionBlock]; + + } - (void)replaceAfterRoot:(nonnull UIViewController *)viewController navigationController:(nullable UINavigationController *)navigationController animated:(BOOL)animated delegate:(nullable NSObject*)delegate replaceInStack:(BOOL)replaceInStack completionHandler:(nullable void (^)(void))completionBlock { diff --git a/MVMCore/MVMCore/PresentationHandling/MVMCoreNavigationOperation.m b/MVMCore/MVMCore/PresentationHandling/MVMCoreNavigationOperation.m index a1fda67..ffd3c82 100644 --- a/MVMCore/MVMCore/PresentationHandling/MVMCoreNavigationOperation.m +++ b/MVMCore/MVMCore/PresentationHandling/MVMCoreNavigationOperation.m @@ -106,7 +106,10 @@ // Replaces the current view controller. NSMutableArray *viewControllers = [NSMutableArray arrayWithArray:self.navigationObject.navigationController.viewControllers]; - [viewControllers replaceObjectAtIndex:([self.navigationObject.navigationController.viewControllers count] - 1) withObject:self.navigationObject.viewController]; + if (viewControllers.count > 1) { + [viewControllers removeObjectAtIndex:0]; + } + [viewControllers replaceObjectAtIndex:(viewControllers.count - 1) withObject:self.navigationObject.viewController]; [self setViewControllers:viewControllers]; } else { @@ -240,10 +243,30 @@ - (nullable id )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]; + id animatedTransitioning = [self.delegate navigationController:navigationController animationControllerForOperation:operation fromViewController:fromVC toViewController:toVC]; + [animatedTransitioning addObserver:self forKeyPath:@"interactiveTransitionCanceled" options:NSKeyValueObservingOptionOld | NSKeyValueObservingOptionNew context:nil]; + return animatedTransitioning; } else { return nil; } } +- (nullable id )navigationController:(UINavigationController *)navigationController interactionControllerForAnimationController:(id)animationController { + if (self.delegate && [self.delegate respondsToSelector:@selector(navigationController:interactionControllerForAnimationController:)]) { + id interactiveTransitioning = [self.delegate navigationController:navigationController interactionControllerForAnimationController:animationController]; + return interactiveTransitioning; + } else { + return nil; + } +} + +- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context { + if ([keyPath isEqualToString:@"interactiveTransitionCanceled"]) { + BOOL transitionStoped = ((NSNumber*)change[NSKeyValueChangeNewKey]).boolValue; + if (transitionStoped) { + [self markAsFinished]; + } + } +} + @end diff --git a/MVMCore/MVMCore/PresentationHandling/MVMCorePresentationDelegateProtocol.h b/MVMCore/MVMCore/PresentationHandling/MVMCorePresentationDelegateProtocol.h index 219abd8..b4c29c4 100644 --- a/MVMCore/MVMCore/PresentationHandling/MVMCorePresentationDelegateProtocol.h +++ b/MVMCore/MVMCore/PresentationHandling/MVMCorePresentationDelegateProtocol.h @@ -24,6 +24,9 @@ fromViewController:(nonnull UIViewController *)fromVC toViewController:(nonnull UIViewController *)toVC NS_AVAILABLE_IOS(7_0); +- (nullable id )navigationController:(nonnull UINavigationController *)navigationController + interactionControllerForAnimationController:(nonnull id ) animationController NS_AVAILABLE_IOS(7_0); + // Called when a view controller will be presented on another view controller - (void)viewController:(nonnull UIViewController *)presentingViewController willPresentViewController:(nonnull UIViewController *)presentedViewController;