react-native-navigation的迁移库

RNNReactView.m 1.8KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  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 {
  35. if ([alignment isEqualToString:@"fill"]) {
  36. self.sizeFlexibility = RCTRootViewSizeFlexibilityNone;
  37. } else {
  38. self.sizeFlexibility = RCTRootViewSizeFlexibilityWidthAndHeight;
  39. }
  40. }
  41. @end