Updates from Mon 1 Jun

This commit is contained in:
Tadeu Zagallo 2015-06-01 12:51:34 +01:00
commit 6e24a71d3d
6 changed files with 29 additions and 31 deletions

View File

@ -74,7 +74,9 @@ var AppRegistry = {
); );
invariant( invariant(
runnables[appKey] && runnables[appKey].run, runnables[appKey] && runnables[appKey].run,
'Application ' + appKey + ' has not been registered.' 'Application ' + appKey + ' has not been registered. This ' +
'is either due to a require() error during initialization ' +
'or failure to call AppRegistry.registerComponent.'
); );
runnables[appKey].run(appParameters); runnables[appKey].run(appParameters);
}, },

View File

@ -60,14 +60,10 @@ var JSTimers = {
var freeIndex = JSTimers._getFreeIndex(); var freeIndex = JSTimers._getFreeIndex();
JSTimersExecution.timerIDs[freeIndex] = newID; JSTimersExecution.timerIDs[freeIndex] = newID;
JSTimersExecution.callbacks[freeIndex] = function() { JSTimersExecution.callbacks[freeIndex] = function() {
var startTime = Date.now(); return func.apply(undefined, args);
var ret = func.apply(undefined, args);
var endTime = Date.now();
RCTTiming.createTimer(newID, Math.max(0, duration - (endTime - startTime)), endTime, false);
return ret;
}; };
JSTimersExecution.types[freeIndex] = JSTimersExecution.Type.setInterval; JSTimersExecution.types[freeIndex] = JSTimersExecution.Type.setInterval;
RCTTiming.createTimer(newID, duration, Date.now(), /** recurring */ false); RCTTiming.createTimer(newID, duration, Date.now(), /** recurring */ true);
return newID; return newID;
}, },

View File

@ -36,6 +36,7 @@ var createReactNativeComponentClass = function(
}; };
Constructor.displayName = viewConfig.uiViewClassName; Constructor.displayName = viewConfig.uiViewClassName;
Constructor.prototype = new ReactNativeBaseComponent(viewConfig); Constructor.prototype = new ReactNativeBaseComponent(viewConfig);
Constructor.prototype.constructor = Constructor;
return Constructor; return Constructor;
}; };

View File

