react-native-navigation的迁移库

RNNNavigationStackManager.m 2.5KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  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. [self performAnimationBlock:^{
  25. poppedVCs = [viewController.navigationController popToViewController:viewController animated:animated];
  26. } completion:^{
  27. if (completion) {
  28. completion(poppedVCs);
  29. }
  30. }];
  31. }
  32. - (void)popToRoot:(UIViewController*)viewController animated:(BOOL)animated completion:(RNNPopCompletionBlock)completion rejection:(RNNTransitionRejectionBlock)rejection {
  33. __block NSArray* poppedVCs;
  34. [self performAnimationBlock:^{
  35. poppedVCs = [viewController.navigationController popToRootViewControllerAnimated:animated];
  36. } completion:^{
  37. completion(poppedVCs);
  38. }];
  39. }
  40. - (void)setStackRoot:(UIViewController *)newRoot fromViewController:(UIViewController *)fromViewController animated:(BOOL)animated completion:(RNNTransitionCompletionBlock)completion rejection:(RNNTransitionRejectionBlock)rejection {
  41. UINavigationController* nvc = fromViewController.navigationController;
  42. [self performAnimationBlock:^{
  43. [nvc setViewControllers:@[newRoot] animated:animated];
  44. } completion:completion];
  45. }
  46. # pragma mark Private
  47. - (void)performAnimationBlock:(RNNAnimationBlock)animationBlock completion:(RNNTransitionCompletionBlock)completion {
  48. [CATransaction begin];
  49. [CATransaction setCompletionBlock:^{
  50. if (completion) {
  51. completion();
  52. }
  53. }];
  54. animationBlock();
  55. [CATransaction commit];
  56. }
  57. @end