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
This commit is contained in:
parent
bf5aa9e1e7
commit
93a263d874
|
@ -14,6 +14,8 @@
|
|||
@implementation RCTRefreshControl {
|
||||
BOOL _isInitialRender;
|
||||
BOOL _currentRefreshingState;
|
||||
NSString *_title;
|
||||
UIColor *_titleColor;
|
||||
}
|
||||
|
||||
- (instancetype)init
|
||||
|
@ -86,23 +88,33 @@ RCT_NOT_IMPLEMENTED(- (instancetype)initWithCoder:(NSCoder *)aDecoder)
|
|||
|
||||
- (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
|
||||
|
|
Loading…
Reference in New Issue