react-native-navigation的迁移库

RCTHelpers.m 2.2KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. //
  2. // RCTHelpers.m
  3. // ReactNativeControllers
  4. //
  5. // Created by Artal Druk on 25/05/2016.
  6. // Copyright © 2016 artal. All rights reserved.
  7. //
  8. #import "RCTHelpers.h"
  9. #import "RCTView.h"
  10. #import "RCTScrollView.h"
  11. @implementation RCTHelpers
  12. +(NSArray*)getAllSubviewsForView:(UIView*)view
  13. {
  14. NSMutableArray *allSubviews = [NSMutableArray new];
  15. for (UIView *subview in view.subviews)
  16. {
  17. [allSubviews addObject:subview];
  18. [allSubviews addObjectsFromArray:[self getAllSubviewsForView:subview]];
  19. }
  20. return allSubviews;
  21. }
  22. /*
  23. The YellowBox is added to each RCTRootView. Regardless if there are warnings or not, if there's a warning anywhere in the app - it is added
  24. Since it is always appears on the top, it blocks interactions with other components.
  25. It is most noticeable in RCCLightBox and RCCNotification where button (for example) are not clickable if placed at the bottom part of the view
  26. */
  27. +(BOOL)removeYellowBox:(RCTRootView*)reactRootView
  28. {
  29. #ifndef DEBUG
  30. return YES;
  31. #endif
  32. BOOL removed = NO;
  33. NSArray* subviews = [self getAllSubviewsForView:reactRootView];
  34. for (UIView *view in subviews)
  35. {
  36. if ([view isKindOfClass:[RCTView class]])
  37. {
  38. CGFloat r, g, b, a;
  39. [view.backgroundColor getRed:&r green:&g blue:&b alpha:&a];
  40. //identify the yellow view by its hard-coded color and height
  41. if((lrint(r * 255) == 250) && (lrint(g * 255) == 186) && (lrint(b * 255) == 48) && (lrint(a * 100) == 95) && (view.frame.size.height == 46))
  42. {
  43. UIView *yelloboxParentView = view;
  44. while (view.superview != nil)
  45. {
  46. yelloboxParentView = yelloboxParentView.superview;
  47. if ([yelloboxParentView isKindOfClass:[RCTScrollView class]])
  48. {
  49. yelloboxParentView = yelloboxParentView.superview;
  50. break;
  51. }
  52. }
  53. [yelloboxParentView removeFromSuperview];
  54. removed = YES;
  55. break;
  56. }
  57. }
  58. if (removed)
  59. {
  60. break;
  61. }
  62. }
  63. return removed;
  64. }
  65. @end