Skip to content

Commit 0c8de68

Browse files
committed
Merge pull request #1630 from tadeuzagallo/Update_Mon_15_Jun
Update mon 15 jun
2 parents 9dc9648 + 0d00a0e commit 0c8de68

File tree

8 files changed

+60
-33
lines changed

8 files changed

+60
-33
lines changed

Examples/UIExplorer/UIExplorerList.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ var COMMON_APIS = [
4444
require('./GeolocationExample'),
4545
require('./LayoutExample'),
4646
require('./PanResponderExample'),
47+
require('./PointerEventsExample'),
4748
];
4849

4950
if (Platform.OS === 'ios') {
@@ -80,7 +81,6 @@ if (Platform.OS === 'ios') {
8081
require('./CameraRollExample.ios'),
8182
require('./LayoutEventsExample'),
8283
require('./NetInfoExample'),
83-
require('./PointerEventsExample'),
8484
require('./PushNotificationIOSExample'),
8585
require('./StatusBarIOSExample'),
8686
require('./TimerExample'),

Libraries/Network/NetInfo.js

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
*/
1212
'use strict';
1313

14+
var Map = require('Map');
1415
var NativeModules = require('NativeModules');
1516
var Platform = require('Platform');
1617
var RCTDeviceEventEmitter = require('RCTDeviceEventEmitter');
@@ -140,30 +141,32 @@ type ConnectivityStateAndroid = $Enum<{
140141
* ```
141142
*/
142143

143-
var _subscriptions = {};
144+
var _subscriptions = new Map();
144145

145146
var NetInfo = {
146147
addEventListener: function (
147148
eventName: ChangeEventName,
148149
handler: Function
149150
): void {
150-
_subscriptions[String(handler)] = RCTDeviceEventEmitter.addListener(
151+
var listener = RCTDeviceEventEmitter.addListener(
151152
DEVICE_REACHABILITY_EVENT,
152153
(appStateData) => {
153154
handler(appStateData.network_reachability);
154155
}
155156
);
157+
_subscriptions.set(handler, listener);
156158
},
157159

158160
removeEventListener: function(
159161
eventName: ChangeEventName,
160162
handler: Function
161163
): void {
162-
if (!_subscriptions[String(handler)]) {
164+
var listener = _subscriptions.get(handler);
165+
if (!listener) {
163166
return;
164167
}
165-
_subscriptions[String(handler)].remove();
166-
_subscriptions[String(handler)] = null;
168+
listener.remove();
169+
_subscriptions.delete(handler);
167170
},
168171

169172
fetch: function(): Promise {
@@ -197,30 +200,33 @@ if (Platform.OS === 'ios') {
197200
};
198201
}
199202

200-
var _isConnectedSubscriptions = {};
203+
var _isConnectedSubscriptions = new Map();
201204

202205
NetInfo.isConnected = {
203206
addEventListener: function (
204207
eventName: ChangeEventName,
205208
handler: Function
206209
): void {
207-
_isConnectedSubscriptions[String(handler)] = (connection) => {
210+
var listener = (connection) => {
208211
handler(_isConnected(connection));
209212
};
213+
_isConnectedSubscriptions.set(handler, listener);
210214
NetInfo.addEventListener(
211215
eventName,
212-
_isConnectedSubscriptions[String(handler)]
216+
listener
213217
);
214218
},
215219

216220
removeEventListener: function(
217221
eventName: ChangeEventName,
218222
handler: Function
219223
): void {
224+
var listener = _isConnectedSubscriptions.get(handler);
220225
NetInfo.removeEventListener(
221226
eventName,
222-
_isConnectedSubscriptions[String(handler)]
227+
listener
223228
);
229+
_isConnectedSubscriptions.delete(handler);
224230
},
225231

226232
fetch: function(): Promise {

Libraries/Text/RCTShadowText.m

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,9 @@ - (void)applyLayoutNode:(css_node_t *)node
7979

8080
- (NSTextStorage *)buildTextStorageForWidth:(CGFloat)width
8181
{
82+
UIEdgeInsets padding = self.paddingAsInsets;
83+
width -= (padding.left + padding.right);
84+
8285
if (_cachedTextStorage && width == _cachedTextStorageWidth) {
8386
return _cachedTextStorage;
8487
}
@@ -92,16 +95,13 @@ - (NSTextStorage *)buildTextStorageForWidth:(CGFloat)width
9295
textContainer.lineFragmentPadding = 0.0;
9396
textContainer.lineBreakMode = _numberOfLines > 0 ? NSLineBreakByTruncatingTail : NSLineBreakByClipping;
9497
textContainer.maximumNumberOfLines = _numberOfLines;
95-
96-
UIEdgeInsets padding = self.paddingAsInsets;
97-
width -= (padding.left + padding.right);
9898
textContainer.size = (CGSize){isnan(width) ? CGFLOAT_MAX : width, CGFLOAT_MAX};
9999

100100
[layoutManager addTextContainer:textContainer];
101101
[layoutManager ensureLayoutForTextContainer:textContainer];
102102

103-
_cachedTextStorage = textStorage;
104103
_cachedTextStorageWidth = width;
104+
_cachedTextStorage = textStorage;
105105

106106
return textStorage;
107107
}

Libraries/WebSocket/RCTWebSocketExecutor.m

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,15 @@ - (void)injectJSONText:(NSString *)script asGlobalObjectNamed:(NSString *)object
185185
}
186186

187187
- (void)executeBlockOnJavaScriptQueue:(dispatch_block_t)block
188+
{
189+
if ([NSThread isMainThread]) {
190+
block();
191+
} else {
192+
dispatch_async(dispatch_get_main_queue(), block);
193+
}
194+
}
195+
196+
- (void)executeAsyncBlockOnJavaScriptQueue:(dispatch_block_t)block
188197
{
189198
dispatch_async(dispatch_get_main_queue(), block);
190199
}

React/Base/RCTLog.m

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,22 @@ void _RCTLogFormat(
171171

172172
// Log to red box
173173
if (level >= RCTLOG_REDBOX_LEVEL) {
174-
[[RCTRedBox sharedInstance] showErrorMessage:message];
174+
NSArray *stackSymbols = [NSThread callStackSymbols];
175+
NSMutableArray *stack = [NSMutableArray arrayWithCapacity:(stackSymbols.count - 1)];
176+
[stackSymbols enumerateObjectsUsingBlock:^(NSString *frameSymbols, NSUInteger idx, BOOL *stop) {
177+
if (idx != 0) { // don't include the current frame
178+
NSString *address = [[frameSymbols componentsSeparatedByString:@"0x"][1] componentsSeparatedByString:@" "][0];
179+
NSRange addressRange = [frameSymbols rangeOfString:address];
180+
NSString *methodName = [frameSymbols substringFromIndex:(addressRange.location + addressRange.length + 1)];
181+
if (idx == 1) {
182+
NSString *file = [[@(fileName) componentsSeparatedByString:@"/"] lastObject];
183+
stack[0] = @{@"methodName": methodName, @"file": file, @"lineNumber": @(lineNumber)};
184+
} else {
185+
stack[idx - 1] = @{@"methodName": methodName};
186+
}
187+
}
188+
}];
189+
[[RCTRedBox sharedInstance] showErrorMessage:message withStack:stack];
175190
}
176191

177192
// Log to JS executor

React/Executors/RCTWebViewExecutor.m

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -182,25 +182,19 @@ - (void)executeApplicationScript:(NSString *)script
182182
[_webView loadHTMLString:runScript baseURL:url];
183183
}
184184

185-
/**
186-
* In order to avoid `UIWebView` thread locks, all JS executions should be
187-
* performed outside of the event loop that notifies the `UIWebViewDelegate`
188-
* that the page has loaded. This is only an issue with the remote debug mode of
189-
* `UIWebView`. For a production `UIWebView` deployment, this delay is
190-
* unnecessary and possibly harmful (or helpful?)
191-
*
192-
* The delay might not be needed as soon as the following change lands into
193-
* iOS7. (Review the patch linked here and search for "crash"
194-
* https://bugs.webkit.org/show_bug.cgi?id=125746).
195-
*/
196185
- (void)executeBlockOnJavaScriptQueue:(dispatch_block_t)block
197186
{
198-
dispatch_time_t when = dispatch_time(DISPATCH_TIME_NOW, NSEC_PER_MSEC);
199187

200-
dispatch_after(when, dispatch_get_main_queue(), ^{
201-
RCTAssertMainThread();
188+
if ([NSThread isMainThread]) {
202189
block();
203-
});
190+
} else {
191+
dispatch_async(dispatch_get_main_queue(), block);
192+
}
193+
}
194+
195+
- (void)executeAsyncBlockOnJavaScriptQueue:(dispatch_block_t)block
196+
{
197+
dispatch_async(dispatch_get_main_queue(), block);
204198
}
205199

206200
/**

React/Modules/RCTTiming.m

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,11 @@ - (void)didUpdateFrame:(RCTFrameUpdate *)update
182182
NSTimeInterval jsSchedulingOverhead = -jsSchedulingTime.timeIntervalSinceNow;
183183
if (jsSchedulingOverhead < 0) {
184184
RCTLogWarn(@"jsSchedulingOverhead (%ims) should be positive", (int)(jsSchedulingOverhead * 1000));
185+
186+
/**
187+
* Probably debugging on device, set to 0 so we don't ignore the interval
188+
*/
189+
jsSchedulingOverhead = 0;
185190
}
186191

187192
NSTimeInterval targetTime = jsDuration - jsSchedulingOverhead;

React/Modules/RCTUIManager.m

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -371,9 +371,7 @@ - (void)setFrame:(CGRect)frame forRootView:(UIView *)rootView
371371
rootShadowView.frame = frame;
372372
[rootShadowView updateLayout];
373373

374-
RCTViewManagerUIBlock uiBlock = [self uiBlockWithLayoutUpdateForRootView:rootShadowView];
375-
[self addUIBlock:uiBlock];
376-
[self flushUIBlocks];
374+
[self batchDidComplete];
377375
});
378376
}
379377

0 commit comments

Comments
 (0)