react-native-navigation的迁移库

RNNReactView.m 2.0KB

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