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

notify subscriptions after refresh #630

Merged
merged 1 commit into from Oct 5, 2022

Conversation

sdandois
Copy link
Contributor

@sdandois sdandois commented Oct 3, 2022

Overview

Related to #591 #557

I've experienced problems with useNetInfo and location permissions. I'm using Android 11 and my app only has location permissions when the app is in foreground.

If the network changes while the app is in background bssid and ssid values are not being reported (or obfuscated). When the app comes back to foreground, no events are being triggered.

To handle that case, I've triggered NetInfo.refresh() when the appState becomes active again. However, this doesn't update the useNetInfo state. To force the update, I've added the event dispatch after updating _lastState.

Test Plan

  1. Run on a phone with Android 11 (10 I think is the same thing).

  2. Add this code to see updates to netInfo.

const netInfo = useNetInfo();
useEffect(() => {
  console.log('net info ssid is updated', netInfo?.details?.ssid) 
  

}, [netInfo?.details?.ssid])
  1. Go to settings and change to another wifi network and wait around 10 seconds.

  2. Net info ssid is updated with null

  3. Go back to the app: No changes are triggered.

  4. Add:

  const appState = useAppState();
  useEffect(() => {
    if (appState === 'active') {
      NetInfo.refresh();
    }
  }, [appState]);

With this code and my changes after coming back to the app, the ssid and bssid are updated.

Details

"@react-native-community/netinfo@": "9.3.2"
react-native: 0.67.3

SO Android 11.

@sdandois
Copy link
Contributor Author

sdandois commented Oct 5, 2022

Also related to #538 . @mikehardy, I hope this change is suitable for you.

Copy link
Contributor

@mikehardy mikehardy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems very reasonable, and the test case you laid out is excellent - thank you!

@mikehardy mikehardy added the pending merge A PR that will be merged shortly, waiting for CI or final comment label Oct 5, 2022
@mikehardy mikehardy merged commit 67c88be into react-native-netinfo:master Oct 5, 2022
@sdandois
Copy link
Contributor Author

sdandois commented Oct 5, 2022

This seems very reasonable, and the test case you laid out is excellent - thank you!

Thank you for maintaining the library :)

github-actions bot pushed a commit that referenced this pull request Oct 5, 2022
## [9.3.4](v9.3.3...v9.3.4) (2022-10-05)

### Bug Fixes

* notify subscriptions after state changes ([#630](#630)) ([67c88be](67c88be))
@matt-oakes
Copy link
Collaborator

🎉 This PR is included in version 9.3.4 🎉

The release is available on:

Your semantic-release bot 📦🚀

@mikehardy mikehardy removed the pending merge A PR that will be merged shortly, waiting for CI or final comment label Nov 1, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants