Skip to content

NetInfo.isConnected.addEventListener: diverging behaviors on Android and iOS #22954

Closed
@josmithua

Description

@josmithua

Environment

  React Native Environment Info:
    System:
      OS: macOS 10.14.2
      CPU: (4) x64 Intel(R) Core(TM) i5-5257U CPU @ 2.70GHz
      Memory: 788.00 MB / 8.00 GB
      Shell: 3.2.57 - /bin/bash
    Binaries:
      Node: 11.4.0 - /usr/local/bin/node
      Yarn: 1.12.3 - /usr/local/bin/yarn
      npm: 6.4.1 - /usr/local/bin/npm
      Watchman: 4.9.0 - /usr/local/bin/watchman
    SDKs:
      iOS SDK:
        Platforms: iOS 12.1, macOS 10.14, tvOS 12.1, watchOS 5.1
      Android SDK:
        API Levels: 20, 25, 26, 27, 28
        Build Tools: 23.0.1, 25.0.1, 25.0.2, 26.0.2, 27.0.2, 27.0.3, 28.0.2, 28.0.3
        System Images: android-25 | Google APIs Intel x86 Atom_64, android-26 | Google APIs Intel x86 Atom, android-28 | Google Play Intel x86 Atom
    IDEs:
      Android Studio: 3.2 AI-181.5540.7.32.5056338
      Xcode: 10.1/10B61 - /usr/bin/xcodebuild
    npmPackages:
      react: ^16.7.0 => 16.7.0
      react-native: 0.57.8 => 0.57.8

Description

#11041
NetInfo.isConnected.addEventListener diverging behaviors on Android and iOS:

  • On Android, when a listener is added, it will not be triggered.
  • However, on iOS, the handler is triggered when it is added.

Solution (?): Make iOS not trigger the handler when it is added, only when the connection changes.

Reproducible Demo

https://snack.expo.io/S1PS-UrzV
Notice Handler triggered: false on Android, but Handler triggered: true for iOS

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions