react-native-navigation的迁移库

RNNReactView.m 2.3KB

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