react-native-navigation的迁移库

RNNModalAnimation.m 1.7KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. #import "RNNModalAnimation.h"
  2. @implementation RNNModalAnimation
  3. - (instancetype)initWithScreenTransition:(RNNScreenTransition *)screenTransition isDismiss:(BOOL)isDismiss {
  4. self = [super init];
  5. self.screenTransition = screenTransition;
  6. self.isDismiss = isDismiss;
  7. return self;
  8. }
  9. - (NSTimeInterval)transitionDuration:(id <UIViewControllerContextTransitioning>)transitionContext {
  10. return self.screenTransition.content.duration;
  11. }
  12. - (void)animateTransition:(id<UIViewControllerContextTransitioning>)transitionContext {
  13. UIViewController* toViewController = [transitionContext viewControllerForKey:self.isDismiss ? UITransitionContextFromViewControllerKey : UITransitionContextToViewControllerKey];
  14. UIViewController* fromViewController = [transitionContext viewControllerForKey:self.isDismiss ? UITransitionContextToViewControllerKey : UITransitionContextFromViewControllerKey];
  15. if (self.isDismiss) {
  16. [[transitionContext containerView] addSubview:fromViewController.view];
  17. [[transitionContext containerView] addSubview:toViewController.view];
  18. } else {
  19. [[transitionContext containerView] addSubview:toViewController.view];
  20. }
  21. [_screenTransition.content setupInitialTransitionForView:toViewController.view];
  22. [_screenTransition.topBar setupInitialTransitionForView:toViewController.navigationController.navigationBar];
  23. [UIView animateWithDuration:[self transitionDuration:transitionContext] animations:^{
  24. [_screenTransition.content completeTransitionForView:toViewController.view];
  25. [_screenTransition.topBar completeTransitionForView:toViewController.navigationController.navigationBar];
  26. } completion:^(BOOL finished) {
  27. [transitionContext completeTransition:![transitionContext transitionWasCancelled]];
  28. }];
  29. }
  30. @end