react-native-navigation的迁移库

RNNElementFinder.m 1.7KB

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