react-native-netinfo: Listener randomly not triggered when turning on/off wifi or airplane mode
Environment
System: OS: macOS 11.6 CPU: (8) x64 Apple M1 Memory: 17.72 MB / 16.00 GB Shell: 5.8 - /bin/zsh Binaries: Node: 12.5.0 - ~/.nvm/versions/node/v12.5.0/bin/node Yarn: 1.22.10 - ~/.nvm/versions/node/v12.5.0/bin/yarn npm: 6.9.0 - ~/.nvm/versions/node/v12.5.0/bin/npm Watchman: 2021.08.30.00 - /opt/homebrew/bin/watchman Managers: CocoaPods: 1.11.0 - /opt/homebrew/bin/pod SDKs: iOS SDK: Platforms: DriverKit 21.0.1, iOS 15.0, macOS 12.0, tvOS 15.0, watchOS 8.0 Android SDK: Not Found IDEs: Android Studio: 2020.3 AI-203.7717.56.2031.7784292 Xcode: 13.1/13A1030d - /usr/bin/xcodebuild Languages: Java: 1.8.0_144 - /usr/bin/javac Python: 2.7.16 - /usr/bin/python npmPackages: @react-native-community/cli: Not Found react: 16.13.1 => 16.13.1 react-native: 0.63.3 => 0.63.3 react-native-macos: Not Found npmGlobalPackages: react-native: Not Found
Platforms
Android
Versions
- Android: 12
- iOS:
- react-native-netinfo: 7.1.2
- react-native: 0.63.3
- react: 16.13.1
Description
When only wifi connected, the network change listener is randomly not triggered when turning on/off wifi or airplane mode.
Reproducible Demo
componentDidMount() {
this.netListenerUnsub = NetInfo.addEventListener(this.handleNetworkChange);
}
handleNetworkChange = (state: NetInfoState) => {
const { AppActions } = this.props;
console.log('network state changed', state);
AppActions.setNetwork(state.isConnected);
};
turn on/off wifi or airplane mode.
About this issue
- Original URL
- State: closed
- Created 3 years ago
- Reactions: 3
- Comments: 24 (18 by maintainers)
Commits related to this issue
- Test a possible fix for #542 For review. — committed to cristianoccazinsp/react-native-netinfo by cristianocca 3 years ago
- fix(android): try async state fetch as stale state workaround (#547) * Test a possible fix for #542 For review. * Combine 6.2.0 and 6.2.1 fixes into one. Co-authored-by: Cristiano Coelho <cristi... — committed to react-native-netinfo/react-native-netinfo by cristianoccazinsp 3 years ago
- chore(release): 7.1.4 [skip ci] ## [7.1.4](https://github.com/react-native-netinfo/react-native-netinfo/compare/v7.1.3...v7.1.4) (2021-12-07) ### Bug Fixes * **android:** try async state fetch as s... — committed to react-native-netinfo/react-native-netinfo by semantic-release-bot 3 years ago
It’s what I described above. 7.1.6 added a change that will only work from RN 0.65 and above.
@mikehardy @HatCloud thoughts on changing https://github.com/react-native-netinfo/react-native-netinfo/pull/548 so it works for all RN versions?
@CptMaumau can you test if the changes here resolve the issue for you? https://github.com/cristianoccazinsp/react-native-netinfo/tree/android-fix