Giter Site home page Giter Site logo

react-native-netinfo / react-native-netinfo Goto Github PK

View Code? Open in Web Editor NEW
1.9K 20.0 390.0 2.13 MB

React Native Network Info API for Android & iOS

License: MIT License

Java 25.63% JavaScript 5.17% Objective-C 13.35% Ruby 1.06% TypeScript 43.71% HTML 0.15% Shell 0.88% C++ 9.82% C 0.22%
react-native network networking

react-native-netinfo's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

react-native-netinfo's Issues

NetInfo.getConnectionInfo() return unknown for android

I am using the following code to get the connection info but it return unknown for android:

componentDidMount() { NetInfo.getConnectionInfo().then(connectionInfo => { console.log("Connection type", connectionInfo.type); console.log("Connection effective type", connectionInfo.effectiveType); }); }

React Native Version: 0.59.0

NativeModule.RNCNetInfo is null

Environment

React Native Environment Info:
    System:
      OS: macOS 10.14.3
      CPU: (4) x64 Intel(R) Core(TM) i5-7360U CPU @ 2.30GHz
      Memory: 350.61 MB / 16.00 GB
      Shell: 5.3 - /bin/zsh
    Binaries:
      Node: 11.12.0 - /usr/local/bin/node
      Yarn: 1.12.3 - /usr/local/bin/yarn
      npm: 6.7.0 - /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: 19, 21, 23, 25, 26, 27, 28
        Build Tools: 23.0.1, 25.0.2, 26.0.3, 27.0.3, 28.0.3
        System Images: android-19 | Google APIs ARM EABI v7a, android-21 | Google APIs ARM EABI v7a, android-25 | Google APIs Intel x86 Atom, android-26 | Google APIs Intel x86 Atom, android-26 | Google APIs Intel x86 Atom_64, android-27 | Google Play Intel x86 Atom
    IDEs:
      Android Studio: 2.3 AI-162.4069837
      Xcode: 10.1/10B61 - /usr/bin/xcodebuild
    npmPackages:
      react: 16.8.3 => 16.8.3 
      react-native: 0.59.4 => 0.59.4 
    npmGlobalPackages:
      react-native-cli: 2.0.1

Platforms

Versions

  • Android: 7.1.1
  • iOS: 12.1
  • react-native-netinfo: 2.0.1
  • react-native: 0.59.4
  • react: 16.8.3

Description

Just used yarn to add the package, and I am getting this error. I have followed the instructions suggested in the message. I am not using CocoaPods.
Screen Shot 2019-04-14 at 4 34 22 PM

Reproducible Demo

Simply importing the library as described in the README documentation produces the error.

import NetInfo from '@react-native-community/netinfo';

[Android] Package android.support.v4.net does not exist

Environment

React Native Environment Info:
System:
OS: macOS 10.14.4
CPU: (4) x64 Intel(R) Core(TM) i5-5257U CPU @ 2.70GHz
Memory: 37.34 MB / 8.00 GB
Shell: 3.2.57 - /bin/bash
Binaries:
Node: 8.12.0 - ~/.nvm/versions/node/v8.12.0/bin/node
Yarn: 1.9.4 - /usr/local/bin/yarn
npm: 6.4.1 - ~/.nvm/versions/node/v8.12.0/bin/npm
Watchman: 4.9.0 - /usr/local/bin/watchman
SDKs:
iOS SDK:
Platforms: iOS 12.2, macOS 10.14, tvOS 12.2, watchOS 5.2
IDEs:
Android Studio: 3.3 AI-182.5107.16.33.5314842
Xcode: 10.2.1/10E1001 - /usr/bin/xcodebuild
npmPackages:
react: 16.8.6 => 16.8.6
react-native: 0.59.8 => 0.59.8
npmGlobalPackages:
react-native-cli: 2.0.1
react-native-create-library: 3.1.2
react-native-git-upgrade: 0.2.7
react-native-schemes-manager: 1.0.5

Platforms

Android

Versions

  • Android:
  • iOS:
  • react-native-netinfo: 3.2.0
  • react-native: 0.59.8
  • react: 16.8.6

Description

Cannot build react-native run-android
Screen Shot 2019-05-28 at 3 00 25 PM

Reproducible Demo

  • Note:
android.useAndroidX=true
android.enableJetifier=true
classpath 'com.android.tools.build:gradle:3.3.1'
        buildToolsVersion           = "28.0.3"
        minSdkVersion               = 19
        compileSdkVersion           = 28
        targetSdkVersion            = 28
        supportLibVersion           = "28.0.0"

Build Failed in Android

Environment

Environment:
OS: Windows 10
Node: 10.15.3
Yarn: Not Found
npm: 3.10.10
Watchman: Not Found
Xcode: N/A
Android Studio: Version 3.3.0.0 AI-182.5107.16.33.5314842

Packages: (wanted => installed)
react: 16.2.0 => 16.2.0
react-native: 0.52.0 => 0.52.0

Issue

Loading dependency graph, done.
error: bundling failed: SyntaxError in D:\github\markit\node_modules@react-native-community\netinfo\js\index.js: D:/github/markit/node_modules/@react-native-community/netinfo/js/index.js: Unexpected token (42:46)
40 | type IsConnectedHandler = (isConnected: boolean) => void;
41 |

42 | const _subscriptions = new Set();
| ^
43 | const _isConnectedSubscriptions = new Map();
44 |
45 | let _latestNetInfo = null;
DELTA [android, dev] ./index.js ▓▓▓▓▓▓▓▓▓▓░░░░░░ 62.9% (613/773), failed.

Platforms

On Android

Description

I am getting this error on build my android app, help needed.

getConnectionInfo returns wrong info if network state changes while app is "sleeping" in background

Environment

React Native Environment Info:
System:
OS: Windows 10
CPU: (4) x64 Intel(R) Core(TM) i5-3230M CPU @ 2.60GHz
Memory: 6.47 GB / 15.95 GB
Binaries:
Yarn: 1.13.0 - C:\Program Files (x86)\Yarn\bin\yarn.CMD
npm: 6.4.1 - C:\Program Files\nodejs\npm.CMD
IDEs:
Android Studio: Version 3.3.0.0 AI-182.5107.16.33.5314842

Platforms

I'm experiencing the issue on both iOS and Android.

Versions

  • Android: 7.1.2
  • iOS: 12.1.4
  • react-native-netinfo: 1.3.0
  • react-native: 0.59.1
  • react: 16.8.3

Description

If the network state changes while the app is in background, NetInfo.getConnectionInfo() returns the older state until the state changes again with the app in foreground.
A similar issue was opened on 4 Oct 2018 on the react-native repo: facebook/react-native#21476.
I don't know if it's a regression or not.

Reproducible Demo

I call the function when the instrested component mounts:

static getDeviceConnectionInfo = async () => {
    const info = await NetInfo.getConnectionInfo();
    Reactotron.log('G O T   N E T   I N F O', info);
    return info;
}

