deprecate some usage of NetInfo
Reviewed By: wwjholmes Differential Revision: D5493891 fbshipit-source-id: f86f034294f3fd07a535d2856ca6c7d4e2eb7824
This commit is contained in:
parent
aadeff032f
commit
bca825ee50
|
@ -59,21 +59,25 @@ type ConnectivityStateAndroid = $Enum<{
|
||||||
|
|
||||||
const _subscriptions = new Map();
|
const _subscriptions = new Map();
|
||||||
|
|
||||||
let _isConnected;
|
let _isConnectedDeprecated;
|
||||||
if (Platform.OS === 'ios') {
|
if (Platform.OS === 'ios') {
|
||||||
_isConnected = function(
|
_isConnectedDeprecated = function(
|
||||||
reachability: ReachabilityStateIOS,
|
reachability: ReachabilityStateIOS,
|
||||||
): bool {
|
): bool {
|
||||||
return reachability !== 'none' && reachability !== 'unknown';
|
return reachability !== 'none' && reachability !== 'unknown';
|
||||||
};
|
};
|
||||||
} else if (Platform.OS === 'android') {
|
} else if (Platform.OS === 'android') {
|
||||||
_isConnected = function(
|
_isConnectedDeprecated = function(
|
||||||
connectionType: ConnectivityStateAndroid,
|
connectionType: ConnectivityStateAndroid,
|
||||||
): bool {
|
): bool {
|
||||||
return connectionType !== 'NONE' && connectionType !== 'UNKNOWN';
|
return connectionType !== 'NONE' && connectionType !== 'UNKNOWN';
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function _isConnected(connection) {
|
||||||
|
return connection.type !== 'none' && connection.type !== 'unknown';
|
||||||
|
}
|
||||||
|
|
||||||
const _isConnectedSubscriptions = new Map();
|
const _isConnectedSubscriptions = new Map();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -290,7 +294,11 @@ const NetInfo = {
|
||||||
handler: Function
|
handler: Function
|
||||||
): {remove: () => void} {
|
): {remove: () => void} {
|
||||||
const listener = (connection) => {
|
const listener = (connection) => {
|
||||||
handler(_isConnected(connection));
|
if (eventName === 'change') {
|
||||||
|
handler(_isConnectedDeprecated(connection));
|
||||||
|
} else if (eventName === 'connectionChange') {
|
||||||
|
handler(_isConnected(connection));
|
||||||
|
}
|
||||||
};
|
};
|
||||||
_isConnectedSubscriptions.set(handler, listener);
|
_isConnectedSubscriptions.set(handler, listener);
|
||||||
NetInfo.addEventListener(
|
NetInfo.addEventListener(
|
||||||
|
@ -318,9 +326,7 @@ const NetInfo = {
|
||||||
},
|
},
|
||||||
|
|
||||||
fetch(): Promise<any> {
|
fetch(): Promise<any> {
|
||||||
return NetInfo.fetch().then(
|
return NetInfo.getConnectionInfo().then(_isConnected);
|
||||||
(connection) => _isConnected(connection)
|
|
||||||
);
|
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue