react-native-navigation的迁移库

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  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.componentId]) {
  20. _reactViewReadyBlock();
  21. _reactViewReadyBlock = nil;
  22. [[NSNotificationCenter defaultCenter] removeObserver:self];
  23. }
  24. }
  25. - (NSString *)componentId {
  26. return self.appProperties[@"componentId"];
  27. }
  28. - (void)setRootViewDidChangeIntrinsicSize:(void (^)(CGSize))rootViewDidChangeIntrinsicSize {
  29. _rootViewDidChangeIntrinsicSize = rootViewDidChangeIntrinsicSize;
  30. self.delegate = self;
  31. }
  32. - (void)rootViewDidChangeIntrinsicSize:(RCTRootView *)rootView {
  33. if (_rootViewDidChangeIntrinsicSize) {
  34. _rootViewDidChangeIntrinsicSize(rootView.intrinsicContentSize);
  35. }
  36. }
  37. - (void)setAlignment:(NSString *)alignment inFrame:(CGRect)frame {
  38. if ([alignment isEqualToString:@"fill"]) {
  39. self.sizeFlexibility = RCTRootViewSizeFlexibilityNone;
  40. [self setFrame:frame];
  41. } else {
  42. self.sizeFlexibility = RCTRootViewSizeFlexibilityWidthAndHeight;
  43. __weak RNNReactView *weakSelf = self;
  44. [self setRootViewDidChangeIntrinsicSize:^(CGSize intrinsicSize) {
  45. [weakSelf setFrame:CGRectMake(0, 0, intrinsicSize.width, intrinsicSize.height)];
  46. }];
  47. }
  48. }
  49. @end