Unforked ExceptionsManager, AlertManager and AppState

This commit is contained in:
Nick Lockwood
2015-03-11 13:53:30 -07:00
parent 30d3117f96
commit 2424711a03
12 changed files with 376 additions and 10 deletions

View File

@@ -7,6 +7,7 @@
objects = {
/* Begin PBXBuildFile section */
1372B7371AB03E7B00659ED6 /* RCTReachability.m in Sources */ = {isa = PBXBuildFile; fileRef = 1372B7361AB03E7B00659ED6 /* RCTReachability.m */; };
58B512081A9E6CE300147676 /* RCTDataManager.m in Sources */ = {isa = PBXBuildFile; fileRef = 58B512071A9E6CE300147676 /* RCTDataManager.m */; };
/* End PBXBuildFile section */
@@ -23,6 +24,8 @@
/* End PBXCopyFilesBuildPhase section */
/* Begin PBXFileReference section */
1372B7351AB03E7B00659ED6 /* RCTReachability.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RCTReachability.h; sourceTree = "<group>"; };
1372B7361AB03E7B00659ED6 /* RCTReachability.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RCTReachability.m; sourceTree = "<group>"; };
58B511DB1A9E6C8500147676 /* libRCTNetwork.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = libRCTNetwork.a; sourceTree = BUILT_PRODUCTS_DIR; };
58B512061A9E6CE300147676 /* RCTDataManager.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RCTDataManager.h; sourceTree = "<group>"; };
58B512071A9E6CE300147676 /* RCTDataManager.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RCTDataManager.m; sourceTree = "<group>"; };
@@ -44,6 +47,8 @@
children = (
58B512061A9E6CE300147676 /* RCTDataManager.h */,
58B512071A9E6CE300147676 /* RCTDataManager.m */,
1372B7351AB03E7B00659ED6 /* RCTReachability.h */,
1372B7361AB03E7B00659ED6 /* RCTReachability.m */,
58B511DC1A9E6C8500147676 /* Products */,
);
sourceTree = "<group>";
@@ -112,6 +117,7 @@
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
1372B7371AB03E7B00659ED6 /* RCTReachability.m in Sources */,
58B512081A9E6CE300147676 /* RCTDataManager.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;

View File

@@ -0,0 +1,11 @@
// Copyright 2004-present Facebook. All Rights Reserved.
#import <SystemConfiguration/SystemConfiguration.h>
#import "RCTBridgeModule.h"
@interface RCTReachability : NSObject<RCTBridgeModule>
- (instancetype)initWithHost:(NSString *)host NS_DESIGNATED_INITIALIZER;
@end

View File

@@ -0,0 +1,85 @@
// Copyright 2004-present Facebook. All Rights Reserved.
#import "RCTReachability.h"
#import "RCTBridge.h"
#import "RCTEventDispatcher.h"
static NSString *const RCTReachabilityStateUnknown = @"unknown";
static NSString *const RCTReachabilityStateNone = @"none";
static NSString *const RCTReachabilityStateWifi = @"wifi";
static NSString *const RCTReachabilityStateCell = @"cell";
@implementation RCTReachability
{
SCNetworkReachabilityRef _reachability;
NSString *_status;
}
@synthesize bridge = _bridge;
static void RCTReachabilityCallback(__unused SCNetworkReachabilityRef target, SCNetworkReachabilityFlags flags, void *info)
{
RCTReachability *self = (__bridge id)info;
NSString *status = RCTReachabilityStateUnknown;
if ((flags & kSCNetworkReachabilityFlagsReachable) == 0 ||
(flags & kSCNetworkReachabilityFlagsConnectionRequired) != 0) {
status = RCTReachabilityStateNone;
}
#if TARGET_OS_IPHONE
else if ((flags & kSCNetworkReachabilityFlagsIsWWAN) != 0) {
status = RCTReachabilityStateCell;
}
#endif
else {
status = RCTReachabilityStateWifi;
}
if (![status isEqualToString:self->_status]) {
self->_status = status;
[self->_bridge.eventDispatcher sendDeviceEventWithName:@"reachabilityDidChange"
body:@{@"network_reachability": status}];
}
}
#pragma mark - Lifecycle
- (instancetype)initWithHost:(NSString *)host
{
if ((self = [super init])) {
_status = RCTReachabilityStateUnknown;
_reachability = SCNetworkReachabilityCreateWithName(kCFAllocatorDefault, [host UTF8String]);
SCNetworkReachabilityContext context = { 0, ( __bridge void *)self, NULL, NULL, NULL };
SCNetworkReachabilitySetCallback(_reachability, RCTReachabilityCallback, &context);
SCNetworkReachabilityScheduleWithRunLoop(_reachability, CFRunLoopGetMain(), kCFRunLoopCommonModes);
}
return self;
}
- (instancetype)init
{
return [self initWithHost:@"http://apple.com"];
}
- (void)dealloc
{
SCNetworkReachabilityUnscheduleFromRunLoop(_reachability, CFRunLoopGetMain(), kCFRunLoopCommonModes);
CFRelease(_reachability);
}
#pragma mark - Public API
// TODO: remove error callback - not needed except by Subscribable interface
- (void)getCurrentReachability:(RCTResponseSenderBlock)getSuccess
withErrorCallback:(__unused RCTResponseSenderBlock)getError
{
RCT_EXPORT();
getSuccess(@[@{@"network_reachability": _status}]);
}
@end