react-native-navigation的迁移库

RNNTransition.m 3.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. #import "RNNTransition.h"
  2. #import "RNNElementFinder.h"
  3. #import "RNNTransitionStateHolder.h"
  4. #import "RNNViewLocation.h"
  5. #import "RNNInteractivePopAnimator.h"
  6. @interface RNNTransition () {
  7. UIViewController* _toVC;
  8. UIViewController* _fromVC;
  9. BOOL _isBackButton;
  10. }
  11. @property (nonatomic, strong) RNNElementView* fromElement;
  12. @property (nonatomic, strong) RNNElementView* toElement;
  13. @property (nonatomic, strong) RNNViewLocation* locations;
  14. @end
  15. @implementation RNNTransition
  16. - (instancetype)initFromVC:(UIViewController *)fromVC toVC:(UIViewController *)toVC transitionOptions:(RNNTransitionStateHolder *)transitionOptions isBackButton:(BOOL)isBackButton {
  17. self = [super init];
  18. _toVC = toVC;
  19. _fromVC = fromVC;
  20. _isBackButton = isBackButton;
  21. self.options = transitionOptions;
  22. RNNElementFinder* elementFinder = [[RNNElementFinder alloc] initWithToVC:toVC andfromVC:fromVC];
  23. self.fromElement = [elementFinder findElementForId:self.options.fromId];
  24. self.toElement = [elementFinder findElementForId:transitionOptions.toId];
  25. self.locations = [[RNNViewLocation alloc] initWithFromElement:self.fromElement toElement:self.toElement startPoint:CGPointMake(self.options.startX, self.options.startY) endPoint:CGPointMake(self.options.endX, self.options.endY) andVC:fromVC];
  26. self.animatedView = [[RNNAnimatedView alloc] initFromElement:self.fromElement toElement:self.toElement andLocation:self.locations andIsBackButton:isBackButton startAlpha:self.options.startAlpha endAlpha:self.options.endAlpha];
  27. if (transitionOptions.isSharedElementTransition) {
  28. [self.toElement setHidden: YES];
  29. }
  30. [self.fromElement setHidden:YES];
  31. return self;
  32. }
  33. - (void)setAnimatedViewFinalProperties {
  34. CGFloat alpha = _isBackButton ? self.options.startAlpha : self.options.endAlpha;
  35. self.animatedView.alpha = alpha;
  36. CGPoint center = _isBackButton ? self.locations.fromCenter : self.locations.toCenter;
  37. self.animatedView.center = center;
  38. CGAffineTransform transform = _isBackButton ? self.locations.transformBack : self.locations.transform;
  39. self.animatedView.transform = transform;
  40. RNNElementView* fromElement = _isBackButton ? self.toElement : self.fromElement;
  41. RNNElementView* toElement = _isBackButton ? self.fromElement : self.toElement;
  42. if (self.options.isSharedElementTransition) {
  43. if ([[fromElement subviews][0] isKindOfClass:[UIImageView class]]) {
  44. self.animatedView.contentMode = UIViewContentModeScaleAspectFill;
  45. if ([toElement resizeMode]){
  46. self.animatedView.contentMode = [RNNAnimatedView contentModefromString:[toElement resizeMode]];
  47. }
  48. }
  49. }
  50. }
  51. - (void)transitionCompleted {
  52. [self.fromElement setHidden:NO];
  53. if (self.options.isSharedElementTransition) {
  54. [self.toElement setHidden:NO];
  55. }
  56. [self.animatedView removeFromSuperview];
  57. if (self.options.interactivePop) {
  58. RNNInteractivePopAnimator* interactivePopAnimator = [[RNNInteractivePopAnimator alloc] initWithTopView:self.toElement andBottomView:self.fromElement andOriginFrame:self.locations.fromFrame andViewController:_toVC];
  59. UIPanGestureRecognizer* gesture = [[UIPanGestureRecognizer alloc] initWithTarget:interactivePopAnimator
  60. action:@selector(handleGesture:)];
  61. [self.toElement addGestureRecognizer:gesture];
  62. }
  63. }
  64. @end