[ReactNative] OSS snapshot tests

This commit is contained in:
Spencer Ahrens
2015-03-24 10:20:13 -07:00
parent c9a40a989b
commit 3f137da232
22 changed files with 1261 additions and 40 deletions

View File

@@ -11,7 +11,7 @@
#import "RCTBridge.h"
@interface RCTRootView : UIView
@interface RCTRootView : UIView<RCTInvalidating>
/**
* The URL of the bundled application script (required).

View File

@@ -106,12 +106,32 @@ static Class _globalExecutorClass;
[_bridge enqueueJSCall:@"ReactIOS.unmountComponentAtNodeAndRemoveContainer"
args:@[self.reactTag]];
[self invalidate];
}
#pragma mark - RCTInvalidating
- (BOOL)isValid
{
return [_bridge isValid];
}
- (void)invalidate
{
// Clear view
[self.subviews makeObjectsPerformSelector:@selector(removeFromSuperview)];
[self removeGestureRecognizer:_touchHandler];
[_touchHandler invalidate];
[_executor invalidate];
// TODO: eventually we'll want to be able to share the bridge between
// multiple rootviews, in which case we'll need to move this elsewhere
[_bridge invalidate];
}
#pragma mark Bundle loading
- (void)bundleFinishedLoading:(NSError *)error
{
if (error != nil) {
@@ -137,19 +157,12 @@ static Class _globalExecutorClass;
- (void)loadBundle
{
// Clear view
[self.subviews makeObjectsPerformSelector:@selector(removeFromSuperview)];
[self invalidate];
if (!_scriptURL) {
return;
}
// Clean up
[self removeGestureRecognizer:_touchHandler];
[_touchHandler invalidate];
[_executor invalidate];
[_bridge invalidate];
// Choose local executor if specified, followed by global, followed by default
_executor = [[_executorClass ?: _globalExecutorClass ?: [RCTContextExecutor class] alloc] init];
_bridge = [[RCTBridge alloc] initWithExecutor:_executor moduleProvider:_moduleProvider];
@@ -209,6 +222,9 @@ static Class _globalExecutorClass;
[self bundleFinishedLoading:error];
return;
}
if (!_bridge.isValid) {
return; // Bridge was invalidated in the meanwhile
}
// Success!
RCTSourceCode *sourceCodeModule = _bridge.modules[NSStringFromClass([RCTSourceCode class])];
@@ -217,7 +233,9 @@ static Class _globalExecutorClass;
[_bridge enqueueApplicationScript:rawText url:_scriptURL onComplete:^(NSError *error) {
dispatch_async(dispatch_get_main_queue(), ^{
[self bundleFinishedLoading:error];
if (_bridge.isValid) {
[self bundleFinishedLoading:error];
}
});
}];