It returns the correct state. If I disable the WiFi (for example) and re-mount my component (it's a modal that I mount/unmount) the state I get is correct and updated (type === unknown).

Now i put the app in background and I re-enable the WiFi. Then I resume the app and open the modal again. The state returned is still type === unknown.

The state I get doesn't update until I make another network change with the app in foreground.

Connection with a vpn at android is not recognized

Platforms

Android

Versions

  • Android: 9 (Samsung Galaxy S8)
  • react-native-netinfo: 2.0.9
  • react-native: 0.59.0

Description

Calling NetInfo.getConnectionInfo() returns type "unknown", if a vpn is activated and the device have a connection with wifi/cellular.
The deprecated intern React Native Package have the correct return of "wifi" by calling getConnectionInfo().
Also calling NetInfo.isConnected() return "false".

[ci] android tests

Just throwing up an issue to track some issues with Android CI flakiness;


Potential workaround: I think this is just down to lack of host gpu support on Circle CI & gpu emulation being slow - could increase the timeout


Potential fix: Add a Jest afterAll() global and a await device.terminateApp(); or process.exit(0)


I can take a look at these sometime next week; unless someone beats me too it 🙃

Make API more flexible

Why?

  1. We require an "event name", but we actually only have a single event and likely won't add more.
  2. The effectiveType property name does not really communicate what the value means (cellular generation).
  3. The effectiveType property only makes sense when type: "cellular". Additionally, the shape of the object makes it hard to add new properties which are only applicable for one of the connection types such as "SSID" for Wifi connections. Related to issues #37 and #52.
  4. There is a mismatch between the name of NetInfo.getCurrentInfo() and NetInfo.isConnected.fetch() even though they serve the same purpose of fetching the current information once.
  5. It is not clear enough that the NetInfo.isConnected methods only say that we have an active connection, not that the internet is reachable. Related to issue #12.
  6. NetInfo.isConnectionExpensive() is only available on Android. This is useful information to know for when you want to make large API calls.

What?

// Methods
NetInfo.fetch(): Promise<NetInfoState>;
NetInfo.addEventListener(listener: (state: NetInfoState) => void): void;

// Types
type NetInfoState =
  | NetInfoUnknownState
  | NetInfoNoConnectionState
  | NetInfoCellularState
  | NetInfoWifiState
  | NetInfoBluetoothState
  | NetInfoEthernetState
  | NetInfoWimaxState;

type NetInfoConnectedDetails = {
  isConnectionExpensive: boolean,
  externalIp: string | null,
  externalIpv6: string | null,
};

type NetInfoUnknownState = {
  type: 'unknown',
  isConnected: false,
  isInternetReachable: false,
  details: null,
};

type NetInfoNoConnectionState = {
  type: 'none',
  isConnected: false,
  isInternetReachable: false,
  details: null,
};

type NetInfoCellularState = {
  type: 'cellular',
  isConnected: true,
  isInternetReachable: boolean,
  details: NetInfoConnectedDetails & {
    cellularGeneration: '2g' | '3g' | '4g' | null,
  },
};

type NetInfoWifiState = {
  type: 'wifi',
  isConnected: true,
  isInternetReachable: boolean,
  details: NetInfoConnectedDetails & {
    ssid: string | null,
  },
};

type NetInfoBluetoothState = {
  type: 'bluetooth',
  isConnected: true,
  isInternetReachable: boolean,
  details: NetInfoConnectedDetails,
};

type NetInfoEthernetState = {
  type: 'ethernet',
  isConnected: true,
  isInternetReachable: boolean,
  details: NetInfoConnectedDetails,
};

type NetInfoWimaxState = {
  type: 'wimax',
  isConnected: true,
  isInternetReachable: boolean,
  details: NetInfoConnectedDetails,
};

For the shape of the NetInfoState type:

  • Top level properties (type, isConnected, isInternetReachable) are properties which make sense across all states, including type: "none"`.
  • Properties in details are one which are only applicable for a subset of states, including those which are only applicable when connected. To tidy up the types these are defined once in the NetInfoConnectedDetails type.

Example usage:

NetInfo.addEventListener((state: NetInfoState) => {
  if (state.isConnected) {
    console.log(`Connected!`);
    console.log(`Is internet reachable: ${state.isInternetReachable}`);

    // Get the connection type and cellular generation and SSID if we have the correct types
    console.log(`Type: ${state.type}`);
    if (state.type === 'cellular') {
      console.log(`Cellular generation: ${state.details.cellularGeneration}`);
    } else if (state.type === 'wifi') {
      console.log(`Cellular generation: ${state.details.ssid}`);
    }

    // Type systems should allow this as details always has "externalIpv6" when connected, but it might be "null"
    console.log(`External IP: ${state.details.externalIpv6}`);
  } else {
    console.log('No connection');
  }
});

How does this API change solve the issues?

  1. Removes the first parameter from the NetInfo.addEventListener() method.
  2. Changes the effectiveType property to state.details.cellularGeneration.
  3. Moves the connection specific details into the state.details property. The types make it clear when these properties are available and will throw errors on both Flow and TypeScript if misused.
  4. Removes the need for the NetInfo.isConnected methods as the connected flag is now included in NetInfoState. This encourages developer to make full use of the information we fetch and is no less efficient because we always fetch all of the data anyway and transform is to a boolean in Javascript.
  5. Adds the isInternetReachable flag which makes it clearer that isConnected is not the one to use.
  6. Moving the isConnectionExpensive into state.details for all connected states makes the flag useable on both platforms and much easier to get access to.
    • Note that the implementation of this is likely to be different as Android has a way to ask the system if the connection is "metered" which has the possibility, for example, of classifying certain Wifi connections as "expensive". iOS does not have this functionality so we will likely just need to say that cellular is expensive and wifi is not. This is why the property is a boolean rather than having a fixed true or false value for each connection type.

Backward compatibility

We should not introduce such big breaking changes lightly. I believe with this API we can actually provide full backward compatibility with the current API.

  • Because we are changing the current NetInfo.getCurrentInfo() method to NetInfo.fetch() we can keep the previous one around and transform the new state shape into the current one. This was the reason for changing the method name to fetch.
  • If the user calls the NetInfo.addEventListener() method with a string as the first parameter, we can assume they want to use the current API and transform the new state shape into the current one.
  • We can keep the current NetInfo.isConnected methods is the API and simply return the isConnected boolean from the new state shape.

All of these cases can be handled in a backward compatible way and we can include Yellow Box warnings to encourage upgrading to the newer APIs.

  • Advantages:
    • Much easier upgrade path for existing developers.
    • We can gently nudge towards upgrading with yellow box warnings (likely with a "warnOnce` to avoid spamming developers).
    • The new features will only be available with the new API, so it will encourage upgrading.
  • Disadvantages:
    • We need to have some code in the library to provide backward compatibility which slightly increases the bundle size and surface areas of the library.

Discussion points

  1. Is this a good idea?
  2. Does this API look good and be something which is flexible enough to add new properties and connection types in the future as technology changes?
  3. How do we handle deprecating the current API? Do we just remove it and release a new major version or do we provide backward compatible methods which produce warnings when used?

RN 0.59+ Android build error

Environment

