Skip to content

Proposal: Add reactive NetworkStatusChanged event #2

Description

@victorycodedev

I'd like to contribute reactive network status change support to nativephp/mobile-network.

Currently, Network::status() provides a snapshot of the current network state. The proposed addition would allow applications to react when that state changes, using the native platform APIs:

Android: ConnectivityManager.NetworkCallback
iOS: a persistent NWPathMonitor

The proposed API would be a single NetworkStatusChanged event containing the same status information currently exposed by Network::status():

  • connected
  • type
  • isExpensive
  • isConstrained

The first native observation would establish the baseline without emitting an event. Subsequent meaningful changes, including connection/disconnection, Wi-Fi ↔ cellular, or metered/constrained changes would emit NetworkStatusChanged, with duplicate states suppressed.

I was thinking of making the event package-owned, following the newer plugin pattern:

NativePHP\Network\Events\NetworkStatusChanged
Ideally, the event would implement BroadcastsGlobally, allowing application-wide usage such as:

Event::listen(NetworkStatusChanged::class, function (NetworkStatusChanged $event) { // React to connectivity changes... });

One compatibility issue i noticed while investigating the implementation is that mobile-network currently supports nativephp/mobile ^3.0 || ^4.0, while BroadcastsGlobally is a v4 API.

Would you prefer this feature to target NativePHP v4 and update the package constraint accordingly, or should mobile-network retain v3 compatibility and keep the event component-scoped?

I'm happy to implement this and submit the PR once the preferred direction is clear.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions