mirror of
https://github.com/zhigang1992/react-native.git
synced 2026-03-27 22:54:46 +08:00
Updates from Mon 15 Jun
This commit is contained in:
@@ -11,6 +11,7 @@
|
||||
*/
|
||||
'use strict';
|
||||
|
||||
var Map = require('Map');
|
||||
var NativeModules = require('NativeModules');
|
||||
var Platform = require('Platform');
|
||||
var RCTDeviceEventEmitter = require('RCTDeviceEventEmitter');
|
||||
@@ -140,30 +141,32 @@ type ConnectivityStateAndroid = $Enum<{
|
||||
* ```
|
||||
*/
|
||||
|
||||
var _subscriptions = {};
|
||||
var _subscriptions = new Map();
|
||||
|
||||
var NetInfo = {
|
||||
addEventListener: function (
|
||||
eventName: ChangeEventName,
|
||||
handler: Function
|
||||
): void {
|
||||
_subscriptions[String(handler)] = RCTDeviceEventEmitter.addListener(
|
||||
var listener = RCTDeviceEventEmitter.addListener(
|
||||
DEVICE_REACHABILITY_EVENT,
|
||||
(appStateData) => {
|
||||
handler(appStateData.network_reachability);
|
||||
}
|
||||
);
|
||||
_subscriptions.set(handler, listener);
|
||||
},
|
||||
|
||||
removeEventListener: function(
|
||||
eventName: ChangeEventName,
|
||||
handler: Function
|
||||
): void {
|
||||
if (!_subscriptions[String(handler)]) {
|
||||
var listener = _subscriptions.get(handler);
|
||||
if (!listener) {
|
||||
return;
|
||||
}
|
||||
_subscriptions[String(handler)].remove();
|
||||
_subscriptions[String(handler)] = null;
|
||||
listener.remove();
|
||||
_subscriptions.delete(handler);
|
||||
},
|
||||
|
||||
fetch: function(): Promise {
|
||||
@@ -197,19 +200,20 @@ if (Platform.OS === 'ios') {
|
||||
};
|
||||
}
|
||||
|
||||
var _isConnectedSubscriptions = {};
|
||||
var _isConnectedSubscriptions = new Map();
|
||||
|
||||
NetInfo.isConnected = {
|
||||
addEventListener: function (
|
||||
eventName: ChangeEventName,
|
||||
handler: Function
|
||||
): void {
|
||||
_isConnectedSubscriptions[String(handler)] = (connection) => {
|
||||
var listener = (connection) => {
|
||||
handler(_isConnected(connection));
|
||||
};
|
||||
_isConnectedSubscriptions.set(handler, listener);
|
||||
NetInfo.addEventListener(
|
||||
eventName,
|
||||
_isConnectedSubscriptions[String(handler)]
|
||||
listener
|
||||
);
|
||||
},
|
||||
|
||||
@@ -217,10 +221,12 @@ NetInfo.isConnected = {
|
||||
eventName: ChangeEventName,
|
||||
handler: Function
|
||||
): void {
|
||||
var listener = _isConnectedSubscriptions.get(handler);
|
||||
NetInfo.removeEventListener(
|
||||
eventName,
|
||||
_isConnectedSubscriptions[String(handler)]
|
||||
listener
|
||||
);
|
||||
_isConnectedSubscriptions.delete(handler);
|
||||
},
|
||||
|
||||
fetch: function(): Promise {
|
||||
|
||||
@@ -79,6 +79,9 @@ static css_dim_t RCTMeasure(void *context, float width)
|
||||
|
||||
- (NSTextStorage *)buildTextStorageForWidth:(CGFloat)width
|
||||
{
|
||||
UIEdgeInsets padding = self.paddingAsInsets;
|
||||
width -= (padding.left + padding.right);
|
||||
|
||||
if (_cachedTextStorage && width == _cachedTextStorageWidth) {
|
||||
return _cachedTextStorage;
|
||||
}
|
||||
@@ -92,16 +95,13 @@ static css_dim_t RCTMeasure(void *context, float width)
|
||||
textContainer.lineFragmentPadding = 0.0;
|
||||
textContainer.lineBreakMode = _numberOfLines > 0 ? NSLineBreakByTruncatingTail : NSLineBreakByClipping;
|
||||
textContainer.maximumNumberOfLines = _numberOfLines;
|
||||
|
||||
UIEdgeInsets padding = self.paddingAsInsets;
|
||||
width -= (padding.left + padding.right);
|
||||
textContainer.size = (CGSize){isnan(width) ? CGFLOAT_MAX : width, CGFLOAT_MAX};
|
||||
|
||||
[layoutManager addTextContainer:textContainer];
|
||||
[layoutManager ensureLayoutForTextContainer:textContainer];
|
||||
|
||||
_cachedTextStorage = textStorage;
|
||||
_cachedTextStorageWidth = width;
|
||||
_cachedTextStorage = textStorage;
|
||||
|
||||
return textStorage;
|
||||
}
|
||||
|
||||
@@ -185,6 +185,15 @@ RCT_EXPORT_MODULE()
|
||||
}
|
||||
|
||||
- (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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user