React Native Environment Info:
System:
OS: macOS 10.14.3
CPU: (8) x64 Intel(R) Core(TM) i7-6820HQ CPU @ 2.70GHz
Memory: 78.85 MB / 16.00 GB
Shell: 5.3 - /bin/zsh
Binaries:
Node: 10.14.1 - /usr/local/bin/node
Yarn: 1.15.2 - /usr/local/bin/yarn
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: 23, 24, 25, 26, 27, 28
Build Tools: 23.0.1, 23.0.2, 23.0.3, 25.0.0, 25.0.2, 26.0.1, 26.0.2, 26.0.3, 27.0.3, 28.0.2, 28.0.3
System Images: android-25 | Google APIs Intel x86 Atom, android-25 | Google APIs Intel x86 Atom_64, android-27 | Intel x86 Atom, android-28 | Intel x86 Atom, android-28 | Google APIs Intel x86 Atom, android-28 | Google Play Intel x86 Atom
IDEs:
Android Studio: 3.3 AI-182.5107.16.33.5314842
Xcode: 10.1/10B61 - /usr/bin/xcodebuild
npmPackages:
react: 16.8.3 => 16.8.3
react-native: 0.59.1 => 0.59.1

Platforms

Android only

Versions

  • Android: 9
  • react-native-netinfo: 1.3.0
  • react-native: 0.59.1
  • react: 16.8.3

Description

Task :@react-native-community_netinfo:compileDebugJavaWithJavac FAILED

FAILURE: Build failed with an exception.

  • What went wrong:
    Execution failed for task ':@react-native-community_netinfo:compileDebugJavaWithJavac'.

Could not create service of type DefaultGeneralCompileCaches using GradleScopeCompileServices.createGeneralCompileCaches().

Result from background calls (headless/fetch) always unknown?

Following this issue: #32

Calls to await NetInfo.getConnectionInfo(); always return type "unknown" when called from a headless or background task (such as when using react-native-background-fetch).

Is there a way to get an uncached version of the network info? This is critical to only perform background requests when the user is on wifi.

Podfile is broken in 2.0.1

Environment

React Native Environment Info:
System:
OS: macOS 10.14.4
CPU: (8) x64 Intel(R) Core(TM) i7-7920HQ CPU @ 3.10GHz
Memory: 127.13 MB / 16.00 GB
Shell: 5.3 - /bin/zsh
Binaries:
Node: 11.12.0 - /usr/local/bin/node
Yarn: 1.15.2 - /usr/local/bin/yarn
npm: 6.7.0 - /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
IDEs:
Android Studio: 3.3 AI-182.5107.16.33.5314842
Xcode: 10.1/10B61 - /usr/bin/xcodebuild
npmPackages:
react: 16.8.3 => 16.8.3
react-native: 0.59.4 => 0.59.4
npmGlobalPackages:
create-react-native-app: 1.0.0
react-native-cli: 2.0.1
react-native-git-upgrade: 0.2.7

Platforms

iOS

Versions

  • react-native-netinfo: 2.0.1
  • react-native: 0.59.4
  • react: 16.8.3

Description

After upgrading from 2.0.0 to 2.0.1 pod init returns in this error. [!] No podspec found for 'react-native-netinfo' in '../node_modules/@react-native-community/netinfo' before the update everything is working fine. There's no new instruction for linking or a warning in the release.

Add instructions for mocking with Jest

Environment

  React Native Environment Info:
    System:
      OS: macOS 10.14.4
      CPU: (4) x64 Intel(R) Core(TM) i5-7267U CPU @ 3.10GHz
      Memory: 784.71 MB / 16.00 GB
      Shell: 5.3 - /bin/zsh
    Binaries:
      Node: 11.6.0 - ~/.nvm/versions/node/v11.6.0/bin/node
      Yarn: 1.13.0 - ~/.yarn/bin/yarn
      npm: 6.9.0 - ~/.nvm/versions/node/v11.6.0/bin/npm
      Watchman: 4.9.0 - /usr/local/bin/watchman
    SDKs:
      iOS SDK:
        Platforms: iOS 12.2, macOS 10.14, tvOS 12.2, watchOS 5.2
      Android SDK:
        API Levels: 23, 27, 28
        Build Tools: 27.0.3, 28.0.2, 28.0.3
        System Images: android-23 | Google APIs Intel x86 Atom_64, android-28 | Intel x86 Atom_64, android-28 | Google APIs Intel x86 Atom, android-28 | Google APIs Intel x86 Atom_64, android-28 | Google Play Intel x86 Atom_64
    IDEs:
      Android Studio: 3.3 AI-182.5107.16.33.5314842
      Xcode: 10.2.1/10E1001 - /usr/bin/xcodebuild
    npmPackages:
      react: 16.8.4 => 16.8.4 
      react-native: 0.59.5 => 0.59.5 
    npmGlobalPackages:
      react-native-cli: 2.0.1

Platforms

Jest

Versions

  • react-native-netinfo: 2.0.4
  • react-native: 0.59.5
  • react: 16.8.4

Description

Running a simple test in my app result in this:

 FAIL  src/__tests__/App.test.js
  ● Test suite failed to run

    @react-native-community/netinfo: NativeModule.RNCNetInfo is null. To fix this issue try these steps:

    • Run `react-native link @react-native-community/netinfo` in the project root.
    • Rebuild and re-run the app.
    • If you are using CocoaPods on iOS, run `pod install` in the `ios` directory and then rebuild and re-run the app. You may also need to re-open Xcode to get the new pods.

    If none of these fix the issue, please open an issue on the Github repository: https://github.com/react-native-community/react-native-netinfo

      at Object.<anonymous> (node_modules/@react-native-community/netinfo/lib/commonjs/nativeInterface.js:18:9)
      at Object.<anonymous> (node_modules/@react-native-community/netinfo/lib/commonjs/index.js:14:1)

Reproducible Demo

tests/App.test.js:

import React from 'react';
import renderer from 'react-test-renderer';
import App from '../App';

describe('App tests', () => {
  test('renders correctly', () => {
    const tree = renderer.create(<App />).toJSON();
    expect(tree).toMatchSnapshot();
  });
});

run jest

when could NetInfo.fetch reject?

Ask your Question

Hi. There is not any information in docs when NetInfo.fetch promise is rejected. Could you explain it in the docs?

CocoaPods crashes (with the stupid React dependency in podfile)

Environment

info
React Native Environment Info:
System:
OS: macOS 10.14.3
CPU: x64 Intel(R) Core(TM) i7-6567U CPU @ 3.30GHz
Memory: 261.48 MB / 16.00 GB
Shell: 3.2.57 - /bin/bash
Binaries:
Node: 8.15.1 - /usr/local/bin/node
Yarn: 1.15.2 - /usr/local/bin/yarn
npm: 6.7.0 - /usr/local/bin/npm
Watchman: 4.9.0 - /usr/local/bin/watchman
SDKs:
iOS SDK:
Platforms: iOS 12.2, macOS 10.14, tvOS 12.2, watchOS 5.2
Android SDK:
Build Tools: 21.1.1, 21.1.2, 22.0.0, 22.0.1, 23.0.1, 23.0.2, 23.0.3, 24.0.1, 25.0.0, 25.0.2, 25.0.3, 26.0.0, 26.0.2, 27.0.3, 28.0.0, 28.0.2, 28.0.3
API Levels: 22, 24, 26, 27, 28
IDEs:
Android Studio: 3.2 AI-181.5540.7.32.5014246
Xcode: 10.2/10E125 - /usr/bin/xcodebuild
npmPackages:
react: 16.8.5 => 16.8.5
react-native: 0.59.2 => 0.59.2
npmGlobalPackages:
react-native-cli: 2.0.1
react-native-git-upgrade: 0.2.7

