From 79c1be8f21de82647d96283f80c36a31e584046f Mon Sep 17 00:00:00 2001 From: Rafael Lincoln Date: Mon, 28 Jan 2019 03:54:53 -0800 Subject: [PATCH] Fix Warnings in Xcode (#23184) Summary: His PR is related to #22609 Changelog: ---------- [IOS][Changed] - Fix warning in RCTImage [IOS][Changed] - Fix warning in RCTNetwork Pull Request resolved: https://github.com/facebook/react-native/pull/23184 Differential Revision: D13838680 Pulled By: cpojer fbshipit-source-id: 698303e44bb85a4819abff7d71e0b75936c09dc8 --- Libraries/Image/RCTImageCache.m | 26 ++++++++++++++------------ moved/RCTNetInfo.m | 17 +++++++++++------ 2 files changed, 25 insertions(+), 18 deletions(-) diff --git a/Libraries/Image/RCTImageCache.m b/Libraries/Image/RCTImageCache.m index a25f35222a7a0b..9a941f1b889e1a 100644 --- a/Libraries/Image/RCTImageCache.m +++ b/Libraries/Image/RCTImageCache.m @@ -36,18 +36,20 @@ @implementation RCTImageCache - (instancetype)init { - _decodedImageCache = [NSCache new]; - _decodedImageCache.totalCostLimit = 20 * 1024 * 1024; // 20 MB - _cacheStaleTimes = [[NSMutableDictionary alloc] init]; - - [[NSNotificationCenter defaultCenter] addObserver:self - selector:@selector(clearCache) - name:UIApplicationDidReceiveMemoryWarningNotification - object:nil]; - [[NSNotificationCenter defaultCenter] addObserver:self - selector:@selector(clearCache) - name:UIApplicationWillResignActiveNotification - object:nil]; + if (self = [super init]) { + _decodedImageCache = [NSCache new]; + _decodedImageCache.totalCostLimit = 20 * 1024 * 1024; // 20 MB + _cacheStaleTimes = [[NSMutableDictionary alloc] init]; + + [[NSNotificationCenter defaultCenter] addObserver:self + selector:@selector(clearCache) + name:UIApplicationDidReceiveMemoryWarningNotification + object:nil]; + [[NSNotificationCenter defaultCenter] addObserver:self + selector:@selector(clearCache) + name:UIApplicationWillResignActiveNotification + object:nil]; + } return self; } diff --git a/moved/RCTNetInfo.m b/moved/RCTNetInfo.m index b3ee23c1796da9..f9441f16b7af65 100644 --- a/moved/RCTNetInfo.m +++ b/moved/RCTNetInfo.m @@ -52,20 +52,25 @@ static void RCTReachabilityCallback(__unused SCNetworkReachabilityRef target, SC { RCTNetInfo *self = (__bridge id)info; BOOL didSetReachabilityFlags = [self setReachabilityStatus:flags]; + + NSString *connectionType = self->_connectionType ?: RCTConnectionTypeUnknown; + NSString *effectiveConnectionType = self->_effectiveConnectionType ?: RCTEffectiveConnectionTypeUnknown; + NSString *networkInfo = self->_statusDeprecated ?: RCTReachabilityStateUnknown; + if (self->_firstTimeReachability && self->_resolve) { SCNetworkReachabilityUnscheduleFromRunLoop(self->_firstTimeReachability, CFRunLoopGetMain(), kCFRunLoopCommonModes); CFRelease(self->_firstTimeReachability); - self->_resolve(@{@"connectionType": self->_connectionType ?: RCTConnectionTypeUnknown, - @"effectiveConnectionType": self->_effectiveConnectionType ?: RCTEffectiveConnectionTypeUnknown, - @"network_info": self->_statusDeprecated ?: RCTReachabilityStateUnknown}); + self->_resolve(@{@"connectionType": connectionType, + @"effectiveConnectionType": effectiveConnectionType, + @"network_info": networkInfo}); self->_firstTimeReachability = nil; self->_resolve = nil; } if (didSetReachabilityFlags && self->_isObserving) { - [self sendEventWithName:@"networkStatusDidChange" body:@{@"connectionType": self->_connectionType, - @"effectiveConnectionType": self->_effectiveConnectionType, - @"network_info": self->_statusDeprecated}]; + [self sendEventWithName:@"networkStatusDidChange" body:@{@"connectionType": connectionType, + @"effectiveConnectionType": effectiveConnectionType, + @"network_info": networkInfo}]; } }