react-native-navigation的迁移库

SharedElementAnimator.m 3.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. #import "SharedElementAnimator.h"
  2. #import "AnimatedViewFactory.h"
  3. #import "RectTransition.h"
  4. #import "TransformRectTransition.h"
  5. #import "RotationTransition.h"
  6. #import "ColorTransition.h"
  7. #import "AnimatedTextView.h"
  8. #import "TextStorageTransition.h"
  9. #import "AnchorTransition.h"
  10. @implementation SharedElementAnimator {
  11. SharedElementTransitionOptions* _transitionOptions;
  12. UIViewController* _toVC;
  13. UIViewController* _fromVC;
  14. UIView* _fromView;
  15. UIView* _toView;
  16. UIView* _containerView;
  17. }
  18. - (instancetype)initWithTransitionOptions:(SharedElementTransitionOptions *)transitionOptions fromView:(UIView *)fromView toView:(UIView *)toView fromVC:(UIViewController *)fromVC toVC:(UIViewController *)toVC containerView:(UIView *)containerView {
  19. self = [super init];
  20. _transitionOptions = transitionOptions;
  21. _fromVC = fromVC;
  22. _toVC = toVC;
  23. _fromView = fromView;
  24. _toView = toView;
  25. _containerView = containerView;
  26. self.view = [self createAnimatedView:transitionOptions fromView:fromView toView:toView];
  27. self.animations = [self createAnimations];
  28. return self;
  29. }
  30. - (AnimatedReactView *)createAnimatedView:(SharedElementTransitionOptions *)transitionOptions fromView:(UIView *)fromView toView:(UIView *)toView {
  31. return [AnimatedViewFactory createFromElement:fromView toElement:toView transitionOptions:transitionOptions];
  32. }
  33. - (NSMutableArray<id<DisplayLinkAnimation>> *)createAnimations {
  34. NSMutableArray* animations = [super createAnimations:_transitionOptions];
  35. CGFloat startDelay = [_transitionOptions.startDelay getWithDefaultValue:0];
  36. CGFloat duration = [_transitionOptions.duration getWithDefaultValue:300];
  37. Text* interpolation = [_transitionOptions.interpolation getWithDefaultValue:@"accelerateDecelerate"];
  38. if (!CGRectEqualToRect(self.view.location.fromFrame, self.view.location.toFrame)) {
  39. if ([self.view isKindOfClass:AnimatedTextView.class]) {
  40. [animations addObject:[[RectTransition alloc] initWithView:self.view from:self.view.location.fromFrame to:self.view.location.toFrame startDelay:startDelay duration:duration interpolation:interpolation]];
  41. } else {
  42. [animations addObject:[[TransformRectTransition alloc] initWithView:self.view fromRect:self.view.location.fromFrame toRect:self.view.location.toFrame fromAngle:self.view.location.fromAngle toAngle:self.view.location.toAngle startDelay:startDelay duration:duration interpolation:interpolation]];
  43. }
  44. }
  45. if (![_fromView.backgroundColor isEqual:_toView.backgroundColor]) {
  46. [animations addObject:[[ColorTransition alloc] initWithView:self.view from:_fromView.backgroundColor to:_toView.backgroundColor startDelay:startDelay duration:duration interpolation:interpolation]];
  47. }
  48. if ([self.view isKindOfClass:AnimatedTextView.class]) {
  49. [animations addObject:[[TextStorageTransition alloc] initWithView:self.view from:((AnimatedTextView *)self.view).fromTextStorage to:((AnimatedTextView *)self.view).toTextStorage startDelay:startDelay duration:duration interpolation:interpolation]];
  50. }
  51. return animations;
  52. }
  53. - (void)end {
  54. [super end];
  55. [self.view reset];
  56. }
  57. @end