react-native-navigation的迁移库

RNNReactTitleView.m 1.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. #import "RNNReactTitleView.h"
  2. @implementation RNNReactTitleView {
  3. BOOL _fillParent;
  4. }
  5. - (NSString *)componentType {
  6. return ComponentTypeTitle;
  7. }
  8. - (CGSize)intrinsicContentSize {
  9. if (_fillParent) {
  10. return UILayoutFittingExpandedSize;
  11. } else {
  12. return [super intrinsicContentSize];
  13. }
  14. }
  15. - (void)setAlignment:(NSString *)alignment inFrame:(CGRect)frame {
  16. if ([alignment isEqualToString:@"fill"]) {
  17. _fillParent = YES;
  18. self.translatesAutoresizingMaskIntoConstraints = NO;
  19. self.sizeFlexibility = RCTRootViewSizeFlexibilityNone;
  20. } else {
  21. self.sizeFlexibility = RCTRootViewSizeFlexibilityWidthAndHeight;
  22. __weak RNNReactView *weakSelf = self;
  23. [self setRootViewDidChangeIntrinsicSize:^(CGSize intrinsicSize) {
  24. [weakSelf setFrame:CGRectMake(0, 0, intrinsicSize.width, intrinsicSize.height)];
  25. }];
  26. }
  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. @end