From 849a0f31acb71b62745d2abbb92e67fde55313be Mon Sep 17 00:00:00 2001 From: Sokovikov Date: Sat, 16 Apr 2016 15:14:50 -0700 Subject: [PATCH] Allow to set refresh control title color Summary:Closes #6812 ![simulator screen shot 14 apr 2016 12 13 36](https://cloud.githubusercontent.com/assets/1488195/14521441/0abccf5c-0232-11e6-94dc-0ebdbfac4b3f.png) Closes https://github.com/facebook/react-native/pull/6970 Differential Revision: D3189244 fb-gh-sync-id: 7625b6ab5859aaa20bc0cb379855c5daeb584abf fbshipit-source-id: 7625b6ab5859aaa20bc0cb379855c5daeb584abf --- Examples/UIExplorer/RefreshControlExample.js | 1 + .../Components/RefreshControl/RefreshControl.js | 5 +++++ React/Views/RCTRefreshControl.m | 13 ++++++++++++- React/Views/RCTRefreshControlManager.m | 1 + 4 files changed, 19 insertions(+), 1 deletion(-) diff --git a/Examples/UIExplorer/RefreshControlExample.js b/Examples/UIExplorer/RefreshControlExample.js index b6bca301316..e3fb6e184d8 100644 --- a/Examples/UIExplorer/RefreshControlExample.js +++ b/Examples/UIExplorer/RefreshControlExample.js @@ -94,6 +94,7 @@ const RefreshControlExample = React.createClass({ onRefresh={this._onRefresh} tintColor="#ff0000" title="Loading..." + titleColor="#00ff00" colors={['#ff0000', '#00ff00', '#0000ff']} progressBackgroundColor="#ffff00" /> diff --git a/Libraries/Components/RefreshControl/RefreshControl.js b/Libraries/Components/RefreshControl/RefreshControl.js index f79305d935a..1a9389f4a4e 100644 --- a/Libraries/Components/RefreshControl/RefreshControl.js +++ b/Libraries/Components/RefreshControl/RefreshControl.js @@ -92,6 +92,11 @@ const RefreshControl = React.createClass({ * @platform ios */ tintColor: ColorPropType, + /** + * Title color. + * @platform ios + */ + titleColor: ColorPropType, /** * The title displayed under the refresh indicator. * @platform ios diff --git a/React/Views/RCTRefreshControl.m b/React/Views/RCTRefreshControl.m index 8b8638a2d94..a316246bcc1 100644 --- a/React/Views/RCTRefreshControl.m +++ b/React/Views/RCTRefreshControl.m @@ -89,7 +89,18 @@ RCT_NOT_IMPLEMENTED(- (instancetype)initWithCoder:(NSCoder *)aDecoder) - (void)setTitle:(NSString *)title { - self.attributedTitle = [[NSAttributedString alloc] initWithString:title]; + NSRange range = NSMakeRange(0, self.attributedTitle.length); + NSDictionary *attrs = [self.attributedTitle attributesAtIndex:0 effectiveRange: &range]; + self.attributedTitle = [[NSAttributedString alloc] initWithString:title attributes:attrs]; +} + +- (void)setTitleColor:(UIColor *)color +{ + NSRange range = NSMakeRange(0, self.attributedTitle.length); + NSDictionary *attrs = [self.attributedTitle attributesAtIndex:0 effectiveRange: &range]; + NSMutableDictionary *attrsMutable = [attrs mutableCopy]; + [attrsMutable setObject:color forKey:NSForegroundColorAttributeName]; + self.attributedTitle = [[NSAttributedString alloc] initWithString:self.attributedTitle.string attributes:attrsMutable]; } - (void)setRefreshing:(BOOL)refreshing diff --git a/React/Views/RCTRefreshControlManager.m b/React/Views/RCTRefreshControlManager.m index bc479a150eb..cd5e1759149 100644 --- a/React/Views/RCTRefreshControlManager.m +++ b/React/Views/RCTRefreshControlManager.m @@ -24,5 +24,6 @@ RCT_EXPORT_VIEW_PROPERTY(onRefresh, RCTDirectEventBlock) RCT_EXPORT_VIEW_PROPERTY(refreshing, BOOL) RCT_EXPORT_VIEW_PROPERTY(tintColor, UIColor) RCT_EXPORT_VIEW_PROPERTY(title, NSString) +RCT_EXPORT_VIEW_PROPERTY(titleColor, UIColor) @end