mirror of
https://github.com/status-im/react-native.git
synced 2025-02-20 13:18:07 +00:00
Ensure RCTImageCache's DateFormatter is only allocated once
Summary: This change attempts to fix a crash within RCTImageCache's new dateWithHeaderString method. This is a speculative fix as there aren't any concrete repro steps. Reviewed By: hramos Differential Revision: D13278666 fbshipit-source-id: cdb69b1296c946d89e14c074329280994d87ddcd
This commit is contained in:
parent
fe97458b03
commit
668341a294
@ -32,8 +32,6 @@ static NSString *RCTCacheKeyForImage(NSString *imageTag, CGSize size, CGFloat sc
|
||||
NSOperationQueue *_imageDecodeQueue;
|
||||
NSCache *_decodedImageCache;
|
||||
NSMutableDictionary *_cacheStaleTimes;
|
||||
|
||||
NSDateFormatter *_headerDateFormatter;
|
||||
}
|
||||
|
||||
- (instancetype)init
|
||||
@ -50,7 +48,7 @@ static NSString *RCTCacheKeyForImage(NSString *imageTag, CGSize size, CGFloat sc
|
||||
selector:@selector(clearCache)
|
||||
name:UIApplicationWillResignActiveNotification
|
||||
object:nil];
|
||||
|
||||
|
||||
return self;
|
||||
}
|
||||
|
||||
@ -137,14 +135,16 @@ static NSString *RCTCacheKeyForImage(NSString *imageTag, CGSize size, CGFloat sc
|
||||
}
|
||||
|
||||
- (NSDate *)dateWithHeaderString:(NSString *)headerDateString {
|
||||
if (_headerDateFormatter == nil) {
|
||||
_headerDateFormatter = [[NSDateFormatter alloc] init];
|
||||
_headerDateFormatter.locale = [[NSLocale alloc] initWithLocaleIdentifier:@"en_US_POSIX"];
|
||||
_headerDateFormatter.dateFormat = @"EEE',' dd MMM yyyy HH':'mm':'ss 'GMT'";
|
||||
_headerDateFormatter.timeZone = [NSTimeZone timeZoneForSecondsFromGMT:0];
|
||||
}
|
||||
static NSDateFormatter *formatter;
|
||||
static dispatch_once_t onceToken;
|
||||
dispatch_once(&onceToken, ^{
|
||||
formatter = [[NSDateFormatter alloc] init];
|
||||
formatter.locale = [[NSLocale alloc] initWithLocaleIdentifier:@"en_US_POSIX"];
|
||||
formatter.dateFormat = @"EEE',' dd MMM yyyy HH':'mm':'ss 'GMT'";
|
||||
formatter.timeZone = [NSTimeZone timeZoneForSecondsFromGMT:0];
|
||||
});
|
||||
|
||||
return [_headerDateFormatter dateFromString:headerDateString];
|
||||
return [formatter dateFromString:headerDateString];
|
||||
}
|
||||
|
||||
@end
|
||||
|
Loading…
x
Reference in New Issue
Block a user