Browse Source

fixed custom top bar alignment

yogevbd 6 years ago
parent
commit
029440567e
2 changed files with 15 additions and 4 deletions
  1. 13
    1
      ios/RCCCustomTitleView.m
  2. 2
    3
      ios/RCCViewController.m

+ 13
- 1
ios/RCCCustomTitleView.m View File

29
         
29
         
30
         if ([alignment isEqualToString:@"fill"]) {
30
         if ([alignment isEqualToString:@"fill"]) {
31
             self.frame = frame;
31
             self.frame = frame;
32
-            self.subView.frame = self.frame;
32
+            subView.sizeFlexibility = RCTRootViewSizeFlexibilityNone;
33
         } else {
33
         } else {
34
             self.subView.delegate = self;
34
             self.subView.delegate = self;
35
+            subView.sizeFlexibility = RCTRootViewSizeFlexibilityWidthAndHeight;
35
         }
36
         }
36
         
37
         
37
         [self addSubview:subView];
38
         [self addSubview:subView];
40
     return self;
41
     return self;
41
 }
42
 }
42
 
43
 
44
+- (void)layoutSubviews {
45
+    [super layoutSubviews];
46
+    if ([self.alignment isEqualToString:@"fill"]) {
47
+        [self.subView setFrame:self.bounds];
48
+    }
49
+}
50
+
51
+- (NSString *)alignment {
52
+    return _alignment ? _alignment : @"center";
53
+}
54
+
43
 - (void)rootViewDidChangeIntrinsicSize:(RCTRootView *)rootView {
55
 - (void)rootViewDidChangeIntrinsicSize:(RCTRootView *)rootView {
44
     if ([self.alignment isEqualToString:@"center"]) {
56
     if ([self.alignment isEqualToString:@"center"]) {
45
         [self setFrame:CGRectMake(0, 0, rootView.intrinsicContentSize.width, rootView.intrinsicContentSize.height)];
57
         [self setFrame:CGRectMake(0, 0, rootView.intrinsicContentSize.width, rootView.intrinsicContentSize.height)];

+ 2
- 3
ios/RCCViewController.m View File

642
       
642
       
643
       NSDictionary *initialProps = self.navigatorStyle[@"navBarCustomViewInitialProps"];
643
       NSDictionary *initialProps = self.navigatorStyle[@"navBarCustomViewInitialProps"];
644
       RCTRootView *reactView = [[RCTRootView alloc] initWithBridge:bridge moduleName:navBarCustomView initialProperties:initialProps];
644
       RCTRootView *reactView = [[RCTRootView alloc] initWithBridge:bridge moduleName:navBarCustomView initialProperties:initialProps];
645
-      reactView.sizeFlexibility = RCTRootViewSizeFlexibilityWidthAndHeight;
646
-        
645
+
647
       RCCCustomTitleView *titleView = [[RCCCustomTitleView alloc] initWithFrame:self.navigationController.navigationBar.bounds
646
       RCCCustomTitleView *titleView = [[RCCCustomTitleView alloc] initWithFrame:self.navigationController.navigationBar.bounds
648
                                                                         subView:reactView
647
                                                                         subView:reactView
649
                                                                       alignment:self.navigatorStyle[@"navBarComponentAlignment"]];
648
                                                                       alignment:self.navigatorStyle[@"navBarComponentAlignment"]];
650
-      
649
+
651
       self.navigationItem.titleView = titleView;
650
       self.navigationItem.titleView = titleView;
652
       self.navigationItem.titleView.backgroundColor = [UIColor clearColor];
651
       self.navigationItem.titleView.backgroundColor = [UIColor clearColor];
653
       self.navigationItem.titleView.clipsToBounds = YES;
652
       self.navigationItem.titleView.clipsToBounds = YES;