Permalink
Browse files

Make RCTRefreshControl not dependent on order of setting properties

Summary: With the Cxx bridge, properties are not guaranteed to be set it any order (and furthermore, they should not be). RCTRefreshControl previously had its title set first, and would crash otherwise. This fixes that.

Reviewed By: mhorowitz

Differential Revision: D4580253

fbshipit-source-id: 39baecceb8b67c6a851c08ba9cabbf4dc99359cb
  • Loading branch information...
mmmulani authored and facebook-github-bot committed Feb 17, 2017
1 parent bf5aa9e commit 93a263d874789c23646cb1f77df0198e9e58cf33
Showing with 21 additions and 9 deletions.
  1. +21 −9 React/Views/RCTRefreshControl.m
@@ -14,6 +14,8 @@
@implementation RCTRefreshControl {
BOOL _isInitialRender;
BOOL _currentRefreshingState;
NSString *_title;
UIColor *_titleColor;
}
- (instancetype)init
@@ -86,23 +88,33 @@ - (void)endRefreshing
- (NSString *)title
{
return self.attributedTitle.string;
return _title;
}
- (void)setTitle:(NSString *)title
{
NSRange range = NSMakeRange(0, self.attributedTitle.length);
NSDictionary *attrs = [self.attributedTitle attributesAtIndex:0 effectiveRange: &range];
self.attributedTitle = [[NSAttributedString alloc] initWithString:title attributes:attrs];
_title = title;
[self _updateTitle];
}
- (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];
_titleColor = color;
[self _updateTitle];
}
- (void)_updateTitle
{
if (!_title) {
return;
}
NSMutableDictionary *attributes = [NSMutableDictionary dictionary];
if (_titleColor) {
attributes[NSForegroundColorAttributeName] = _titleColor;
}
self.attributedTitle = [[NSAttributedString alloc] initWithString:_title attributes:attributes];
}
- (void)setRefreshing:(BOOL)refreshing

0 comments on commit 93a263d

Please sign in to comment.