chore(NetInfo): fixup NetInfo with latest from upstream module.
This commit is contained in:
Родитель
e3827acd74
Коммит
f4a103fc34
|
@ -12,53 +12,54 @@
|
|||
'use strict';
|
||||
|
||||
const Map = require('Map');
|
||||
const NativeEventEmitter = require('NativeEventEmitter');
|
||||
const NativeModules = require('NativeModules');
|
||||
const Platform = require('Platform');
|
||||
const RCTDeviceEventEmitter = require('RCTDeviceEventEmitter');
|
||||
const RCTNetInfo = NativeModules.NetInfo;
|
||||
const deprecatedCallback = require('deprecatedCallback');
|
||||
|
||||
const NetInfoEventEmitter = new NativeEventEmitter(RCTNetInfo);
|
||||
|
||||
const DEVICE_CONNECTIVITY_EVENT = 'networkStatusDidChange';
|
||||
|
||||
type ChangeEventName = $Enum<{
|
||||
change: string;
|
||||
change: string,
|
||||
}>;
|
||||
|
||||
type ReachabilityStateIOS = $Enum<{
|
||||
cell: string;
|
||||
none: string;
|
||||
unknown: string;
|
||||
wifi: string;
|
||||
cell: string,
|
||||
none: string,
|
||||
unknown: string,
|
||||
wifi: string,
|
||||
}>;
|
||||
|
||||
type ConnectivityStateAndroid = $Enum<{
|
||||
NONE: string;
|
||||
MOBILE: string;
|
||||
WIFI: string;
|
||||
MOBILE_MMS: string;
|
||||
MOBILE_SUPL: string;
|
||||
MOBILE_DUN: string;
|
||||
MOBILE_HIPRI: string;
|
||||
WIMAX: string;
|
||||
BLUETOOTH: string;
|
||||
DUMMY: string;
|
||||
ETHERNET: string;
|
||||
MOBILE_FOTA: string;
|
||||
MOBILE_IMS: string;
|
||||
MOBILE_CBS: string;
|
||||
WIFI_P2P: string;
|
||||
MOBILE_IA: string;
|
||||
MOBILE_EMERGENCY: string;
|
||||
PROXY: string;
|
||||
VPN: string;
|
||||
UNKNOWN: string;
|
||||
NONE: string,
|
||||
MOBILE: string,
|
||||
WIFI: string,
|
||||
MOBILE_MMS: string,
|
||||
MOBILE_SUPL: string,
|
||||
MOBILE_DUN: string,
|
||||
MOBILE_HIPRI: string,
|
||||
WIMAX: string,
|
||||
BLUETOOTH: string,
|
||||
DUMMY: string,
|
||||
ETHERNET: string,
|
||||
MOBILE_FOTA: string,
|
||||
MOBILE_IMS: string,
|
||||
MOBILE_CBS: string,
|
||||
WIFI_P2P: string,
|
||||
MOBILE_IA: string,
|
||||
MOBILE_EMERGENCY: string,
|
||||
PROXY: string,
|
||||
VPN: string,
|
||||
UNKNOWN: string,
|
||||
}>;
|
||||
|
||||
type ConnectivityStateWindows = $Enum<{
|
||||
None: string;
|
||||
LocalAccess: string;
|
||||
ConstrainedInternetAccess: string;
|
||||
InternetAccess: string;
|
||||
None: string,
|
||||
LocalAccess: string,
|
||||
ConstrainedInternetAccess: string,
|
||||
InternetAccess: string,
|
||||
}>;
|
||||
|
||||
const _subscriptions = new Map();
|
||||
|
@ -199,7 +200,7 @@ const NetInfo = {
|
|||
eventName: ChangeEventName,
|
||||
handler: Function
|
||||
): {remove: () => void} {
|
||||
const listener = RCTDeviceEventEmitter.addListener(
|
||||
const listener = NetInfoEventEmitter.addListener(
|
||||
DEVICE_CONNECTIVITY_EVENT,
|
||||
(appStateData) => {
|
||||
handler(appStateData.network_info);
|
||||
|
@ -230,7 +231,7 @@ const NetInfo = {
|
|||
* Returns a promise that resolves with one of the connectivity types listed
|
||||
* above.
|
||||
*/
|
||||
fetch(): Promise {
|
||||
fetch(): Promise<any> {
|
||||
return RCTNetInfo.getCurrentConnectivity().then(resp => resp.network_info);
|
||||
},
|
||||
|
||||
|
@ -271,21 +272,18 @@ const NetInfo = {
|
|||
_isConnectedSubscriptions.delete(handler);
|
||||
},
|
||||
|
||||
fetch(): Promise {
|
||||
fetch(): Promise<any> {
|
||||
return NetInfo.fetch().then(
|
||||
(connection) => _isConnected(connection)
|
||||
);
|
||||
},
|
||||
},
|
||||
|
||||
isConnectionExpensive(): Promise {
|
||||
return deprecatedCallback(
|
||||
Platform.OS === 'android' ? RCTNetInfo.isConnectionMetered() : Promise.reject(new Error('Currently not supported on iOS')),
|
||||
Array.prototype.slice.call(arguments),
|
||||
'single-callback-value-first',
|
||||
'NetInfo.isConnectionMetered(callback) is deprecated. Use the returned Promise instead.'
|
||||
isConnectionExpensive(): Promise<boolean> {
|
||||
return (
|
||||
Platform.OS === 'android' ? RCTNetInfo.isConnectionMetered() : Promise.reject(new Error('Currently not supported on iOS'))
|
||||
);
|
||||
},
|
||||
};
|
||||
|
||||
module.exports = NetInfo;
|
||||
module.exports = NetInfo;
|
Загрузка…
Ссылка в новой задаче