Browse Source

fix custom nav bar view and add initial props (#1172)

Ran 7 years ago
parent
commit
249acca9a9

+ 1
- 1
example/src/screens/CustomNavBar.js View File

@@ -20,7 +20,7 @@ export default class CustomNavBar extends Component {
20 20
     return (
21 21
       <View style={styles.container}>
22 22
         <TouchableOpacity stye={styles.button} onPress={ () => alert('Thanks for that :)') }>
23
-          <Text style={{color: 'red', textAlign: 'center'}}>Hi Custom</Text>
23
+          <Text style={{color: 'red', textAlign: 'center'}}>{this.props.name}</Text>
24 24
           <Text style={{textAlign: 'center'}}>Press Me</Text>
25 25
         </TouchableOpacity>
26 26
 

+ 2
- 1
example/src/screens/CustomNavBarScreen.js View File

@@ -11,7 +11,8 @@ import {
11 11
 export default class CustomNavBarScreen extends Component {
12 12
   static navigatorStyle = {
13 13
     drawUnderTabBar: true,
14
-    navBarCustomView: 'example.CustomNavBar'
14
+    navBarCustomView: 'example.CustomNavBar',
15
+    navBarCustomViewInitialProps: {name: 'Hi Custom'}
15 16
   };
16 17
 
17 18
 

+ 6
- 4
ios/RCCViewController.m View File

@@ -486,23 +486,25 @@ const NSInteger TRANSPARENT_NAVBAR_TAG = 78264803;
486 486
   }
487 487
   
488 488
   NSString *navBarCustomView = self.navigatorStyle[@"navBarCustomView"];
489
-  if (navBarCustomView && !self.navigationItem.titleView) {
489
+  if (navBarCustomView && ![self.navigationItem.titleView isKindOfClass:[RCCCustomTitleView class]]) {
490 490
     if ([self.view isKindOfClass:[RCTRootView class]]) {
491 491
       
492 492
       RCTBridge *bridge = ((RCTRootView*)self.view).bridge;
493
-      RCTRootView *reactView = [[RCTRootView alloc] initWithBridge:bridge moduleName:navBarCustomView initialProperties:nil];
493
+      
494
+      NSDictionary *initialProps = self.navigatorStyle[@"navBarCustomViewInitialProps"];
495
+      RCTRootView *reactView = [[RCTRootView alloc] initWithBridge:bridge moduleName:navBarCustomView initialProperties:initialProps];
494 496
       
495 497
       RCCCustomTitleView *titleView = [[RCCCustomTitleView alloc] initWithFrame:self.navigationController.navigationBar.bounds subView:reactView alignment:self.navigatorStyle[@"navBarComponentAlignment"]];
496 498
       titleView.backgroundColor = [UIColor clearColor];
497 499
       reactView.backgroundColor = [UIColor clearColor];
498
-    
500
+      
499 501
       self.navigationItem.titleView = titleView;
500 502
       
501 503
       self.navigationItem.titleView.backgroundColor = [UIColor clearColor];
502 504
       self.navigationItem.titleView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleRightMargin;
503 505
       self.navigationItem.titleView.clipsToBounds = YES;
504 506
     }
505
-  }  
507
+  }
506 508
 }
507 509
 
508 510