Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[No QA] Update netinfo to 8.3.0 #8750

Merged
merged 5 commits into from
Apr 26, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 3 additions & 6 deletions __mocks__/@react-native-community/netinfo.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
export default {
configure: () => {},
fetch: () => {},
addEventListener: () => {},
useNetInfo: () => {},
};
import NetInfoMock from '@react-native-community/netinfo/jest/netinfo-mock';

export default NetInfoMock;
6 changes: 3 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
"@react-native-community/cli": "6.2.0",
"@react-native-community/clipboard": "^1.5.1",
"@react-native-community/datetimepicker": "^3.5.2",
"@react-native-community/netinfo": "^8.0.0",
"@react-native-community/netinfo": "^8.3.0",
"@react-native-community/progress-bar-android": "^1.0.4",
"@react-native-community/progress-view": "^1.2.3",
"@react-native-firebase/analytics": "^12.3.0",
Expand Down
15 changes: 6 additions & 9 deletions src/libs/NetworkConnection.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import CONST from '../CONST';
let unsubscribeFromNetInfo;
let unsubscribeFromAppState;
let isOffline = false;
let hasPendingNetworkCheck = true;
let hasPendingNetworkCheck = false;

// Holds all of the callbacks that need to be triggered when the network reconnects
const reconnectionCallbacks = [];
Expand Down Expand Up @@ -73,9 +73,6 @@ function subscribeToNetInfo() {
unsubscribeFromNetInfo = NetInfo.addEventListener((state) => {
Log.info('[NetworkConnection] NetInfo state change', false, state);
setOfflineStatus(state.isInternetReachable === false);

// When internet state is indeterminate a check is already running. Set the flag to prevent duplicate checks
hasPendingNetworkCheck = state.isInternetReachable === null;
});
}

Expand Down Expand Up @@ -113,18 +110,18 @@ function onReconnect(callback) {
reconnectionCallbacks.push(callback);
}

/**
* Refresh NetInfo state.
*/
function recheckNetworkConnection() {
if (hasPendingNetworkCheck) {
return;
}

Log.info('[NetworkConnection] recheck NetInfo');
hasPendingNetworkCheck = true;

if (unsubscribeFromNetInfo) {
unsubscribeFromNetInfo();
}
subscribeToNetInfo();
NetInfo.refresh()
.finally(() => hasPendingNetworkCheck = false);
}

NetworkEvents.onRecheckNeeded(recheckNetworkConnection);
Expand Down