react-native-navigation的迁移库

SharedElementAnimator.m 3.0KB

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