react-native-navigation的迁移库

StackControllerDelegate.m 1.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. #import "StackControllerDelegate.h"
  2. #import "StackTransitionDelegate.h"
  3. #import "UIViewController+LayoutProtocol.h"
  4. @implementation StackControllerDelegate {
  5. RNNEventEmitter* _eventEmitter;
  6. UIViewController* _presentedViewController;
  7. }
  8. - (instancetype)initWithEventEmitter:(RNNEventEmitter *)eventEmitter {
  9. self = [super init];
  10. _eventEmitter = eventEmitter;
  11. return self;
  12. }
  13. - (void)navigationController:(UINavigationController *)navigationController didShowViewController:(UIViewController *)viewController animated:(BOOL)animated {
  14. if ([navigationController.viewControllers indexOfObject:_presentedViewController] < 0) {
  15. [self sendScreenPoppedEvent:_presentedViewController];
  16. }
  17. _presentedViewController = viewController;
  18. }
  19. - (void)sendScreenPoppedEvent:(UIViewController *)poppedScreen {
  20. [_eventEmitter sendScreenPoppedEvent:poppedScreen.layoutInfo.componentId];
  21. }
  22. - (id<UIViewControllerAnimatedTransitioning>)navigationController:(UINavigationController *)navigationController
  23. animationControllerForOperation:(UINavigationControllerOperation)operation
  24. fromViewController:(UIViewController*)fromVC
  25. toViewController:(UIViewController*)toVC {
  26. if (operation == UINavigationControllerOperationPush && toVC.resolveOptions.animations.push.hasCustomAnimation) {
  27. return [[StackTransitionDelegate alloc] initWithScreenTransition:toVC.resolveOptions.animations.push bridge:_eventEmitter.bridge];
  28. } else if (operation == UINavigationControllerOperationPop && fromVC.resolveOptions.animations.pop.hasCustomAnimation) {
  29. return [[StackTransitionDelegate alloc] initWithScreenTransition:fromVC.resolveOptions.animations.pop bridge:_eventEmitter.bridge];
  30. } else {
  31. return nil;
  32. }
  33. return nil;
  34. }
  35. @end