Updates from Mon 15 Jun

This commit is contained in:
Tadeu Zagallo 2015-06-15 11:30:56 +01:00
commit 0d00a0e600
8 changed files with 60 additions and 33 deletions

View File

@ -44,6 +44,7 @@ var COMMON_APIS = [
require('./GeolocationExample'), require('./GeolocationExample'),
require('./LayoutExample'), require('./LayoutExample'),
require('./PanResponderExample'), require('./PanResponderExample'),
require('./PointerEventsExample'),
]; ];
if (Platform.OS === 'ios') { if (Platform.OS === 'ios') {
@ -80,7 +81,6 @@ if (Platform.OS === 'ios') {
require('./CameraRollExample.ios'), require('./CameraRollExample.ios'),
require('./LayoutEventsExample'), require('./LayoutEventsExample'),
require('./NetInfoExample'), require('./NetInfoExample'),
require('./PointerEventsExample'),
require('./PushNotificationIOSExample'), require('./PushNotificationIOSExample'),
require('./StatusBarIOSExample'), require('./StatusBarIOSExample'),
require('./TimerExample'), require('./TimerExample'),

View File

@ -11,6 +11,7 @@
*/ */
'use strict'; 'use strict';
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');
@ -140,30 +141,32 @@ type ConnectivityStateAndroid = $Enum<{
* ``` * ```
*/ */
var _subscriptions = {}; var _subscriptions = new Map();
var NetInfo = { var NetInfo = {
addEventListener: function ( addEventListener: function (
eventName: ChangeEventName, eventName: ChangeEventName,
handler: Function handler: Function
): void { ): void {
_subscriptions[String(handler)] = RCTDeviceEventEmitter.addListener( var listener = RCTDeviceEventEmitter.addListener(
DEVICE_REACHABILITY_EVENT, DEVICE_REACHABILITY_EVENT,
(appStateData) => { (appStateData) => {
handler(appStateData.network_reachability); handler(appStateData.network_reachability);
} }
); );
_subscriptions.set(handler, listener);
}, },
removeEventListener: function( removeEventListener: function(
eventName: ChangeEventName, eventName: ChangeEventName,
handler: Function handler: Function
): void { ): void {
if (!_subscriptions[String(handler)]) { var listener = _subscriptions.get(handler);
if (!listener) {
return; return;
} }
_subscriptions[String(handler)].remove(); listener.remove();
_subscriptions[String(handler)] = null; _subscriptions.delete(handler);
}, },
fetch: function(): Promise { fetch: function(): Promise {
@ -197,19 +200,20 @@ if (Platform.OS === 'ios') {
}; };
} }
var _isConnectedSubscriptions = {}; var _isConnectedSubscriptions = new Map();
NetInfo.isConnected = { NetInfo.isConnected = {
addEventListener: function ( addEventListener: function (
eventName: ChangeEventName, eventName: ChangeEventName,
handler: Function handler: Function
): void { ): void {
_isConnectedSubscriptions[String(handler)] = (connection) => { var listener = (connection) => {
handler(_isConnected(connection)); handler(_isConnected(connection));
}; };
_isConnectedSubscriptions.set(handler, listener);
NetInfo.addEventListener( NetInfo.addEventListener(
eventName, eventName,
_isConnectedSubscriptions[String(handler)] listener
); );
}, },
@ -217,10 +221,12 @@ NetInfo.isConnected = {
eventName: ChangeEventName, eventName: ChangeEventName,
handler: Function handler: Function
): void { ): void {
var listener = _isConnectedSubscriptions.get(handler);
NetInfo.removeEventListener( NetInfo.removeEventListener(
eventName, eventName,
_isConnectedSubscriptions[String(handler)] listener
); );
_isConnectedSubscriptions.delete(handler);
}, },
fetch: function(): Promise { fetch: function(): Promise {

View File

@ -79,6 +79,9 @@ static css_dim_t RCTMeasure(void *context, float width)
- (NSTextStorage *)buildTextStorageForWidth:(CGFloat)width - (NSTextStorage *)buildTextStorageForWidth:(CGFloat)width
{ {
UIEdgeInsets padding = self.paddingAsInsets;
width -= (padding.left + padding.right);
if (_cachedTextStorage && width == _cachedTextStorageWidth) { if (_cachedTextStorage && width == _cachedTextStorageWidth) {
return _cachedTextStorage; return _cachedTextStorage;
} }
@ -92,16 +95,13 @@ static css_dim_t RCTMeasure(void *context, float width)
textContainer.lineFragmentPadding = 0.0; textContainer.lineFragmentPadding = 0.0;
textContainer.lineBreakMode = _numberOfLines > 0 ? NSLineBreakByTruncatingTail : NSLineBreakByClipping; textContainer.lineBreakMode = _numberOfLines > 0 ? NSLineBreakByTruncatingTail : NSLineBreakByClipping;
textContainer.maximumNumberOfLines = _numberOfLines; textContainer.maximumNumberOfLines = _numberOfLines;
UIEdgeInsets padding = self.paddingAsInsets;
width -= (padding.left + padding.right);
textContainer.size = (CGSize){isnan(width) ? CGFLOAT_MAX : width, CGFLOAT_MAX}; textContainer.size = (CGSize){isnan(width) ? CGFLOAT_MAX : width, CGFLOAT_MAX};
[layoutManager addTextContainer:textContainer]; [layoutManager addTextContainer:textContainer];
[layoutManager ensureLayoutForTextContainer:textContainer]; [layoutManager ensureLayoutForTextContainer:textContainer];
_cachedTextStorage = textStorage;
_cachedTextStorageWidth = width; _cachedTextStorageWidth = width;
_cachedTextStorage = textStorage;
return textStorage; return textStorage;
} }

View File

@ -185,6 +185,15 @@ RCT_EXPORT_MODULE()
} }
- (void)executeBlockOnJavaScriptQueue:(dispatch_block_t)block - (void)executeBlockOnJavaScriptQueue:(dispatch_block_t)block
{
if ([NSThread isMainThread]) {
block();
} else {
dispatch_async(dispatch_get_main_queue(), block);
}
}
- (void)executeAsyncBlockOnJavaScriptQueue:(dispatch_block_t)block
{ {
dispatch_async(dispatch_get_main_queue(), block); dispatch_async(dispatch_get_main_queue(), block);
} }

View File

@ -171,7 +171,22 @@ void _RCTLogFormat(
// Log to red box // Log to red box
if (level >= RCTLOG_REDBOX_LEVEL) { if (level >= RCTLOG_REDBOX_LEVEL) {
[[RCTRedBox sharedInstance] showErrorMessage:message]; NSArray *stackSymbols = [NSThread callStackSymbols];
NSMutableArray *stack = [NSMutableArray arrayWithCapacity:(stackSymbols.count - 1)];
[stackSymbols enumerateObjectsUsingBlock:^(NSString *frameSymbols, NSUInteger idx, BOOL *stop) {
if (idx != 0) { // don't include the current frame
NSString *address = [[frameSymbols componentsSeparatedByString:@"0x"][1] componentsSeparatedByString:@" "][0];
NSRange addressRange = [frameSymbols rangeOfString:address];
NSString *methodName = [frameSymbols substringFromIndex:(addressRange.location + addressRange.length + 1)];
if (idx == 1) {
NSString *file = [[@(fileName) componentsSeparatedByString:@"/"] lastObject];
stack[0] = @{@"methodName": methodName, @"file": file, @"lineNumber": @(lineNumber)};
} else {
stack[idx - 1] = @{@"methodName": methodName};
}
}
}];
[[RCTRedBox sharedInstance] showErrorMessage:message withStack:stack];
} }
// Log to JS executor // Log to JS executor

View File

@ -182,25 +182,19 @@ RCT_EXPORT_MODULE()
[_webView loadHTMLString:runScript baseURL:url]; [_webView loadHTMLString:runScript baseURL:url];
} }
/**
* In order to avoid `UIWebView` thread locks, all JS executions should be
* performed outside of the event loop that notifies the `UIWebViewDelegate`
* that the page has loaded. This is only an issue with the remote debug mode of
* `UIWebView`. For a production `UIWebView` deployment, this delay is
* unnecessary and possibly harmful (or helpful?)
*
* The delay might not be needed as soon as the following change lands into
* iOS7. (Review the patch linked here and search for "crash"
* https://bugs.webkit.org/show_bug.cgi?id=125746).
*/
- (void)executeBlockOnJavaScriptQueue:(dispatch_block_t)block - (void)executeBlockOnJavaScriptQueue:(dispatch_block_t)block
{ {
dispatch_time_t when = dispatch_time(DISPATCH_TIME_NOW, NSEC_PER_MSEC);
dispatch_after(when, dispatch_get_main_queue(), ^{ if ([NSThread isMainThread]) {
RCTAssertMainThread();
block(); block();
}); } else {
dispatch_async(dispatch_get_main_queue(), block);
}
}
- (void)executeAsyncBlockOnJavaScriptQueue:(dispatch_block_t)block
{
dispatch_async(dispatch_get_main_queue(), block);
} }
/** /**

View File

@ -182,6 +182,11 @@ RCT_EXPORT_METHOD(createTimer:(NSNumber *)callbackID
NSTimeInterval jsSchedulingOverhead = -jsSchedulingTime.timeIntervalSinceNow; NSTimeInterval jsSchedulingOverhead = -jsSchedulingTime.timeIntervalSinceNow;
if (jsSchedulingOverhead < 0) { if (jsSchedulingOverhead < 0) {
RCTLogWarn(@"jsSchedulingOverhead (%ims) should be positive", (int)(jsSchedulingOverhead * 1000)); RCTLogWarn(@"jsSchedulingOverhead (%ims) should be positive", (int)(jsSchedulingOverhead * 1000));
/**
* Probably debugging on device, set to 0 so we don't ignore the interval
*/
jsSchedulingOverhead = 0;
} }
NSTimeInterval targetTime = jsDuration - jsSchedulingOverhead; NSTimeInterval targetTime = jsDuration - jsSchedulingOverhead;

View File

@ -371,9 +371,7 @@ static NSDictionary *RCTViewConfigForModule(Class managerClass, NSString *viewNa
rootShadowView.frame = frame; rootShadowView.frame = frame;
[rootShadowView updateLayout]; [rootShadowView updateLayout];
RCTViewManagerUIBlock uiBlock = [self uiBlockWithLayoutUpdateForRootView:rootShadowView]; [self batchDidComplete];
[self addUIBlock:uiBlock];
[self flushUIBlocks];
}); });
} }