react-native-navigation的迁移库

RNNCustomTitleView.m 1.4KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. #import "RNNCustomTitleView.h"
  2. @interface RNNCustomTitleView ()
  3. @property (nonatomic, strong) RCTRootView *subView;
  4. @property (nonatomic, strong) NSString *alignment;
  5. @end
  6. @implementation RNNCustomTitleView
  7. - (instancetype)initWithFrame:(CGRect)frame subView:(RCTRootView*)subView alignment:(NSString*)alignment {
  8. self = [super init];
  9. if (self) {
  10. self.subView = subView;
  11. self.alignment = alignment;
  12. self.backgroundColor = [UIColor clearColor];
  13. self.subView.backgroundColor = [UIColor clearColor];
  14. if ([alignment isEqualToString:@"fill"]) {
  15. self.frame = frame;
  16. subView.sizeFlexibility = RCTRootViewSizeFlexibilityNone;
  17. } else {
  18. self.subView.delegate = self;
  19. subView.sizeFlexibility = RCTRootViewSizeFlexibilityWidthAndHeight;
  20. }
  21. [self addSubview:subView];
  22. }
  23. return self;
  24. }
  25. - (void)layoutSubviews {
  26. [super layoutSubviews];
  27. if ([self.alignment isEqualToString:@"fill"]) {
  28. [self.subView setFrame:self.bounds];
  29. }
  30. }
  31. - (NSString *)alignment {
  32. return _alignment ? _alignment : @"center";
  33. }
  34. - (void)rootViewDidChangeIntrinsicSize:(RCTRootView *)rootView {
  35. if ([self.alignment isEqualToString:@"center"]) {
  36. [self setFrame:CGRectMake(self.frame.origin.x, self.frame.origin.y, self.subView.intrinsicContentSize.width, self.subView.intrinsicContentSize.height)];
  37. [self.subView setFrame:CGRectMake(0, 0, rootView.intrinsicContentSize.width, rootView.intrinsicContentSize.height)];
  38. }
  39. }
  40. @end