Platforms

iOS

Versions

  • react-native-netinfo:
  • react-native: 0.59.2
  • react: 16.8.5

Description

Uses old version of React and when adding the React dependecies from the node_modules directory (which is a really stupid way to do this) CocoaPods crashes. Isn't there really a better way to add dependencies with just package.json as all other dependencies? Really don't understand why some developers choose this CocoaPods way, which never works.

pod 'yoga', path: './node_modules/react-native/ReactCommon/yoga'
  pod 'Folly', :podspec => './node_modules/react-native/third-party-podspecs/Folly.podspec'
  pod 'GLog', :podspec => './node_modules/react-native/third-party-podspecs/GLog.podspec'
  pod 'DoubleConversion', :podspec => '../node_modules/react-native/third-party-podspecs/DoubleConversion.podspec'
  pod 'React', path: './node_modules/react-native', subspecs: [
    'Core',
    'jschelpers',
    'cxxreact',
    'CxxBridge',
    'DevSupport',
    'RCTText',
    'RCTImage',
    'RCTNetwork',
    'RCTActionSheet',
    'RCTAnimation',
    'RCTWebSocket'
  ]

.rvm/gems/ruby-2.2.1@global/gems/gh_inspector-1.0.3/lib/gh_inspector/sidekick.rb:91:in `block in validate_delegate': #<Pod::UserInterface::InspectorReporter:0x007f811242da48> does not handle inspector_successfully_recieved_report (RuntimeError)

Typescript error / downlevel-iterators?

Environment

Honestly, I tried to run react-native info but it hung? That was unexpected. It only spit this bit out first:

react-native info output until it hungmike@isabela:~/work/Kullki/kscoreapp-rxp (mvp3-dev *) % react-native info info React Native Environment Info: System: OS: Linux 5.1 Ubuntu 19.04 (Disco Dingo) CPU: (12) x64 Intel(R) Core(TM) i7-8750H CPU @ 2.20GHz Memory: 685.18 MB / 31.13 GB Shell: 5.0.3 - /bin/bash Binaries: Node: 12.2.0 - ~/.nvm/versions/node/v12.2.0/bin/node Yarn: 1.16.0 - ~/.nvm/versions/node/v12.2.0/bin/yarn npm: 6.9.0 - ~/.nvm/versions/node/v12.2.0/bin/npm SDKs: Android SDK: API Levels: 15, 16, 17, 18, 19, 21, 22, 23, 24, 25, 26, 27, 28 Build Tools: 23.0.1, 24.0.0, 24.0.2, 25.0.0, 25.0.1, 25.0.2, 26.0.0, 26.0.3, 27.0.3, 28.0.0, 28.0.1, 28.0.2, 28.0.3, 29.0.0 System Images: android-15 | Intel x86 Atom, android-15 | Google APIs Intel x86 Atom, android-16 | ARM EABI v7a, android-16 | Intel x86 Atom, android-16 | Google APIs Intel x86 Atom, android-17 | Intel x86 Atom, android-17 | Google APIs Intel x86 Atom, android-18 | Intel x86 Atom, android-18 | Google APIs Intel x86 Atom, android-19 | Intel x86 Atom, android-19 | Google APIs Intel x86 Atom, android-21 | Intel x86 Atom, android-21 | Google APIs Intel x86 Atom, android-22 | ARM EABI v7a, android-22 | Intel x86 Atom, android-22 | Google APIs ARM EABI v7a, android-23 | Android TV Intel x86 Atom, android-23 | Intel x86 Atom, android-23 | Google APIs ARM EABI v7a, android-23 | Google APIs Intel x86 Atom, android-24 | ARM 64 v8a, android-24 | ARM EABI v7a, android-24 | Intel x86 Atom, android-24 | Google APIs Intel x86 Atom, android-25 | Google APIs ARM 64 v8a, android-25 | Google APIs ARM EABI v7a, android-25 | Google APIs Intel x86 Atom, android-26 | Google APIs Intel x86 Atom, android-27 | Google APIs Intel x86 Atom, android-28 | Google APIs Intel x86 Atom, android-Q | Google Play Intel x86 Atom_64, chromeos-67 | Chrome OS 67 npmPackages: react: ^16.8.6 => 16.8.6 react-native: ^0.59.8 => 0.59.8 npmGlobalPackages: react-native-cli: 2.0.1

Platforms

both - but really, typescript 3.4.5 with this tsconfig:

{
  "compilerOptions": {
    "declaration": false,
    "noResolve": false,
    "jsx": "react",
    "reactNamespace": "RX",
    "lib": ["dom", "es5", "scripthost", "es2015"],
    "module": "commonjs",
    "target": "es5",
    "experimentalDecorators": true,
    "sourceMap": true,
    "skipLibCheck": true,
    "noImplicitAny": true,
    "noImplicitReturns": true,
    "outDir": "./dist/",
    "strict": true
  },
  "exclude": ["node_modules"],
  "include": ["./src/**/*"]
}

Versions

  • Android: N/A
  • iOS: N/A
  • react-native-netinfo: 3.1.0
  • react-native: 0.59.8
  • react: 16.8.6

Description

I run tsc and get this, with the above tsconfig.json:

[12:39:59 AM] Starting compilation in watch mode...

node_modules/@react-native-community/netinfo/src/internal/deprecatedSubscriptions.ts:23:23 - error TS2569: Type 'Set<ChangeHandler>' is not an array type or a string type. Use compiler option '--downlevelIteration' to allow iterating of iterators.

23   for (let handler of _subscriptions) {
                         ~~~~~~~~~~~~~~

node_modules/@react-native-community/netinfo/src/internal/subscriptions.ts:23:23 - error TS2569: Type 'Set<NetInfoChangeHandler>' is not an array type or a string type. Use compiler option '--downlevelIteration' to allow iterating of iterators.

23   for (let handler of _subscriptions) {
                         ~~~~~~~~~~~~~~

[12:40:06 AM] Found 2 errors. Watching for file changes.

Reproducible Demo

If you paste my tsconfig.json over the project's one in the root, then run npm run validate:typescript you will see it

This looked like interesting related reading: https://mariusschulz.com/blog/typescript-2-3-downlevel-iteration-for-es3-es5

I suppose I could move up to es6 as my target but it would be nice for safety's sake in a ReactXP project (that touches the web) to stay on ES5 just in case. Maybe there's an easy refactor to remove the need for this style iteration?

Or at the least you should warn that the typescript requires either ES6 or downlevel-iterators, but then you might take note of the tslib/importhelpers note in the linked article

Add Wifi SSID to the connection info

Describe the Feature

NetInfo.isConnected.addEventListener only works when wifi is turned on/off. I am looking to listen to an event when wifi switches from one network to another. Can anyone have some solutions or any workarounds? Thanks in advance.

Possible Implementations

NetInfo.isConnected.addEventListener("connectionSwitch", listener)
or
NetInfo.isConnected.addEventListener("wifiConnectionSwitch", listener)

No default export found in module

No default export found in module

Hi all, ever since we migrated from the original ReactNative library to this one we've been having two issues, one with eslint error (which can be ignored) that complains about no default export being found and more importantly with Jest:

.../node_modules/@react-native-community/netinfo/js/index.js:11
    import {Platform} from 'react-native';
           ^

which seems to be similar.

Judging by google result and the fact that no one else seems to be having this issue I think we're doing something wrong but after a few days of trying I thought it's best to ask here.

correct me if I'm wrong but judging by the source code looks like this library is using es5 style module export which seems to be related to the errors we're getting?

Any help or ideas would be much appreciated :) Thanks!

Android throws an error - RNCNetInfo Native module is not present

Environment

info
React Native Environment Info:
System:
OS: macOS High Sierra 10.13.6
CPU: (8) x64 Intel(R) Core(TM) i7-7700HQ CPU @ 2.80GHz
Memory: 84.29 MB / 16.00 GB
Shell: 3.2.57 - /bin/bash
Binaries:
Node: 11.0.0 - /usr/local/bin/node
Yarn: 1.10.1 - /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.0, macOS 10.14, tvOS 12.0, watchOS 5.0
Android SDK:
API Levels: 21, 22, 23, 24, 25, 26, 27, 28
Build Tools: 23.0.1, 23.0.2, 25.0.0, 25.0.1, 25.0.2, 25.0.3, 26.0.1, 26.0.2, 26.0.3, 27.0.3, 28.0.0, 28.0.2, 28.0.3
System Images: android-27 | Google APIs Intel x86 Atom
IDEs:
Android Studio: 3.3 AI-182.5107.16.33.5199772
Xcode: 10.0/10A255 - /usr/bin/xcodebuild
npmPackages:
react: 16.8.3 => 16.8.3
react-native: 0.59.4 => 0.59.3
npmGlobalPackages:
create-react-native-app: 1.0.0
react-native-cli: 2.0.1
react-native-create-library: 3.1.2
react-native-git-upgrade: 0.2.7

Platforms

Android

Description

Android keeps throwing an error on launch saying RNCNetInfo Native module is not present. iOS is working fine.

Reproducible Demo

See attached picture,
imageedit_3_4316371832

Error On Install Following Directions RN 59.4

Environment

React Native Environment Info:
System:
OS: macOS 10.14.4
CPU: (8) x64 Intel(R) Core(TM) i7-7920HQ CPU @ 3.10GHz
Memory: 1.17 GB / 16.00 GB
Shell: 3.2.57 - /bin/bash
Binaries:
Node: 11.8.0 - /usr/local/bin/node
Yarn: 1.13.0 - /usr/local/bin/yarn
npm: 6.7.0 - /usr/local/bin/npm
SDKs:
iOS SDK:
Platforms: iOS 12.2, macOS 10.14, tvOS 12.2, watchOS 5.2
Android SDK:
API Levels: 24, 26, 27, 28
Build Tools: 24.0.0, 26.0.0, 28.0.3
System Images: android-27 | Android TV Intel x86 Atom, android-28 | Google APIs Intel x86 Atom, android-28 | Google Play Intel x86 Atom
IDEs:
Android Studio: 3.3 AI-182.5107.16.33.5314842
Xcode: 10.2/10E125 - /usr/bin/xcodebuild
npmPackages:
react: 16.5.0 => 16.5.0
react-native: https://github.com/expo/react-native/archive/sdk-32.0.0.tar.gz => 0.57.1
npmGlobalPackages:
react-native-cli: 2.0.1
react-native: 0.59.4

Platforms

Test on IOS only so far, actual device

Versions

Info above

Description

After following the directions, 2 steps to install I get an error running the example code that says RNCNetInfo is null. To fix this issue try these steps:, Run 'react-native link....'. I have removed the node modules and reinstalled everything. This module does not work. Very disappointing to see the NetInfo is depreciated and the replacement has problems just to run the example code.

Reproducible Demo

Just install the project using NPM per the instructions with the latest react-native version

npm install --save @react-native-community/netinfo
react-native link @react-native-community/netinfo

Build problem on android

Hi,

I recently upgraded to Netinfo 2.0.6 and I'm getting the following error:

Task :@react-native-community_netinfo:compileReleaseJavaWithJavac FAILED
/Users/vsts/agent/2.150.0/work/1/s/node_modules/@react-native-community/netinfo/android/src/main/java/com/reactnativecommunity/netinfo/ConnectivityReceiver.java:14: error: package android.support.v4.net does not exist
import android.support.v4.net.ConnectivityManagerCompat;

I've tried making sure that the package is in my build.gradle but nothing is helping.

My react native version is 0.59.5.

Thanks!

Trying to subscribe to unknown event message

Environment

info
React Native Environment Info:
System:
OS: macOS 10.14.5
CPU: (8) x64 Intel(R) Core(TM) i7-5775R CPU @ 3.30GHz
Memory: 183.88 MB / 16.00 GB
Shell: 5.3 - /bin/zsh
Binaries:
Node: 10.15.3 - ~/.nvm/versions/node/v10.15.3/bin/node
Yarn: 1.13.0 - /usr/local/bin/yarn
npm: 6.4.1 - ~/.nvm/versions/node/v10.15.3/bin/npm
SDKs:
iOS SDK:
Platforms: iOS 12.2, macOS 10.14, tvOS 12.2, watchOS 5.2
Android SDK:
API Levels: 22, 23, 24, 25, 26, 27, 28
Build Tools: 23.0.1, 23.0.3, 24.0.1, 25.0.0, 25.0.2, 26.0.1, 26.0.2, 27.0.3, 28.0.0, 28.0.2, 28.0.3, 29.0.0
System Images: android-23 | Google APIs Intel x86 Atom_64, android-24 | ARM 64 v8a, android-25 | Google APIs ARM EABI v7a, android-25 | Google APIs Intel x86 Atom_64, android-25 | Google Play Intel x86 Atom, android-26 | Google APIs Intel x86 Atom, android-26 | Google Play Intel x86 Atom, android-28 | Google Play Intel x86 Atom
IDEs:
Xcode: 10.2.1/10E1001 - /usr/bin/xcodebuild
npmPackages:
react: 16.6.3 => 16.6.3
react-native: 0.59.0 => 0.59.0

Platforms

Both Android and iOS

Versions

  • Android: 9.0
  • iOS: 12.2
  • react-native-netinfo: 2.0.10
  • react-native: 0.59
  • react: 16.6.3

Description

If we use the code in readme:

const subscription = NetInfo.addEventListener(state => {
console.log("Connection type", state.type);
console.log("Is connected?", state.isConnected);
});

we got this message in logcat:

Trying to subscribe to unknown event: "function (state) {
console.log('DEBUG!!! Connection type', state.type);
console.log('DEBUG!!! Is connected?', state.isConnected);
}"

And Netinfo seems not working...
Can you help us ?

Thank you

annotationProcessors.json not found

Environment

Execution failed for task ':@react-native-community_netinfo:compileDebugJavaWithJavac'.

java.io.FileNotFoundException: /node_modules/@react-native-community/netinfo/android/build/intermediates/annotation_processor_list/debug/annotationProcessors.json (No such file or directory)

Platforms

Android

Versions

  • react-native-netinfo: 2.0.9
  • react-native: 0.59.5

Description

This file is not present in the relevant directory.
I tried running the assemble task inside the android folder of netinfo library. Then this file got generated inside /node_modules/@react-native-community/netinfo/android/build/intermediates/annotation_processor_list/debug/javaPreCompileDebug directory.
Then I tried pasting that file into the desired directory.
When I tried running react-native run-android command this file automatically gets removed from the directory.

Offline is always repoted as "unknown" instead of "none" ?

Platforms

Android

Versions

  • Android: 8.1 (Motorola G5), 9 (Pixel 2)
  • react-native-netinfo: 2.0.0
  • react-native: 0.59.4
  • react: 16.8.6

Description

Calling NetInfo.getConnectionInfo() always returns type "unknown" when wifi is turned off, and cellular data is turned off.
One would expect that "none" is returned instead. Right now, it is impossible to tell the difference between actually being offline, or not being able to tell the network status at all.

Since network info can be sometimes be unreliable (such as when called in background #64 ), being able to tell the difference between unknown and none is actually very important, since you can then implement different behaviors for each case.

Fix Android Warnings

Platforms

Android

Description

Android has multiple Java and Lint warnings which, depending on project configuration, could cause build errors. These should all be fixed or suppressed.

Android: NetworkCallbackConnectivityReceiver does not report "none" status correctly

Environment

React Native Environment Info:
    System:
      OS: macOS 10.14.3
      CPU: (12) x64 Intel(R) Core(TM) i9-8950HK CPU @ 2.90GHz
      Memory: 3.03 GB / 32.00 GB
      Shell: 5.3 - /bin/zsh
    Binaries:
      Node: 10.13.0 - ~/.nvm/versions/node/v10.13.0/bin/node
      Yarn: 1.15.2 - /usr/local/bin/yarn
      npm: 6.4.1 - ~/.nvm/versions/node/v10.13.0/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: 23, 25, 26, 27, 28
        Build Tools: 25.0.2, 27.0.3, 28.0.2, 28.0.3
        System Images: android-28 | Google APIs Intel x86 Atom, android-28 | Google Play Intel x86 Atom
    IDEs:
      Android Studio: 3.1 AI-173.4907809
      Xcode: 10.1/10B61 - /usr/bin/xcodebuild
    npmPackages:
      react: 16.8.3 => 16.8.3
      react-native: 0.59.2 => 0.59.2
    npmGlobalPackages:
      react-native-cli: 2.0.1

Platforms

Android

Versions

  • Android: 24+ (N and above)
  • iOS: NA
  • react-native-netinfo: Any
  • react-native: Any
  • react: Any

Description

The NetworkCallbackConnectivityReceiver class does not correctly handle the none case. It should set connectionType to CONNECTION_TYPE_NONE when mNetworkCapabilities is null. This will match the behaviour of iOS and older versions of Android.

Reproducible Demo

https://github.com/matt-oakes/net-info-test

Update Readme

Ask your Question

can you please update the documentation?
By example
Readme says
NetInfo.fetch()
and this doesn't works at all, The Right way it's the next
NetInfo.isConnected.fetch().

Import NetInfo issue

Environment

  React Native Environment Info:
    System:
      OS: Linux 4.20 Arch Linux undefined
      CPU: (4) x64 Intel(R) Core(TM) i5-6500 CPU @ 3.20GHz
      Memory: 399.44 MB / 15.35 GB
      Shell: 5.0.0 - /bin/bash
    Binaries:
      Node: 10.7.0 - /usr/local/bin/node
      npm: 6.7.0 - ~/.node_modules/bin/npm
    IDEs:
      Android Studio: 3.3
    npmPackages:
      react: ^16.8.4 => 16.8.4 
      react-native: ^0.59.0 => 0.59.0 
    npmGlobalPackages:
      react-native-cli: 2.0.1
      react-native-google-signin: 0.12.0
      react-native-rename: 2.4.0

Platforms

Both

Versions

react-native-netinfo: 1.2.3
react-native: 0.59.0
react: 16.8.4
typescript: 3.3.3333

Description

When creating a project using Typescript, import NetInfo from "@react-native-community/netinfo" would throw this error:

Cannot read property 'getConnectionInfo' of undefined

ts file:

   async componentWillMount() {
        let {type} = await NetInfo.getConnectionInfo();
        if (type === "none") {
        }
    }

This is the compiled js file:

    componentWillMount() {
        return __awaiter(this, void 0, void 0, function* () {
            let { type } = yield netinfo_1.default.getConnectionInfo();
            if (type === "none") {
            }
        });
    }

To avoid this error, I have to use

const NetInfo = require("@react-native-community/netinfo");
or
import * as NetInfo from "@react-native-community/netinfo"

but either solution would lose the typing support.

Is it possible to use import * as NetInfo from "@react-native-community/netinfo while it still has the typing available?

My tsconfig:

{
  "compilerOptions": {
    "module": "commonjs",
    "target": "es6",
    "moduleResolution": "node",
    "removeComments": true,
    "allowSyntheticDefaultImports": true,
    "noImplicitAny": false,
    "experimentalDecorators": true,
    "noLib": false,
    "declaration": false,
    "emitDecoratorMetadata": true,
    "lib": ["es6", "dom"],
    "types": ["reflect-metadata"],
    "inlineSources":true,
    "skipLibCheck": true,
    "jsx": "react-native",
    "resolveJsonModule": true
  }
}

Build failed on ios 12.2

Environment

React Native Environment Info:
System:
OS: macOS 10.14.4
CPU: (8) x64 Intel(R) Core(TM) i7-6820HQ CPU @ 2.70GHz
Memory: 188.01 MB / 16.00 GB
Shell: 3.2.57 - /bin/bash
Binaries:
Node: 10.13.0 - /var/folders/nl/710wyq5x15v877chfxh5hsd80000gn/T/yarn--1554154696352-0.5529216754436022/node
Yarn: 1.13.0 - /var/folders/nl/710wyq5x15v877chfxh5hsd80000gn/T/yarn--1554154696352-0.5529216754436022/yarn
npm: 6.4.1 - ~/.nvm/versions/node/v10.13.0/bin/npm
Watchman: 4.9.0 - /usr/local/bin/watchman
SDKs:
iOS SDK:
Platforms: iOS 12.2, macOS 10.14, tvOS 12.2, watchOS 5.2
Android SDK:
API Levels: 23, 25, 26, 27, 28
Build Tools: 26.0.0, 27.0.3, 28.0.3
System Images: android-24 | Google APIs Intel x86 Atom, android-25 | Google APIs ARM 64 v8a, android-25 | Google APIs ARM EABI v7a, android-28 | Google APIs Intel x86 Atom, android-28 | Google Play Intel x86 Atom_64
IDEs:
Android Studio: 3.3 AI-182.5107.16.33.5264788
Xcode: 10.2/10E125 - /usr/bin/xcodebuild
npmPackages:
react: 16.8.3 => 16.8.3
react-native: 0.59.0 => 0.59.0

Platforms

iOS

Versions

  • iOS: 12.2
  • react-native-netinfo: 1.4.0
  • react-native: 0.59
  • react: 16.8.3

Description

yarn react-native run-ios --device="iPhone XS" - getting build failed

image

isConnected.fetch() returns different values on different android devices

I was trying to run the following codes:

NetInfo.isConnected.fetch().then(isConnected => {
   alert("Is connected", isConnected);
});

on OnePlus 2 and Xiaomi Redmi 4 while both devices are connected.

OnePlus2 return true and Redmi4 return false. Just a suggestion and hope we can find the solution :)

Thanks.

getConnectionInfo & isConnected returns different values on different android devices

Environment

info
React Native Environment Info:
System:
OS: macOS 10.14.3
CPU: (4) x64 Intel(R) Core(TM) i5-5257U CPU @ 2.70GHz
Memory: 17.01 MB / 16.00 GB
Shell: 3.2.57 - /bin/bash
Binaries:
Node: 8.9.4 - /usr/local/bin/node
Yarn: 1.6.0 - /usr/local/bin/yarn
npm: 6.4.1 - /usr/local/bin/npm
Watchman: 4.4.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: 23, 25, 26, 27, 28
Build Tools: 23.0.1, 23.0.2, 23.0.3, 25.0.0, 25.0.2, 26.0.1, 26.0.2, 27.0.0, 27.0.3, 28.0.2, 28.0.3
System Images: android-23 | Intel x86 Atom_64, android-23 | Google APIs Intel x86 Atom_64, android-28 | Google APIs Intel x86 Atom
IDEs:
Android Studio: 3.0 AI-171.4408382
Xcode: 10.1/10B61 - /usr/bin/xcodebuild
npmPackages:
react: ^16.8.3 => 16.8.4
react-native: ^0.59.4 => 0.59.4
npmGlobalPackages:
create-react-native-app: 1.0.0
react-native-cli: 2.0.1
react-native-git-upgrade: 0.2.7

Platforms

Android on different brands

Versions

  • Android: OnePlus2 Android version 6.0, Redmi Note 4 Android version 7.0
  • react-native-netinfo: ^1.3.0
  • react-native: ^0.59.4
  • react: ^16.8.3

Description

I was trying to run the following codes:

NetInfo.isConnected.fetch().then(isConnected => {
   alert("Is connected", isConnected);
});

on OnePlus 2 and Xiaomi Redmi 4 while both devices are connected.

OnePlus2 return true and Redmi4 return false. With suggestion from @matt-oakes , I ran the following codes on both devices with and without internet connection.

NetInfo.getConnectionInfo().then(connectionInfo => {
  console.log("Connection type", connectionInfo.type);
  console.log("Connection effective type", connectionInfo.effectiveType);
});

Results are as following:

Redmi Note 4
Either when connected or not connected,
Connection type - unknown
Connection effective type - unknown

OnePlus2
When connected,
Connection type - wifi
Connection effective type - unknown

When not connected,
Connection type - none
Connection effective type - unknown

Reproducible Demo

I just created a simple project and run the codes on both devices.

Gradle 5.+ and name issue

Platforms

Android

Description

When trying to use this plugin with Gradle 5.0 (which should come soon to RN facebook/react-native#23324), I am getting these error :


* What went wrong:
A problem occurred configuring project ':@react-native-community/netinfo'.
> The project name '@react-native-community/netinfo' must not contain any of the following characters: [/, \, :, <, >, ", ?, *, |]. Set the 'rootProject.name' or adjust the 'include' statement (see https://docs.gradle.org/5.2/dsl/org.gradle.api.initialization.Settings.html#org.gradle.api.initialization.Settings:include(java.lang.String[]) for more details).

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.

* Get more help at https://help.gradle.org

I think it is because Gradle 5.+ does not accept anymore that kind of name : https://docs.gradle.org/current/userguide/upgrading_version_4.html

Thanking you in advance

Automatic linking fails on Android

Environment

  React Native Environment Info:
    System:
      OS: macOS 10.14.3
      CPU: (8) x64 Intel(R) Core(TM) i7-6920HQ CPU @ 2.90GHz
      Memory: 225.40 MB / 16.00 GB
      Shell: 2.7.1 - /usr/local/bin/fish
    Binaries:
      Node: 10.15.0 - ~/.nvm/versions/node/v10.15.0/bin/node
      Yarn: 1.12.3 - /usr/local/bin/yarn
      npm: 6.4.1 - ~/.nvm/versions/node/v10.15.0/bin/npm
      Watchman: 4.9.0 - /usr/local/bin/watchman
    SDKs:
      iOS SDK:
        Platforms: iOS 12.2, macOS 10.14, tvOS 12.2, watchOS 5.2
      Android SDK:
        API Levels: 24, 25, 26, 27, 28
        Build Tools: 27.0.3, 28.0.2, 28.0.3
        System Images: android-28 | 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.2/10E125 - /usr/bin/xcodebuild
    npmPackages:
      react: 16.8.3 => 16.8.3
      react-native: 0.59.1 => 0.59.1

Platforms

Android

Versions

  • Android: 2.0.0

Description

react-native link @react-native-community/netinfo command is not linking the library properly.

To fix this issue one must manually add the following

android/app/build.gradle:

dependencies {
...
implementation project(':@react-native-community_netinfo')
}

android/app/src/main/java/.../MainApplication.java:

protected List<ReactPackage> getPackages() {
...
new NetInfoPackage()
}

We are using react-native-navigation that causes the MainApplication.java to be a slightly different than it is in React Native's project template.

Reproducible Demo

  • Install package from NPM
  • Run react-native link for the package

Build on android issues

Environment

$ react-native info
info
React Native Environment Info:
System:
OS: Windows 10
CPU: (4) x64 Intel(R) Core(TM) i7-7660U CPU @ 2.50GHz
Memory: 921.76 MB / 7.93 GB
Binaries:
npm: 6.9.0 - C:\Program Files\nodejs\npm.CMD
IDEs:
Android Studio: Version 3.4.0.0 AI-183.5429.30.34.5452501

Platforms

Android

Versions

  • Android: 2.0.6
  • iOS: 2.0.6
  • react-native-netinfo:
  • react-native: 0.59.5
  • react: 16.8.4

Description

When compiling the android binary I get this error:

Task :@react-native-community_netinfo:compileReleaseJavaWithJavac FAILED
/Users/vsts/agent/2.150.0/work/1/s/node_modules/@react-native-community/netinfo/android/src/main/java/com/reactnativecommunity/netinfo/ConnectivityReceiver.java:14: error: package android.support.v4.net does not exist
import android.support.v4.net.ConnectivityManagerCompat;
^
/Users/vsts/agent/2.150.0/work/1/s/node_modules/@react-native-community/netinfo/android/src/main/java/com/reactnativecommunity/netinfo/ConnectivityReceiver.java:78: error: cannot find symbol
promise.resolve(ConnectivityManagerCompat.isActiveNetworkMetered(getConnectivityManager()));
^
symbol: variable ConnectivityManagerCompat
location: class ConnectivityReceiver
2 errors

FAILURE: Build failed with an exception.

  • What went wrong:
    Execution failed for task ':@react-native-community_netinfo:compileReleaseJavaWithJavac'.

Compilation failed; see the compiler error output for details.

Reproducible Demo

Code matches the sample on the github repo

I have tried putting the old android.support.v4 libraries into my build.gradle. I had to upgrade to androidx for support of @react-native-communiy/slider so I've tried using that to do legacy libraries too but they all fail.

NetInfo.getConnectionInfo() return unknown for android

Environment

  React Native Environment Info:
    System:
      OS: macOS 10.14.4
      CPU: (12) x64 Intel(R) Core(TM) i7-8750H CPU @ 2.20GHz
      Memory: 86.61 MB / 16.00 GB
      Shell: 3.2.57 - /bin/bash
    Binaries:
      Node: 11.3.0 - /usr/local/bin/node
      Yarn: 1.12.3 - /usr/local/bin/yarn
      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: 25, 26, 27, 28
        Build Tools: 26.0.2, 27.0.3, 28.0.3
        System Images: android-27 | Intel x86 Atom_64, android-28 | Google APIs Intel x86 Atom
    IDEs:
      Android Studio: 3.2 AI-181.5540.7.32.5056338
      Xcode: 10.1/10B61 - /usr/bin/xcodebuild
    npmPackages:
      react: 16.6.3 => 16.6.3 
      react-native: 0.58.3 => 0.58.3 

Platforms

Android

Versions

  • Android: 7.0
  • iOS:
  • react-native-netinfo: ^2.0.0
  • react-native: 0.58.3
  • react: 16.6.3

Description

It's the same issue which is described here.

Reproducible Demo

import React, { Component } from 'react'
import {
    View,
    Text
} from 'react-native'

import { connect } from 'src/store'
import NetInfo from "@react-native-community/netinfo";

class InternetConnection extends Component {
    listener = null
    state = {
        online: false
    }

    componentDidMount () {
        let me = this

        me.listener = NetInfo.isConnected.addEventListener('connectionChange', me.onConnectionChange.bind(me))
    }

    componentWillUnmount () {
        let me = this

        if (me.listener) {
            me.listener.remove()
        }
    }

    onConnectionChange ({ info, effectiveType }) {
        let me = this

        if (!info || info === 'none' || info === 'unknown') {
            me.setState({ online: false })
        } else {
            me.setState({ online: true })
        }

        console.log(info, effectiveType)
    }

    render() {
        let { online } = this.state

        if (online) {
            return null
        }

        return (
            <View style={{ backgroundColor: 'red', padding: 5 }}>
                <Text style={{ textAlign: 'center', color: '#fff' }}>
                    Offline
                </Text>
            </View>
        )
    }

}

export default connect(InternetConnection)

Types not correctly declared [Typescript]

Environment

  React Native Environment Info:
    System:
      OS: macOS 10.14.3
      CPU: (8) x64 Intel(R) Core(TM) i7-6820HQ CPU @ 2.70GHz
      Memory: 48.39 MB / 16.00 GB
      Shell: 5.3 - /bin/zsh
    Binaries:
      Node: 11.0.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
    IDEs:
      Android Studio: 3.3 AI-182.5107.16.33.5199772
      Xcode: 10.1/10B61 - /usr/bin/xcodebuild
    npmPackages:
      react: 16.8.3 => 16.8.3
      react-native: 0.59.0-rc.3 => 0.59.0-rc.3
    npmGlobalPackages:
      react-native-cli: 2.0.1
      react-native-git-upgrade: 0.2.7
      react-native-i18n: 2.0.11

Platforms

iOS/Android/Typescript

Versions

  • react-native-netinfo: 1.2.2
  • react-native: 0.59.0-rc.3
  • react: 16.8.3

Description

When creating a project using Typescript the types file for netinfo does not declare its types correctly.

Reproducible Demo

react-native init TestNetInfo --version [email protected] --template typescript
cd TestNetInfo
Open in VSCode (other other editor supporting typescript)

Paste the following code into your App.ts file:

import React from 'react';
import { View } from 'react-native';
import NetInfo, { ConnectionInfo } from "@react-native-community/netinfo";

class App extends React.PureComponent {
  render () { return (<View/>); }
  componentDidMount() {
    NetInfo.addEventListener("connectionChange", this.connectionChanged);
  }
}

Expected

The function addEventListener should be available on the NetInfo type in the editor.

Observe

The function addEventListener is not detected as a valid type in the editor.

Android resolver : Indeed, none of these files exist: netinfo/src/index.ts

Environment

Environment:
OS: macOS 10.14.4
Node: 10.15.3
Yarn: Not Found
npm: 6.4.1
Watchman: Not Found
Xcode: Xcode 10.2.1 Build version 10E1001
Android Studio: 3.4 AI-183.5429.30.34.5452501

Packages: (wanted => installed)
react: ^16.3.1 => 16.3.1
react-native: ^0.55.4 => 0.55.4

Platforms

Android

Description

Resolver doesn't find the module. Still, the package is correctly installed, linked, and the file exist.

I tried to reset-cache, rm -rf node_modules and npm i, still can't resolve this module.

bundling failed: Error: 
While trying to resolve module `@react-native-community/netinfo` from file `xxx/app/middleware/network.js`, 
the package `xxx/node_modules/@react-native-community/netinfo/package.json` was successfully found. 
However, this package itself specifies a `main` module field that could not be resolved (`xxx/node_modules/@react-native-community/netinfo/src/index.ts`. 

Indeed, none of these files exist:

  * `xxx/node_modules/@react-native-community/netinfo/src/index.ts(.native||.android.js|.native.js|.js|.android.json|.native.json|.json)

