react-native-navigation的迁移库

RNNNavigationStackManager.m 2.7KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. #import "RNNNavigationStackManager.h"
  2. #import "RNNErrorHandler.h"
  3. typedef void (^RNNAnimationBlock)(void);
  4. @implementation RNNNavigationStackManager
  5. - (void)push:(UIViewController *)newTop onTop:(UIViewController *)onTopViewController animated:(BOOL)animated animationDelegate:(id)animationDelegate completion:(RNNTransitionCompletionBlock)completion rejection:(RCTPromiseRejectBlock)rejection {
  6. UINavigationController *nvc = onTopViewController.navigationController;
  7. if (animationDelegate) {
  8. nvc.delegate = animationDelegate;
  9. } else {
  10. nvc.delegate = nil;
  11. nvc.interactivePopGestureRecognizer.delegate = nil;
  12. }
  13. [self performAnimationBlock:^{
  14. [nvc pushViewController:newTop animated:animated];
  15. } completion:completion];
  16. }
  17. - (void)pop:(UIViewController *)viewController animated:(BOOL)animated completion:(RNNTransitionCompletionBlock)completion rejection:(RNNTransitionRejectionBlock)rejection {
  18. [self performAnimationBlock:^{
  19. [viewController.navigationController popViewControllerAnimated:animated];
  20. } completion:completion];
  21. }
  22. - (void)popTo:(UIViewController *)viewController animated:(BOOL)animated completion:(RNNPopCompletionBlock)completion rejection:(RNNTransitionRejectionBlock)rejection; {
  23. __block NSArray* poppedVCs;
  24. if ([viewController.navigationController.childViewControllers containsObject:viewController]) {
  25. [self performAnimationBlock:^{
  26. poppedVCs = [viewController.navigationController popToViewController:viewController animated:animated];
  27. } completion:^{
  28. if (completion) {
  29. completion(poppedVCs);
  30. }
  31. }];
  32. } else {
  33. [RNNErrorHandler reject:rejection withErrorCode:1011 errorDescription:@"component not found in stack"];
  34. }
  35. }
  36. - (void)popToRoot:(UIViewController*)viewController animated:(BOOL)animated completion:(RNNPopCompletionBlock)completion rejection:(RNNTransitionRejectionBlock)rejection {
  37. __block NSArray* poppedVCs;
  38. [self performAnimationBlock:^{
  39. poppedVCs = [viewController.navigationController popToRootViewControllerAnimated:animated];
  40. } completion:^{
  41. completion(poppedVCs);
  42. }];
  43. }
  44. - (void)setStackRoot:(UIViewController *)newRoot fromViewController:(UIViewController *)fromViewController animated:(BOOL)animated completion:(RNNTransitionCompletionBlock)completion rejection:(RNNTransitionRejectionBlock)rejection {
  45. UINavigationController* nvc = fromViewController.navigationController;
  46. [self performAnimationBlock:^{
  47. [nvc setViewControllers:@[newRoot] animated:animated];
  48. } completion:completion];
  49. }
  50. # pragma mark Private
  51. - (void)performAnimationBlock:(RNNAnimationBlock)animationBlock completion:(RNNTransitionCompletionBlock)completion {
  52. [CATransaction begin];
  53. [CATransaction setCompletionBlock:^{
  54. if (completion) {
  55. completion();
  56. }
  57. }];
  58. animationBlock();
  59. [CATransaction commit];
  60. }
  61. @end