mirror of
https://github.com/zhigang1992/react-native-web.git
synced 2026-01-12 22:51:09 +08: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) {}
|
||||
});
|
||||
|
||||
describe('fetch', () => {
|
||||
test('returns a boolean', done => {
|
||||
NetInfo.isConnected.fetch().then(isConnected => {
|
||||
expect(isConnected).toBe(true);
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('addEventListener', () => {
|
||||
test('throws if the provided "eventType" is not supported', () => {
|
||||
expect(() => NetInfo.isConnected.addEventListener('foo', handler)).toThrow();
|
||||
|
||||
@@ -156,11 +156,6 @@ const NetInfo = {
|
||||
},
|
||||
|
||||
fetch(): Promise<boolean> {
|
||||
console.warn('`fetch` is deprecated. Use `getConnectionInfo` instead.');
|
||||
return NetInfo.isConnected.getConnectionInfo();
|
||||
},
|
||||
|
||||
getConnectionInfo(): Promise<boolean> {
|
||||
return new Promise((resolve, reject) => {
|
||||
try {
|
||||
resolve(window.navigator.onLine);
|
||||
|
||||
@@ -107,9 +107,9 @@ const NetInfoScreen = () => (
|
||||
|
||||
<Section title="Properties">
|
||||
<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={{
|
||||
code: `NetInfo.isConnected.getConnectionInfo().then((isConnected) => {
|
||||
code: `NetInfo.isConnected.fetch().then((isConnected) => {
|
||||
console.log('Connection status:', (isConnected ? 'online' : 'offline'));
|
||||
});`
|
||||
}}
|
||||
|
||||
Reference in New Issue
Block a user