react-native-navigation的迁移库

RCCCustomTitleView.m 2.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. //
  2. // RCCTitleView.m
  3. // ReactNativeNavigation
  4. //
  5. // Created by Ran Greenberg on 26/04/2017.
  6. // Copyright © 2017 artal. All rights reserved.
  7. //
  8. #import "RCCCustomTitleView.h"
  9. @interface RCCCustomTitleView ()
  10. @property (nonatomic, strong) RCTRootView *subView;
  11. @property (nonatomic, strong) NSString *alignment;
  12. @end
  13. @implementation RCCCustomTitleView
  14. - (instancetype)initWithFrame:(CGRect)frame subView:(RCTRootView*)subView alignment:(NSString*)alignment {
  15. self = [super init];
  16. if (self) {
  17. self.subView = subView;
  18. self.alignment = alignment;
  19. self.backgroundColor = [UIColor clearColor];
  20. self.subView.backgroundColor = [UIColor clearColor];
  21. if ([alignment isEqualToString:@"fill"]) {
  22. self.frame = frame;
  23. subView.sizeFlexibility = RCTRootViewSizeFlexibilityNone;
  24. } else {
  25. self.subView.delegate = self;
  26. subView.sizeFlexibility = RCTRootViewSizeFlexibilityWidthAndHeight;
  27. }
  28. [self addSubview:subView];
  29. }
  30. return self;
  31. }
  32. - (void)layoutSubviews {
  33. [super layoutSubviews];
  34. if ([self.alignment isEqualToString:@"fill"]) {
  35. [self.subView setFrame:self.bounds];
  36. }
  37. }
  38. - (NSString *)alignment {
  39. return _alignment ? _alignment : @"center";
  40. }
  41. - (void)rootViewDidChangeIntrinsicSize:(RCTRootView *)rootView {
  42. if ([self.alignment isEqualToString:@"center"]) {
  43. [self setFrame:CGRectMake(0, 0, rootView.intrinsicContentSize.width, rootView.intrinsicContentSize.height)];
  44. [self.subView setFrame:CGRectMake(0, 0, rootView.intrinsicContentSize.width, rootView.intrinsicContentSize.height)];
  45. }
  46. }
  47. - (void) viewWillTransitionToSize:(CGSize)size withTransitionCoordinator:(id<UIViewControllerTransitionCoordinator>)coordinator {
  48. // whenever the orientation changes this runs
  49. // and sets the nav bar item width to the new size width
  50. CGRect newFrame = self.frame;
  51. if (newFrame.size.width < size.width) {
  52. newFrame.size.width = size.width;
  53. newFrame.origin.x = 0;
  54. }
  55. [super setFrame:newFrame];
  56. }
  57. @end