react-native-navigation的迁移库

RNNReactRootView.m 1.5KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  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. _bridge = bridge;
  10. #ifdef DEBUG
  11. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(contentDidAppear:) name:RCTContentDidAppearNotification object:nil];
  12. #endif
  13. return self;
  14. }
  15. - (void)contentDidAppear:(NSNotification *)notification {
  16. if ([((RNNReactRootView *)notification.object).moduleName isEqualToString:self.moduleName]) {
  17. [RCTHelpers removeYellowBox:self];
  18. [[NSNotificationCenter defaultCenter] removeObserver:self];
  19. }
  20. }
  21. - (void)setRootViewDidChangeIntrinsicSize:(void (^)(CGSize))rootViewDidChangeIntrinsicSize {
  22. _rootViewDidChangeIntrinsicSize = rootViewDidChangeIntrinsicSize;
  23. self.delegate = self;
  24. }
  25. - (void)rootViewDidChangeIntrinsicSize:(RCTRootView *)rootView {
  26. if (_rootViewDidChangeIntrinsicSize) {
  27. _rootViewDidChangeIntrinsicSize(rootView.intrinsicContentSize);
  28. }
  29. }
  30. - (void)setAlignment:(NSString *)alignment {
  31. if ([alignment isEqualToString:@"fill"]) {
  32. self.sizeFlexibility = RCTRootViewSizeFlexibilityNone;
  33. } else {
  34. self.sizeFlexibility = RCTRootViewSizeFlexibilityWidthAndHeight;
  35. }
  36. }
  37. - (void)layoutSubviews {
  38. [super layoutSubviews];
  39. [_bridge.uiManager setSize:self.bounds.size forView:self];
  40. }
  41. @end