react-native-navigation的迁移库

ElementTransitionsCreator.m 2.4KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. #import "ElementTransitionsCreator.h"
  2. #import "RNNElementFinder.h"
  3. @implementation ElementTransitionsCreator
  4. + (NSArray<DisplayLinkAnimatorDelegate> *)create:(NSArray<ElementTransitionOptions *> *)elementTransitions fromVC:(UIViewController *)fromVC toVC:(UIViewController *)toVC containerView:(UIView *)containerView {
  5. NSMutableArray<DisplayLinkAnimatorDelegate>* transitions = [NSMutableArray<DisplayLinkAnimatorDelegate> new];
  6. for (ElementTransitionOptions* transitionOptions in elementTransitions) {
  7. UIView* element = [self findElementById:transitionOptions.elementId fromVC:fromVC toVC:toVC];
  8. ElementAnimator* elementAnimator = [[ElementAnimator alloc] initWithTransitionOptions:transitionOptions
  9. view:element
  10. fromVC:fromVC
  11. toVC:toVC
  12. containerView:containerView];
  13. [transitions addObject:elementAnimator];
  14. }
  15. return transitions;
  16. }
  17. + (id<DisplayLinkAnimatorDelegate>)createTransition:(ElementTransitionOptions *)transitionOptions view:(UIView *)view fromVC:(UIViewController *)fromVC toVC:(UIViewController *)toVC containerView:(UIView *)containerView {
  18. ElementAnimator* elementAnimator = [[ElementAnimator alloc] initWithTransitionOptions:transitionOptions
  19. view:view
  20. fromVC:fromVC
  21. toVC:toVC
  22. containerView:containerView];
  23. return elementAnimator;
  24. }
  25. + (UIView *)findElementById:(NSString *)elementId fromVC:(UIViewController *)fromVC toVC:(UIViewController *)toVC {
  26. UIView* viewInSourceView = [RNNElementFinder findElementForId:elementId inView:fromVC.view];
  27. if (viewInSourceView) {
  28. return viewInSourceView;
  29. }
  30. UIView* viewInDestinationView = [RNNElementFinder findElementForId:elementId inView:toVC.view];
  31. if (viewInDestinationView) {
  32. return viewInDestinationView;
  33. }
  34. return nil;
  35. }
  36. @end