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
     return (
20
     return (
21
       <View style={styles.container}>
21
       <View style={styles.container}>
22
         <TouchableOpacity stye={styles.button} onPress={ () => alert('Thanks for that :)') }>
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
           <Text style={{textAlign: 'center'}}>Press Me</Text>
24
           <Text style={{textAlign: 'center'}}>Press Me</Text>
25
         </TouchableOpacity>
25
         </TouchableOpacity>
26
 
26
 

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

11
 export default class CustomNavBarScreen extends Component {
11
 export default class CustomNavBarScreen extends Component {
12
   static navigatorStyle = {
12
   static navigatorStyle = {
13
     drawUnderTabBar: true,
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
   }
486
   }
487
   
487
   
488
   NSString *navBarCustomView = self.navigatorStyle[@"navBarCustomView"];
488
   NSString *navBarCustomView = self.navigatorStyle[@"navBarCustomView"];
489
-  if (navBarCustomView && !self.navigationItem.titleView) {
489
+  if (navBarCustomView && ![self.navigationItem.titleView isKindOfClass:[RCCCustomTitleView class]]) {
490
     if ([self.view isKindOfClass:[RCTRootView class]]) {
490
     if ([self.view isKindOfClass:[RCTRootView class]]) {
491
       
491
       
492
       RCTBridge *bridge = ((RCTRootView*)self.view).bridge;
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
       RCCCustomTitleView *titleView = [[RCCCustomTitleView alloc] initWithFrame:self.navigationController.navigationBar.bounds subView:reactView alignment:self.navigatorStyle[@"navBarComponentAlignment"]];
497
       RCCCustomTitleView *titleView = [[RCCCustomTitleView alloc] initWithFrame:self.navigationController.navigationBar.bounds subView:reactView alignment:self.navigatorStyle[@"navBarComponentAlignment"]];
496
       titleView.backgroundColor = [UIColor clearColor];
498
       titleView.backgroundColor = [UIColor clearColor];
497
       reactView.backgroundColor = [UIColor clearColor];
499
       reactView.backgroundColor = [UIColor clearColor];
498
-    
500
+      
499
       self.navigationItem.titleView = titleView;
501
       self.navigationItem.titleView = titleView;
500
       
502
       
501
       self.navigationItem.titleView.backgroundColor = [UIColor clearColor];
503
       self.navigationItem.titleView.backgroundColor = [UIColor clearColor];
502
       self.navigationItem.titleView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleRightMargin;
504
       self.navigationItem.titleView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleRightMargin;
503
       self.navigationItem.titleView.clipsToBounds = YES;
505
       self.navigationItem.titleView.clipsToBounds = YES;
504
     }
506
     }
505
-  }  
507
+  }
506
 }
508
 }
507
 
509
 
508
 
510