fix: android: make sure initial network value is not stale on app startup #553
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Overview
When the app is started with no connectivity (e.g., wifi off or airplane mode), the library currently reports
unknown
andconnected = true
values because network listeners are never called when there's no network info, so all default values are read.After this, we now try to properly set the initial network values on register (similar to what the old broadcast received does and was not carried over to the new implementation.
I've also taken the chance to replace the
Runnable
with a lambda as suggested by the linter.P.S.: no idea why old commits were carried over, I'm sure I branched from master.
Test Plan
Tested on Google Pixel 5 (Android 12, RN 0.66.3)
Steps to test:
NetInfo.fetch()
on mount or similar, type should benone
Test again, but now without airplane mode on startup, to make sure the app still reports connectivity when first started if available.