mirror of
https://github.com/zoriya/react-native-web.git
synced 2026-06-07 20:21:25 +00:00
[change] remove NetInfo.isConnected.getConnectionInfo()
React Native doesn't have `NetInfo.isConnected.getConnectionInfo()`. This was incorrectly added to the API while updating the main `NetInfo` API. Close #937
This commit is contained in:
committed by
Nicolas Gallagher
parent
02b6f3ff3c
commit
8b1e6f816f
@@ -37,6 +37,15 @@ describe('apis/NetInfo', () => {
|
|||||||
} catch (e) {}
|
} catch (e) {}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe('fetch', () => {
|
||||||
|
test('returns a boolean', done => {
|
||||||
|
NetInfo.isConnected.fetch().then(isConnected => {
|
||||||
|
expect(isConnected).toBe(true);
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
describe('addEventListener', () => {
|
describe('addEventListener', () => {
|
||||||
test('throws if the provided "eventType" is not supported', () => {
|
test('throws if the provided "eventType" is not supported', () => {
|
||||||
expect(() => NetInfo.isConnected.addEventListener('foo', handler)).toThrow();
|
expect(() => NetInfo.isConnected.addEventListener('foo', handler)).toThrow();
|
||||||
|
|||||||
@@ -156,11 +156,6 @@ const NetInfo = {
|
|||||||
},
|
},
|
||||||
|
|
||||||
fetch(): Promise<boolean> {
|
fetch(): Promise<boolean> {
|
||||||
console.warn('`fetch` is deprecated. Use `getConnectionInfo` instead.');
|
|
||||||
return NetInfo.isConnected.getConnectionInfo();
|
|
||||||
},
|
|
||||||
|
|
||||||
getConnectionInfo(): Promise<boolean> {
|
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
try {
|
try {
|
||||||
resolve(window.navigator.onLine);
|
resolve(window.navigator.onLine);
|
||||||
|
|||||||
@@ -107,9 +107,9 @@ const NetInfoScreen = () => (
|
|||||||
|
|
||||||
<Section title="Properties">
|
<Section title="Properties">
|
||||||
<DocItem
|
<DocItem
|
||||||
description="An object with the same methods as above but the listener receives a boolean which represents the internet connectivity. Use this if you are only interested with whether the device has internet connectivity."
|
description="An object with similar methods as above but the listener receives a boolean which represents the internet connectivity. Use this if you are only interested with whether the device has internet connectivity."
|
||||||
example={{
|
example={{
|
||||||
code: `NetInfo.isConnected.getConnectionInfo().then((isConnected) => {
|
code: `NetInfo.isConnected.fetch().then((isConnected) => {
|
||||||
console.log('Connection status:', (isConnected ? 'online' : 'offline'));
|
console.log('Connection status:', (isConnected ? 'online' : 'offline'));
|
||||||
});`
|
});`
|
||||||
}}
|
}}
|
||||||
|
|||||||
Reference in New Issue
Block a user