react-native-navigation的迁移库

RNNReactRootView.m 1.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. #import "RNNReactRootView.h"
  2. #import "RCTHelpers.h"
  3. #import <React/RCTUIManager.h>
  4. @implementation RNNReactRootView {
  5. RCTBridge* _bridge;
  6. };
  7. - (instancetype)initWithBridge:(RCTBridge *)bridge moduleName:(NSString *)moduleName initialProperties:(NSDictionary *)initialProperties {
  8. self = [super initWithBridge:bridge moduleName:moduleName initialProperties:initialProperties];
  9. #ifdef DEBUG
  10. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(contentDidAppear:) name:RCTContentDidAppearNotification object:nil];
  11. #endif
  12. return self;
  13. }
  14. - (void)contentDidAppear:(NSNotification *)notification {
  15. if ([((RNNReactRootView *)notification.object).moduleName isEqualToString:self.moduleName]) {
  16. [RCTHelpers removeYellowBox:self];
  17. [[NSNotificationCenter defaultCenter] removeObserver:self];
  18. }
  19. }
  20. - (void)setRootViewDidChangeIntrinsicSize:(void (^)(CGSize))rootViewDidChangeIntrinsicSize {
  21. _rootViewDidChangeIntrinsicSize = rootViewDidChangeIntrinsicSize;
  22. self.delegate = self;
  23. }
  24. - (void)rootViewDidChangeIntrinsicSize:(RCTRootView *)rootView {
  25. if (_rootViewDidChangeIntrinsicSize) {
  26. _rootViewDidChangeIntrinsicSize(rootView.intrinsicContentSize);
  27. }
  28. }
  29. - (void)setAlignment:(NSString *)alignment {
  30. if ([alignment isEqualToString:@"fill"]) {
  31. self.sizeFlexibility = RCTRootViewSizeFlexibilityNone;
  32. } else {
  33. self.sizeFlexibility = RCTRootViewSizeFlexibilityWidthAndHeight;
  34. }
  35. }
  36. - (void)layoutSubviews {
  37. [super layoutSubviews];
  38. [_bridge.uiManager setSize:self.bounds.size forView:self];
  39. }
  40. @end