Browse Source

fix navBarSubtitleColor - now it will set the navigation subtitle color properly without any effect on the title (#1847)

Ran Greenberg 7 years ago
parent
commit
3f377f65df
2 changed files with 19 additions and 1 deletions
  1. 10
    0
      example/src/screens/Actions.js
  2. 9
    1
      ios/Helpers/RCCTitleViewHelper.m

+ 10
- 0
example/src/screens/Actions.js View File

@@ -27,6 +27,15 @@ class Actions extends React.Component {
27 27
     });
28 28
   };
29 29
 
30
+  setSubtitle = () => {
31
+    this.props.navigator.setSubTitle({
32
+      subtitle: 'New SubTitle!',
33
+      navigatorStyle: {
34
+        navBarSubtitleColor: 'red'
35
+      }
36
+    });
37
+  };
38
+
30 39
   toggleTabs = () => {
31 40
     const to = this._toggleTabs === 'shown' ? 'hidden' : 'shown';
32 41
 
@@ -142,6 +151,7 @@ class Actions extends React.Component {
142 151
     return (
143 152
       <ScrollView style={styles.container}>
144 153
         <Row title={'Set Title'} onPress={this.setTitle} />
154
+        <Row title={'Set Subtitle'} onPress={this.setSubtitle} />
145 155
         <Row title={'Toggle Tabs'} onPress={this.toggleTabs} />
146 156
         <Row title={'Set Tab Badge'} onPress={this.setTabBadge} />
147 157
         <Row title={'Switch To Tab 0'} onPress={this.switchToTab} />

+ 9
- 1
ios/Helpers/RCCTitleViewHelper.m View File

@@ -8,6 +8,7 @@
8 8
 
9 9
 #import "RCCTitleViewHelper.h"
10 10
 #import <React/RCTConvert.h>
11
+#import "RCCViewController.h"
11 12
 #import "RCTHelpers.h"
12 13
 
13 14
 @implementation RCCTitleView
@@ -69,6 +70,13 @@ navigationController:(UINavigationController*)navigationController
69 70
         return;
70 71
     }
71 72
     
73
+    if ([self.viewController isKindOfClass:[RCCViewController class]]) {
74
+        NSMutableDictionary *mergedStyle = [NSMutableDictionary dictionaryWithDictionary:((RCCViewController*)self.viewController).navigatorStyle];
75
+        [mergedStyle addEntriesFromDictionary:style];
76
+        
77
+        style = mergedStyle;
78
+    }
79
+    
72 80
     CGRect navigationBarBounds = self.navigationController.navigationBar.bounds;
73 81
     
74 82
     self.titleView = [[RCCTitleView alloc] initWithFrame:navigationBarBounds];
@@ -164,7 +172,7 @@ navigationController:(UINavigationController*)navigationController
164 172
     labelframe.size = labelSize;
165 173
     subtitleLabel.frame = labelframe;
166 174
     [subtitleLabel sizeToFit];
167
-
175
+    
168 176
     [self.titleView addSubview:subtitleLabel];
169 177
     
170 178
     return subtitleLabel;