@ -66,7 +66,6 @@
{ {
RCTJavaScriptContext *_context; RCTJavaScriptContext *_context;
NSThread *_javaScriptThread; NSThread *_javaScriptThread;
JSValueRef _undefined;
} }
/** /**
@ -238,9 +237,6 @@ static NSError *RCTNSErrorFromJSError(JSContextRef context, JSValueRef jsError)
JSContextGroupRelease(group); JSContextGroupRelease(group);
} }
// Constant value used for comparison
_undefined = JSValueMakeUndefined(ctx);
strongSelf->_context = [[RCTJavaScriptContext alloc] initWithJSContext:ctx]; strongSelf->_context = [[RCTJavaScriptContext alloc] initWithJSContext:ctx];
[strongSelf _addNativeHook:RCTNativeLoggingHook withName:"nativeLoggingHook"]; [strongSelf _addNativeHook:RCTNativeLoggingHook withName:"nativeLoggingHook"];
[strongSelf _addNativeHook:RCTNoop withName:"noop"]; [strongSelf _addNativeHook:RCTNoop withName:"noop"];
@ -312,7 +308,7 @@ static NSError *RCTNSErrorFromJSError(JSContextRef context, JSValueRef jsError)
JSValueRef requireJSRef = JSObjectGetProperty(contextJSRef, globalObjectJSRef, requireNameJSStringRef, &errorJSRef); JSValueRef requireJSRef = JSObjectGetProperty(contextJSRef, globalObjectJSRef, requireNameJSStringRef, &errorJSRef);
JSStringRelease(requireNameJSStringRef); JSStringRelease(requireNameJSStringRef);
if (requireJSRef != NULL && requireJSRef != _undefined && errorJSRef == NULL) { if (requireJSRef != NULL && !JSValueIsUndefined(contextJSRef, requireJSRef) && errorJSRef == NULL) {
// get module // get module
JSStringRef moduleNameJSStringRef = JSStringCreateWithCFString((__bridge CFStringRef)name); JSStringRef moduleNameJSStringRef = JSStringCreateWithCFString((__bridge CFStringRef)name);

View File

@ -48,17 +48,16 @@ RCT_EXPORT_MODULE()
for (NSString *name in @[UIApplicationDidBecomeActiveNotification, for (NSString *name in @[UIApplicationDidBecomeActiveNotification,
UIApplicationDidEnterBackgroundNotification, UIApplicationDidEnterBackgroundNotification,
UIApplicationDidFinishLaunchingNotification]) { UIApplicationDidFinishLaunchingNotification]) {
[[NSNotificationCenter defaultCenter] addObserver:self [[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(handleAppStateDidChange) selector:@selector(handleAppStateDidChange)
name:name name:name
object:nil]; object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(handleMemoryWarning)
name:UIApplicationDidReceiveMemoryWarningNotification
object:nil];
} }
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(handleMemoryWarning)
name:UIApplicationDidReceiveMemoryWarningNotification
object:nil];
} }
return self; return self;
} }

View File

@ -197,7 +197,8 @@ static UIViewAnimationCurve UIViewAnimationCurveFromRCTAnimationType(RCTAnimatio
NSMutableDictionary *_defaultViews; // Main thread only NSMutableDictionary *_defaultViews; // Main thread only
NSDictionary *_viewManagers; NSDictionary *_viewManagers;
NSDictionary *_viewConfigs; NSDictionary *_viewConfigs;
NSUInteger _rootTag;
NSMutableSet *_bridgeTransactionListeners;
} }
@synthesize bridge = _bridge; @synthesize bridge = _bridge;
@ -263,7 +264,8 @@ static NSDictionary *RCTViewConfigForModule(Class managerClass, NSString *viewNa
// Internal resources // Internal resources
_pendingUIBlocks = [[NSMutableArray alloc] init]; _pendingUIBlocks = [[NSMutableArray alloc] init];
_rootViewTags = [[NSMutableSet alloc] init]; _rootViewTags = [[NSMutableSet alloc] init];
_rootTag = 1;
_bridgeTransactionListeners = [[NSMutableSet alloc] init];
} }
return self; return self;
} }
@ -287,6 +289,7 @@ static NSDictionary *RCTViewConfigForModule(Class managerClass, NSString *viewNa
_rootViewTags = nil; _rootViewTags = nil;
_shadowViewRegistry = nil; _shadowViewRegistry = nil;
_viewRegistry = nil; _viewRegistry = nil;
_bridgeTransactionListeners = nil;
_bridge = nil; _bridge = nil;
[_pendingUIBlocksLock lock]; [_pendingUIBlocksLock lock];
@ -397,6 +400,10 @@ static NSDictionary *RCTViewConfigForModule(Class managerClass, NSString *viewNa
[(id<RCTInvalidating>)subview invalidate]; [(id<RCTInvalidating>)subview invalidate];
} }
registry[subview.reactTag] = nil; registry[subview.reactTag] = nil;
if (registry == _viewRegistry) {
[_bridgeTransactionListeners removeObject:subview];
}
}); });
} }
} }
@ -482,7 +489,6 @@ static NSDictionary *RCTViewConfigForModule(Class managerClass, NSString *viewNa
} }
// Perform layout (possibly animated) // Perform layout (possibly animated)
NSNumber *rootViewTag = rootShadowView.reactTag;
return ^(RCTUIManager *uiManager, RCTSparseArray *viewRegistry) { return ^(RCTUIManager *uiManager, RCTSparseArray *viewRegistry) {
RCTResponseSenderBlock callback = self->_layoutAnimation.callback; RCTResponseSenderBlock callback = self->_layoutAnimation.callback;
__block NSInteger completionsCalled = 0; __block NSInteger completionsCalled = 0;
@ -547,17 +553,11 @@ static NSDictionary *RCTViewConfigForModule(Class managerClass, NSString *viewNa
} }
/** /**
* Enumerate all active (attached to a parent) views and call * TODO(tadeu): Remove it once and for all
* reactBridgeDidFinishTransaction on them if they implement it.
* TODO: this is quite inefficient. If this was handled via the
* ViewManager instead, it could be done more efficiently.
*/ */
UIView *rootView = _viewRegistry[rootViewTag]; for (id<RCTViewNodeProtocol> node in _bridgeTransactionListeners) {
RCTTraverseViewNodes(rootView, ^(id<RCTViewNodeProtocol> view) { [node reactBridgeDidFinishTransaction];
if ([view respondsToSelector:@selector(reactBridgeDidFinishTransaction)]) { }
[view reactBridgeDidFinishTransaction];
}
});
}; };
} }
@ -844,6 +844,10 @@ RCT_EXPORT_METHOD(createView:(NSNumber *)reactTag
view.layer.allowsGroupOpacity = YES; // required for touch handling view.layer.allowsGroupOpacity = YES; // required for touch handling
} }
RCTSetViewProps(props, view, uiManager->_defaultViews[viewName], manager); RCTSetViewProps(props, view, uiManager->_defaultViews[viewName], manager);
if ([view respondsToSelector:@selector(reactBridgeDidFinishTransaction)]) {
[uiManager->_bridgeTransactionListeners addObject:view];
}
} }
viewRegistry[reactTag] = view; viewRegistry[reactTag] = view;
}]; }];