react-native-navigation的迁移库

SharedElementTransitionsCreator.m 2.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. #import "SharedElementTransitionsCreator.h"
  2. #import "RNNElementFinder.h"
  3. #import "AnimatedViewFactory.h"
  4. #import "BaseAnimator.h"
  5. #import "NSArray+utils.h"
  6. #import "SharedElementAnimator.h"
  7. @implementation SharedElementTransitionsCreator
  8. + (NSArray<DisplayLinkAnimatorDelegate>*)create:(NSArray<SharedElementTransitionOptions *>*)sharedElementTransitions
  9. fromVC:(UIViewController *)fromVC
  10. toVC:(UIViewController *)toVC
  11. containerView:(UIView *)containerView {
  12. NSMutableArray<DisplayLinkAnimatorDelegate>* transitions = [NSMutableArray<DisplayLinkAnimatorDelegate> new];
  13. for (SharedElementTransitionOptions* transitionOptions in sharedElementTransitions) {
  14. UIView *fromView = [RNNElementFinder findElementForId:transitionOptions.fromId inView:fromVC.view];
  15. UIView *toView = [RNNElementFinder findElementForId:transitionOptions.toId inView:toVC.view];
  16. SharedElementAnimator* sharedElementAnimator = [[SharedElementAnimator alloc] initWithTransitionOptions:transitionOptions
  17. fromView:fromView
  18. toView:toView
  19. fromVC:fromVC
  20. toVC:toVC
  21. containerView:containerView];
  22. [transitions addObject:sharedElementAnimator];
  23. }
  24. NSArray<DisplayLinkAnimatorDelegate>* sortedTransitions = [self sortByZIndex:transitions];
  25. [self addSharedElementViews:sortedTransitions toContainerView:containerView];
  26. return sortedTransitions;
  27. }
  28. + (void)addSharedElementViews:(NSArray<BaseAnimator *> *)animators toContainerView:(UIView *)containerView {
  29. for (BaseAnimator* animator in animators) {
  30. [containerView addSubview:animator.view];
  31. }
  32. }
  33. + (NSArray<DisplayLinkAnimatorDelegate>*)sortByZIndex:(NSArray<DisplayLinkAnimatorDelegate> *)animators {
  34. return (NSArray<DisplayLinkAnimatorDelegate>*)[animators sortedArrayUsingComparator:^NSComparisonResult(BaseAnimator * a, BaseAnimator* b) {
  35. id first = [a.view valueForKey:@"reactZIndex"];
  36. id second = [b.view valueForKey:@"reactZIndex"];
  37. return [first compare:second];
  38. }];
  39. }
  40. @end