@react-native-community/netinfo: NativeModule.RNCNetInfo is null... after install

Environment

React Native Environment Info:
System:
OS: macOS 10.14.4
CPU: x64 Intel(R) Core(TM) i7-7820HQ CPU @ 2.90GHz
Memory: 174.83 MB / 16.00 GB
Shell: 5.5.1 - /usr/local/bin/zsh
Binaries:
Node: 8.11.4 - ~/.nvm/versions/node/v8.11.4/bin/node
npm: 6.4.0 - ~/.nvm/versions/node/v8.11.4/bin/npm
Watchman: 4.9.0 - /usr/local/bin/watchman
SDKs:
iOS SDK:
Platforms: iOS 12.2, macOS 10.14, tvOS 12.2, watchOS 5.2
IDEs:
Android Studio: 3.2 AI-181.5540.7.32.5056338
Xcode: 10.2/10E125 - /usr/bin/xcodebuild
npmPackages:
react: 16.5.0 => 16.5.0
react-native: 0.57.1 => 0.57.1

Platforms

Both

Versions

  • Android: 8.0.0 && 8.0.1
  • iOS: 12.1
  • react-native-netinfo: 2.0.2 && 2.0.3
  • react-native: 0.57.1
  • react: 16.5.0

Description

I installed the latest version as well as 2.0.2, linked the package using react-native link @react-native-community/netinfo, and rebuilt the project using react-native run-ios. I got the previously reported @react-native-community/netinfo: NativeModule.RNCNetInfo is null... error.

As per @matt-oakes 's request, I am not using Cocoa Pods so there isn't a Podfile or Podlock to report, I am using react-native's link command for everything.

Screen Shot 2019-04-16 at 7 15 53 PM

Reproducible Demo

All I did was install, rebuild the project and restart the packager after importing the package in the root App.js file.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.