mirror of
https://github.com/status-im/react-native.git
synced 2025-01-14 19:44:13 +00:00
Rename RCTReachability to RCTNetInfo
This commit is contained in:
parent
decf35c271
commit
91c8362176
@ -15,14 +15,9 @@ var Map = require('Map');
|
|||||||
var NativeModules = require('NativeModules');
|
var NativeModules = require('NativeModules');
|
||||||
var Platform = require('Platform');
|
var Platform = require('Platform');
|
||||||
var RCTDeviceEventEmitter = require('RCTDeviceEventEmitter');
|
var RCTDeviceEventEmitter = require('RCTDeviceEventEmitter');
|
||||||
|
|
||||||
if (Platform.OS === 'ios') {
|
|
||||||
var RCTNetInfo = NativeModules.Reachability;
|
|
||||||
} else if (Platform.OS === 'android') {
|
|
||||||
var RCTNetInfo = NativeModules.NetInfo;
|
var RCTNetInfo = NativeModules.NetInfo;
|
||||||
}
|
|
||||||
|
|
||||||
var DEVICE_REACHABILITY_EVENT = 'reachabilityDidChange';
|
var DEVICE_REACHABILITY_EVENT = 'networkDidChange';
|
||||||
|
|
||||||
type ChangeEventName = $Enum<{
|
type ChangeEventName = $Enum<{
|
||||||
change: string;
|
change: string;
|
||||||
@ -151,7 +146,7 @@ var NetInfo = {
|
|||||||
var listener = RCTDeviceEventEmitter.addListener(
|
var listener = RCTDeviceEventEmitter.addListener(
|
||||||
DEVICE_REACHABILITY_EVENT,
|
DEVICE_REACHABILITY_EVENT,
|
||||||
(appStateData) => {
|
(appStateData) => {
|
||||||
handler(appStateData.network_reachability);
|
handler(appStateData.network_info);
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
_subscriptions.set(handler, listener);
|
_subscriptions.set(handler, listener);
|
||||||
|
@ -11,7 +11,7 @@
|
|||||||
|
|
||||||
#import "RCTBridgeModule.h"
|
#import "RCTBridgeModule.h"
|
||||||
|
|
||||||
@interface RCTReachability : NSObject<RCTBridgeModule>
|
@interface RCTNetInfo : NSObject<RCTBridgeModule>
|
||||||
|
|
||||||
- (instancetype)initWithHost:(NSString *)host NS_DESIGNATED_INITIALIZER;
|
- (instancetype)initWithHost:(NSString *)host NS_DESIGNATED_INITIALIZER;
|
||||||
|
|
@ -7,7 +7,7 @@
|
|||||||
* of patent rights can be found in the PATENTS file in the same directory.
|
* of patent rights can be found in the PATENTS file in the same directory.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#import "RCTReachability.h"
|
#import "RCTNetInfo.h"
|
||||||
|
|
||||||
#import "RCTAssert.h"
|
#import "RCTAssert.h"
|
||||||
#import "RCTBridge.h"
|
#import "RCTBridge.h"
|
||||||
@ -18,7 +18,7 @@ static NSString *const RCTReachabilityStateNone = @"none";
|
|||||||
static NSString *const RCTReachabilityStateWifi = @"wifi";
|
static NSString *const RCTReachabilityStateWifi = @"wifi";
|
||||||
static NSString *const RCTReachabilityStateCell = @"cell";
|
static NSString *const RCTReachabilityStateCell = @"cell";
|
||||||
|
|
||||||
@implementation RCTReachability
|
@implementation RCTNetInfo
|
||||||
{
|
{
|
||||||
SCNetworkReachabilityRef _reachability;
|
SCNetworkReachabilityRef _reachability;
|
||||||
NSString *_status;
|
NSString *_status;
|
||||||
@ -30,7 +30,7 @@ RCT_EXPORT_MODULE()
|
|||||||
|
|
||||||
static void RCTReachabilityCallback(__unused SCNetworkReachabilityRef target, SCNetworkReachabilityFlags flags, void *info)
|
static void RCTReachabilityCallback(__unused SCNetworkReachabilityRef target, SCNetworkReachabilityFlags flags, void *info)
|
||||||
{
|
{
|
||||||
RCTReachability *self = (__bridge id)info;
|
RCTNetInfo *self = (__bridge id)info;
|
||||||
NSString *status = RCTReachabilityStateUnknown;
|
NSString *status = RCTReachabilityStateUnknown;
|
||||||
if ((flags & kSCNetworkReachabilityFlagsReachable) == 0 ||
|
if ((flags & kSCNetworkReachabilityFlagsReachable) == 0 ||
|
||||||
(flags & kSCNetworkReachabilityFlagsConnectionRequired) != 0) {
|
(flags & kSCNetworkReachabilityFlagsConnectionRequired) != 0) {
|
||||||
@ -51,8 +51,8 @@ static void RCTReachabilityCallback(__unused SCNetworkReachabilityRef target, SC
|
|||||||
|
|
||||||
if (![status isEqualToString:self->_status]) {
|
if (![status isEqualToString:self->_status]) {
|
||||||
self->_status = status;
|
self->_status = status;
|
||||||
[self->_bridge.eventDispatcher sendDeviceEventWithName:@"reachabilityDidChange"
|
[self->_bridge.eventDispatcher sendDeviceEventWithName:@"networkDidChange"
|
||||||
body:@{@"network_reachability": status}];
|
body:@{@"network_info": status}];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -90,7 +90,7 @@ static void RCTReachabilityCallback(__unused SCNetworkReachabilityRef target, SC
|
|||||||
RCT_EXPORT_METHOD(getCurrentReachability:(RCTResponseSenderBlock)getSuccess
|
RCT_EXPORT_METHOD(getCurrentReachability:(RCTResponseSenderBlock)getSuccess
|
||||||
withErrorCallback:(__unused RCTResponseSenderBlock)getError)
|
withErrorCallback:(__unused RCTResponseSenderBlock)getError)
|
||||||
{
|
{
|
||||||
getSuccess(@[@{@"network_reachability": _status}]);
|
getSuccess(@[@{@"network_info": _status}]);
|
||||||
}
|
}
|
||||||
|
|
||||||
@end
|
@end
|
@ -7,7 +7,7 @@
|
|||||||
objects = {
|
objects = {
|
||||||
|
|
||||||
/* Begin PBXBuildFile section */
|
/* 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 */; };
|
13D6D66A1B5FCF8200883BE9 /* RCTDownloadTask.m in Sources */ = {isa = PBXBuildFile; fileRef = 13D6D6691B5FCF8200883BE9 /* RCTDownloadTask.m */; };
|
||||||
352DA0BA1B17855800AA15A8 /* RCTHTTPRequestHandler.m in Sources */ = {isa = PBXBuildFile; fileRef = 352DA0B81B17855800AA15A8 /* RCTHTTPRequestHandler.m */; };
|
352DA0BA1B17855800AA15A8 /* RCTHTTPRequestHandler.m in Sources */ = {isa = PBXBuildFile; fileRef = 352DA0B81B17855800AA15A8 /* RCTHTTPRequestHandler.m */; };
|
||||||
58B512081A9E6CE300147676 /* RCTNetworking.m in Sources */ = {isa = PBXBuildFile; fileRef = 58B512071A9E6CE300147676 /* RCTNetworking.m */; };
|
58B512081A9E6CE300147676 /* RCTNetworking.m in Sources */ = {isa = PBXBuildFile; fileRef = 58B512071A9E6CE300147676 /* RCTNetworking.m */; };
|
||||||
@ -26,8 +26,8 @@
|
|||||||
/* End PBXCopyFilesBuildPhase section */
|
/* End PBXCopyFilesBuildPhase section */
|
||||||
|
|
||||||
/* Begin PBXFileReference section */
|
/* Begin PBXFileReference section */
|
||||||
1372B7351AB03E7B00659ED6 /* RCTReachability.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RCTReachability.h; sourceTree = "<group>"; };
|
1372B7351AB03E7B00659ED6 /* RCTNetInfo.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; lineEnding = 0; path = RCTNetInfo.h; sourceTree = "<group>"; xcLanguageSpecificationIdentifier = xcode.lang.objcpp; };
|
||||||
1372B7361AB03E7B00659ED6 /* RCTReachability.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RCTReachability.m; sourceTree = "<group>"; };
|
1372B7361AB03E7B00659ED6 /* RCTNetInfo.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; lineEnding = 0; path = RCTNetInfo.m; sourceTree = "<group>"; xcLanguageSpecificationIdentifier = xcode.lang.objc; };
|
||||||
13D6D6681B5FCF8200883BE9 /* RCTDownloadTask.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RCTDownloadTask.h; sourceTree = "<group>"; };
|
13D6D6681B5FCF8200883BE9 /* RCTDownloadTask.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RCTDownloadTask.h; sourceTree = "<group>"; };
|
||||||
13D6D6691B5FCF8200883BE9 /* RCTDownloadTask.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RCTDownloadTask.m; sourceTree = "<group>"; };
|
13D6D6691B5FCF8200883BE9 /* RCTDownloadTask.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RCTDownloadTask.m; sourceTree = "<group>"; };
|
||||||
352DA0B71B17855800AA15A8 /* RCTHTTPRequestHandler.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RCTHTTPRequestHandler.h; sourceTree = "<group>"; };
|
352DA0B71B17855800AA15A8 /* RCTHTTPRequestHandler.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RCTHTTPRequestHandler.h; sourceTree = "<group>"; };
|
||||||
@ -55,10 +55,10 @@
|
|||||||
13D6D6691B5FCF8200883BE9 /* RCTDownloadTask.m */,
|
13D6D6691B5FCF8200883BE9 /* RCTDownloadTask.m */,
|
||||||
352DA0B71B17855800AA15A8 /* RCTHTTPRequestHandler.h */,
|
352DA0B71B17855800AA15A8 /* RCTHTTPRequestHandler.h */,
|
||||||
352DA0B81B17855800AA15A8 /* RCTHTTPRequestHandler.m */,
|
352DA0B81B17855800AA15A8 /* RCTHTTPRequestHandler.m */,
|
||||||
|
1372B7351AB03E7B00659ED6 /* RCTNetInfo.h */,
|
||||||
|
1372B7361AB03E7B00659ED6 /* RCTNetInfo.m */,
|
||||||
58B512061A9E6CE300147676 /* RCTNetworking.h */,
|
58B512061A9E6CE300147676 /* RCTNetworking.h */,
|
||||||
58B512071A9E6CE300147676 /* RCTNetworking.m */,
|
58B512071A9E6CE300147676 /* RCTNetworking.m */,
|
||||||
1372B7351AB03E7B00659ED6 /* RCTReachability.h */,
|
|
||||||
1372B7361AB03E7B00659ED6 /* RCTReachability.m */,
|
|
||||||
58B511DC1A9E6C8500147676 /* Products */,
|
58B511DC1A9E6C8500147676 /* Products */,
|
||||||
);
|
);
|
||||||
indentWidth = 2;
|
indentWidth = 2;
|
||||||
@ -130,7 +130,7 @@
|
|||||||
buildActionMask = 2147483647;
|
buildActionMask = 2147483647;
|
||||||
files = (
|
files = (
|
||||||
13D6D66A1B5FCF8200883BE9 /* RCTDownloadTask.m in Sources */,
|
13D6D66A1B5FCF8200883BE9 /* RCTDownloadTask.m in Sources */,
|
||||||
1372B7371AB03E7B00659ED6 /* RCTReachability.m in Sources */,
|
1372B7371AB03E7B00659ED6 /* RCTNetInfo.m in Sources */,
|
||||||
58B512081A9E6CE300147676 /* RCTNetworking.m in Sources */,
|
58B512081A9E6CE300147676 /* RCTNetworking.m in Sources */,
|
||||||
352DA0BA1B17855800AA15A8 /* RCTHTTPRequestHandler.m in Sources */,
|
352DA0BA1B17855800AA15A8 /* RCTHTTPRequestHandler.m in Sources */,
|
||||||
);
|
);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user