-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
feat: Add Hook to monitor network connectivity status #56609
Conversation
This code is non-functioning currently.
This bridge will be required for the planned JavaScript Hook to monitor connection status.
Provides React Hook for monitoring the network connection status via the bridge to the host app.
This reverts commit a8d3660.
Size Change: 0 B Total Size: 1.72 MB ℹ️ View Unchanged
|
packages/react-native-editor/ios/GutenbergDemo/GutenbergViewController.swift
Outdated
Show resolved
Hide resolved
Semicolon is unnecessary. Co-authored-by: Tanner Stokes <tanner.stokes@automattic.com>
This bridge enables monitoring the connection status on Android.
Allow the Android platform to request the current network connection status.
The Demo editor fails to build without a mocked bridge method.
c075674
to
98b6977
Compare
@@ -185,6 +190,49 @@ export function subscribeOnRedoPressed( callback ) { | |||
return gutenbergBridgeEvents.addListener( 'onRedoPressed', callback ); | |||
} | |||
|
|||
export function useIsConnected() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd like to move this useIsConnected
and its related logic into a separate file to improve code comprehension and make testing easier. However, doing so would currently create a cyclic dependency.
After merging this work, I hope to refactor the bridge to avoid cyclic dependencies and enable testing.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I feel we may want to consider adding more detail to this hook's name. In Jetpack, the concept of isConnected refers to a Jetpack site connection. Although it's a separate repo, being more descriptive in the hook name may help avoid confusion, and help also clarify "what" is connected. I had been using isNetworkConnected
in a previous example, and even considered isMobileNetworkConnected
to be extra clear. Open to other perspectives, however. If we do decide to update the name, it can happen in a follow-up PR.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good feedback. I agree we should update the name to more clearly communicate its intent: isNetworkConnected
. I suggest we refactor this in a future PR alongside implementing tests.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks great, and was working well on both host apps during my testing. I left a small note about possibly adding more detail to the name of the hook itself, but it's not a blocker. 🚀
@@ -185,6 +190,49 @@ export function subscribeOnRedoPressed( callback ) { | |||
return gutenbergBridgeEvents.addListener( 'onRedoPressed', callback ); | |||
} | |||
|
|||
export function useIsConnected() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I feel we may want to consider adding more detail to this hook's name. In Jetpack, the concept of isConnected refers to a Jetpack site connection. Although it's a separate repo, being more descriptive in the hook name may help avoid confusion, and help also clarify "what" is connected. I had been using isNetworkConnected
in a previous example, and even considered isMobileNetworkConnected
to be extra clear. Open to other perspectives, however. If we do decide to update the name, it can happen in a follow-up PR.
I reverted this work in #56836 to avoid merging bridge changes into the WordPress host apps, as we do not plan to integrate a tagged release before the next WordPress host app release. Introducing bridge changes without a formal tagged release would've disrupted the release process. I'll open another PR to merge this work after the next WordPress host app release (23.9 on Dec 11). |
Related
What?
Add a React Hook for monitoring the network connection status via the bridge to
the host app.
Why?
The network connection status will enable future features improving the UX when
a user's network connection changes, e.g. displaying status indicators.
Fixes wordpress-mobile/gutenberg-mobile#6409.
How?
Add a
useIsConnected
React Hook that invokes bridge methods retrieving andmonitoring the network connection status from the host app. Relying upon the
host app will result in a single source of truth and mitigate conflicting
statuses.
Testing Instructions
Checkout this branch within the
gutenberg-mobile
submodule.Start the Metro server via
npm run start:reset
.Apply the following patch:
Test Diff
Configure the app to load the local Metro server:
LOCAL_GUTENBERG=true bundle exec pod install
.localGutenbergMobilePath
withinlocal-builds.gradle
.Build and run the WordPress app.
Launch the editor and verify the connection status displayed is accurate.
Toggle airplane mode, verify the connection status displayed is accurate.
Testing Instructions for Keyboard
n/a, this internal tool introduces no user-facing changes.
Screenshots or screencast
n/a, this internal tool introduces no visible changes.