react-native-navigation的迁移库

RNNElementFinder.m 2.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. #import "RNNElementFinder.h"
  2. @implementation RNNElementFinder
  3. -(instancetype)initWithToVC:(UIViewController*)toVC andfromVC:(UIViewController*)fromVC {
  4. self = [super init];
  5. self.toVCTransitionElements = [self findRNNElementViews:toVC.view];
  6. self.fromVCTransitionElements = [self findRNNElementViews:fromVC.view];
  7. return self;
  8. }
  9. -(RNNElementView*)findViewToAnimate:(NSArray*)RNNTransitionElementViews withId:(NSString*)elementId{
  10. for (RNNElementView* view in RNNTransitionElementViews) {
  11. if ([view.elementId isEqualToString:elementId]){
  12. return view;
  13. }
  14. }
  15. return nil;
  16. }
  17. -(NSArray*)findRNNElementViews:(UIView*)view{
  18. NSMutableArray* elementViews = [NSMutableArray new];
  19. for(UIView *aView in view.subviews){
  20. if([aView isMemberOfClass:[RNNElementView class]]){
  21. [elementViews addObject:aView];
  22. } else{
  23. if ([aView subviews]) {
  24. [elementViews addObjectsFromArray:[self findRNNElementViews:aView]];
  25. }
  26. }
  27. }
  28. return elementViews;
  29. }
  30. -(void)findElementsInTransition:(RNNTransitionStateHolder*)transitionStateHolder {
  31. if ([self findViewToAnimate:self.toVCTransitionElements withId:transitionStateHolder.fromId]) {
  32. transitionStateHolder.fromElement = [self findViewToAnimate:self.toVCTransitionElements withId:transitionStateHolder.fromId];
  33. transitionStateHolder.isFromVC = false;
  34. } else if ([self findViewToAnimate:self.fromVCTransitionElements withId:transitionStateHolder.fromId]){
  35. transitionStateHolder.fromElement = [self findViewToAnimate:self.fromVCTransitionElements withId:transitionStateHolder.fromId];
  36. transitionStateHolder.isFromVC = true;
  37. } else {
  38. [[NSException exceptionWithName:NSInvalidArgumentException reason:[NSString stringWithFormat:@"elementId %@ does not exist", transitionStateHolder.fromId] userInfo:nil] raise];
  39. }
  40. if (transitionStateHolder.toId) {
  41. if ([self findViewToAnimate:self.toVCTransitionElements withId:transitionStateHolder.toId]) {
  42. transitionStateHolder.toElement = [self findViewToAnimate:self.toVCTransitionElements withId:transitionStateHolder.toId];
  43. } else if ([self findViewToAnimate:self.fromVCTransitionElements withId:transitionStateHolder.toId]){
  44. transitionStateHolder.toElement = [self findViewToAnimate:self.fromVCTransitionElements withId:transitionStateHolder.toId];
  45. } else {
  46. [[NSException exceptionWithName:NSInvalidArgumentException reason:[NSString stringWithFormat:@"elementId %@ does not exist", transitionStateHolder.toId] userInfo:nil] raise];
  47. }
  48. }
  49. }
  50. @end