react-native-navigation的迁移库

RNNElementFinder.m 1.9KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  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. - (instancetype)initWithFromVC:(UIViewController *)fromVC {
  14. self = [super init];
  15. self.fromVCTransitionElements = [self findRNNElementViews:fromVC.view];
  16. return self;
  17. }
  18. - (RNNElementView *)findViewToAnimate:(NSArray *)RNNTransitionElementViews withId:(NSString *)elementId{
  19. for (RNNElementView* view in RNNTransitionElementViews) {
  20. if ([view.elementId isEqualToString:elementId]){
  21. return view;
  22. }
  23. }
  24. return nil;
  25. }
  26. - (NSArray *)findRNNElementViews:(UIView*)view {
  27. NSMutableArray* elementViews = [NSMutableArray new];
  28. for (UIView *aView in view.subviews) {
  29. if([aView isMemberOfClass:[RNNElementView class]]) {
  30. [elementViews addObject:aView];
  31. } else{
  32. if ([aView subviews]) {
  33. [elementViews addObjectsFromArray:[self findRNNElementViews:aView]];
  34. }
  35. }
  36. }
  37. return elementViews;
  38. }
  39. - (RNNElementView *)findElementForId:(NSString *)elementId {
  40. if (elementId) {
  41. if ([self findViewToAnimate:self.toVCTransitionElements withId:elementId]) {
  42. return [self findViewToAnimate:self.toVCTransitionElements withId:elementId];
  43. } else if ([self findViewToAnimate:self.fromVCTransitionElements withId:elementId]){
  44. return [self findViewToAnimate:self.fromVCTransitionElements withId:elementId];
  45. } else {
  46. [[NSException exceptionWithName:NSInvalidArgumentException reason:[NSString stringWithFormat:@"elementId %@ does not exist", elementId] userInfo:nil] raise];
  47. }
  48. }
  49. return nil;
  50. }
  51. @end