From 91c8362176cf2adf4bcc9326dc7e752bed3714f8 Mon Sep 17 00:00:00 2001 From: Alexsander Akers Date: Fri, 14 Aug 2015 11:08:25 -0100 Subject: [PATCH] Rename RCTReachability to RCTNetInfo --- Libraries/Network/NetInfo.js | 11 +++-------- .../Network/{RCTReachability.h => RCTNetInfo.h} | 2 +- .../Network/{RCTReachability.m => RCTNetInfo.m} | 12 ++++++------ .../Network/RCTNetwork.xcodeproj/project.pbxproj | 12 ++++++------ 4 files changed, 16 insertions(+), 21 deletions(-) rename Libraries/Network/{RCTReachability.h => RCTNetInfo.h} (89%) rename Libraries/Network/{RCTReachability.m => RCTNetInfo.m} (90%) diff --git a/Libraries/Network/NetInfo.js b/Libraries/Network/NetInfo.js index 63df3802b..f51a95529 100644 --- a/Libraries/Network/NetInfo.js +++ b/Libraries/Network/NetInfo.js @@ -15,14 +15,9 @@ var Map = require('Map'); var NativeModules = require('NativeModules'); var Platform = require('Platform'); var RCTDeviceEventEmitter = require('RCTDeviceEventEmitter'); +var RCTNetInfo = NativeModules.NetInfo; -if (Platform.OS === 'ios') { - var RCTNetInfo = NativeModules.Reachability; -} else if (Platform.OS === 'android') { - var RCTNetInfo = NativeModules.NetInfo; -} - -var DEVICE_REACHABILITY_EVENT = 'reachabilityDidChange'; +var DEVICE_REACHABILITY_EVENT = 'networkDidChange'; type ChangeEventName = $Enum<{ change: string; @@ -151,7 +146,7 @@ var NetInfo = { var listener = RCTDeviceEventEmitter.addListener( DEVICE_REACHABILITY_EVENT, (appStateData) => { - handler(appStateData.network_reachability); + handler(appStateData.network_info); } ); _subscriptions.set(handler, listener); diff --git a/Libraries/Network/RCTReachability.h b/Libraries/Network/RCTNetInfo.h similarity index 89% rename from Libraries/Network/RCTReachability.h rename to Libraries/Network/RCTNetInfo.h index ba74fcb42..6c2556e0a 100644 --- a/Libraries/Network/RCTReachability.h +++ b/Libraries/Network/RCTNetInfo.h @@ -11,7 +11,7 @@ #import "RCTBridgeModule.h" -@interface RCTReachability : NSObject +@interface RCTNetInfo : NSObject - (instancetype)initWithHost:(NSString *)host NS_DESIGNATED_INITIALIZER; diff --git a/Libraries/Network/RCTReachability.m b/Libraries/Network/RCTNetInfo.m similarity index 90% rename from Libraries/Network/RCTReachability.m rename to Libraries/Network/RCTNetInfo.m index 7c5530127..5aab64432 100644 --- a/Libraries/Network/RCTReachability.m +++ b/Libraries/Network/RCTNetInfo.m @@ -7,7 +7,7 @@ * of patent rights can be found in the PATENTS file in the same directory. */ -#import "RCTReachability.h" +#import "RCTNetInfo.h" #import "RCTAssert.h" #import "RCTBridge.h" @@ -18,7 +18,7 @@ static NSString *const RCTReachabilityStateNone = @"none"; static NSString *const RCTReachabilityStateWifi = @"wifi"; static NSString *const RCTReachabilityStateCell = @"cell"; -@implementation RCTReachability +@implementation RCTNetInfo { SCNetworkReachabilityRef _reachability; NSString *_status; @@ -30,7 +30,7 @@ RCT_EXPORT_MODULE() static void RCTReachabilityCallback(__unused SCNetworkReachabilityRef target, SCNetworkReachabilityFlags flags, void *info) { - RCTReachability *self = (__bridge id)info; + RCTNetInfo *self = (__bridge id)info; NSString *status = RCTReachabilityStateUnknown; if ((flags & kSCNetworkReachabilityFlagsReachable) == 0 || (flags & kSCNetworkReachabilityFlagsConnectionRequired) != 0) { @@ -51,8 +51,8 @@ static void RCTReachabilityCallback(__unused SCNetworkReachabilityRef target, SC if (![status isEqualToString:self->_status]) { self->_status = status; - [self->_bridge.eventDispatcher sendDeviceEventWithName:@"reachabilityDidChange" - body:@{@"network_reachability": status}]; + [self->_bridge.eventDispatcher sendDeviceEventWithName:@"networkDidChange" + body:@{@"network_info": status}]; } } @@ -90,7 +90,7 @@ static void RCTReachabilityCallback(__unused SCNetworkReachabilityRef target, SC RCT_EXPORT_METHOD(getCurrentReachability:(RCTResponseSenderBlock)getSuccess withErrorCallback:(__unused RCTResponseSenderBlock)getError) { - getSuccess(@[@{@"network_reachability": _status}]); + getSuccess(@[@{@"network_info": _status}]); } @end diff --git a/Libraries/Network/RCTNetwork.xcodeproj/project.pbxproj b/Libraries/Network/RCTNetwork.xcodeproj/project.pbxproj index 8243ac65f..546b301c2 100644 --- a/Libraries/Network/RCTNetwork.xcodeproj/project.pbxproj +++ b/Libraries/Network/RCTNetwork.xcodeproj/project.pbxproj @@ -7,7 +7,7 @@ objects = { /* Begin PBXBuildFile section */ - 1372B7371AB03E7B00659ED6 /* RCTReachability.m in Sources */ = {isa = PBXBuildFile; fileRef = 1372B7361AB03E7B00659ED6 /* RCTReachability.m */; }; + 1372B7371AB03E7B00659ED6 /* RCTNetInfo.m in Sources */ = {isa = PBXBuildFile; fileRef = 1372B7361AB03E7B00659ED6 /* RCTNetInfo.m */; }; 13D6D66A1B5FCF8200883BE9 /* RCTDownloadTask.m in Sources */ = {isa = PBXBuildFile; fileRef = 13D6D6691B5FCF8200883BE9 /* RCTDownloadTask.m */; }; 352DA0BA1B17855800AA15A8 /* RCTHTTPRequestHandler.m in Sources */ = {isa = PBXBuildFile; fileRef = 352DA0B81B17855800AA15A8 /* RCTHTTPRequestHandler.m */; }; 58B512081A9E6CE300147676 /* RCTNetworking.m in Sources */ = {isa = PBXBuildFile; fileRef = 58B512071A9E6CE300147676 /* RCTNetworking.m */; }; @@ -26,8 +26,8 @@ /* End PBXCopyFilesBuildPhase section */ /* Begin PBXFileReference section */ - 1372B7351AB03E7B00659ED6 /* RCTReachability.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RCTReachability.h; sourceTree = ""; }; - 1372B7361AB03E7B00659ED6 /* RCTReachability.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RCTReachability.m; sourceTree = ""; }; + 1372B7351AB03E7B00659ED6 /* RCTNetInfo.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; lineEnding = 0; path = RCTNetInfo.h; sourceTree = ""; xcLanguageSpecificationIdentifier = xcode.lang.objcpp; }; + 1372B7361AB03E7B00659ED6 /* RCTNetInfo.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; lineEnding = 0; path = RCTNetInfo.m; sourceTree = ""; xcLanguageSpecificationIdentifier = xcode.lang.objc; }; 13D6D6681B5FCF8200883BE9 /* RCTDownloadTask.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RCTDownloadTask.h; sourceTree = ""; }; 13D6D6691B5FCF8200883BE9 /* RCTDownloadTask.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RCTDownloadTask.m; sourceTree = ""; }; 352DA0B71B17855800AA15A8 /* RCTHTTPRequestHandler.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RCTHTTPRequestHandler.h; sourceTree = ""; }; @@ -55,10 +55,10 @@ 13D6D6691B5FCF8200883BE9 /* RCTDownloadTask.m */, 352DA0B71B17855800AA15A8 /* RCTHTTPRequestHandler.h */, 352DA0B81B17855800AA15A8 /* RCTHTTPRequestHandler.m */, + 1372B7351AB03E7B00659ED6 /* RCTNetInfo.h */, + 1372B7361AB03E7B00659ED6 /* RCTNetInfo.m */, 58B512061A9E6CE300147676 /* RCTNetworking.h */, 58B512071A9E6CE300147676 /* RCTNetworking.m */, - 1372B7351AB03E7B00659ED6 /* RCTReachability.h */, - 1372B7361AB03E7B00659ED6 /* RCTReachability.m */, 58B511DC1A9E6C8500147676 /* Products */, ); indentWidth = 2; @@ -130,7 +130,7 @@ buildActionMask = 2147483647; files = ( 13D6D66A1B5FCF8200883BE9 /* RCTDownloadTask.m in Sources */, - 1372B7371AB03E7B00659ED6 /* RCTReachability.m in Sources */, + 1372B7371AB03E7B00659ED6 /* RCTNetInfo.m in Sources */, 58B512081A9E6CE300147676 /* RCTNetworking.m in Sources */, 352DA0BA1B17855800AA15A8 /* RCTHTTPRequestHandler.m in Sources */, );