react-native-navigation的迁移库

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. #import "RNNReactView.h"
  2. #import "RCTHelpers.h"
  3. #import <React/RCTUIManager.h>
  4. @implementation RNNReactView {
  5. BOOL _fillParent;
  6. }
  7. - (instancetype)initWithBridge:(RCTBridge *)bridge moduleName:(NSString *)moduleName initialProperties:(NSDictionary *)initialProperties reactViewReadyBlock:(RNNReactViewReadyCompletionBlock)reactViewReadyBlock {
  8. self = [super initWithBridge:bridge moduleName:moduleName initialProperties:initialProperties];
  9. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(contentDidAppear:) name:RCTContentDidAppearNotification object:nil];
  10. _reactViewReadyBlock = reactViewReadyBlock;
  11. return self;
  12. }
  13. - (void)contentDidAppear:(NSNotification *)notification {
  14. #ifdef DEBUG
  15. if ([((RNNReactView *)notification.object).moduleName isEqualToString:self.moduleName]) {
  16. [RCTHelpers removeYellowBox:self];
  17. }
  18. #endif
  19. RNNReactView* appearedView = notification.object;
  20. if (_reactViewReadyBlock && [appearedView.appProperties[@"componentId"] isEqual:self.componentId]) {
  21. _reactViewReadyBlock();
  22. _reactViewReadyBlock = nil;
  23. [[NSNotificationCenter defaultCenter] removeObserver:self];
  24. }
  25. }
  26. - (NSString *)componentId {
  27. return self.appProperties[@"componentId"];
  28. }
  29. - (void)setRootViewDidChangeIntrinsicSize:(void (^)(CGSize))rootViewDidChangeIntrinsicSize {
  30. _rootViewDidChangeIntrinsicSize = rootViewDidChangeIntrinsicSize;
  31. self.delegate = self;
  32. }
  33. - (void)rootViewDidChangeIntrinsicSize:(RCTRootView *)rootView {
  34. if (_rootViewDidChangeIntrinsicSize) {
  35. _rootViewDidChangeIntrinsicSize(rootView.intrinsicContentSize);
  36. }
  37. }
  38. - (CGSize)intrinsicContentSize {
  39. if (_fillParent) {
  40. return UILayoutFittingExpandedSize;
  41. } else {
  42. return [super intrinsicContentSize];
  43. }
  44. }
  45. - (void)setAlignment:(NSString *)alignment inFrame:(CGRect)frame {
  46. if ([alignment isEqualToString:@"fill"]) {
  47. _fillParent = YES;
  48. self.translatesAutoresizingMaskIntoConstraints = NO;
  49. self.sizeFlexibility = RCTRootViewSizeFlexibilityNone;
  50. } else {
  51. self.sizeFlexibility = RCTRootViewSizeFlexibilityWidthAndHeight;
  52. __weak RNNReactView *weakSelf = self;
  53. [self setRootViewDidChangeIntrinsicSize:^(CGSize intrinsicSize) {
  54. [weakSelf setFrame:CGRectMake(0, 0, intrinsicSize.width, intrinsicSize.height)];
  55. }];
  56. }
  57. }
  58. @end