Skip to content

Commit

Permalink
chore: peer dependencies and update docs (#267)
Browse files Browse the repository at this point in the history
  • Loading branch information
rgommezz committed Apr 9, 2020
1 parent 04069a6 commit 61717f4
Show file tree
Hide file tree
Showing 3 changed files with 3,465 additions and 6,818 deletions.
95 changes: 19 additions & 76 deletions README.md
Expand Up @@ -70,94 +70,37 @@ This gives you the power to prioritize our work and support the project contribu

## Installation

### RN >= 0.59.x
Make sure to have `react-redux` version 6.x.x or 7.x.x installed.
```
### RN >= 0.60
This library uses [@react-native-community/netinfo](https://github.com/react-native-community/react-native-netinfo) behind the scenes, which contains native code, so you need to install it and link it as well. Follow the next steps in order:
```bash
$ yarn add react-native-offline
$ yarn add @react-native-community/netinfo
# extra step for iOS
$ (cd ios && pod install)

# Or if you use npm
$ npm i --save react-native-offline
```

This library uses `@react-native-community/netinfo@5.x.x` version underneath the hood. You then need to link the native parts of the library for the platforms you are using.

If you are on React Native v0.60, you don't need to do anything else, since it supports autolinking. For iOS, just go to the `ios` folder and run `pod install`. However, autolinking might not pick up and install the `@react-native-community/netinfo` dependency. If that happens, first install `@react-native-community/netinfo` directly, then run `pod install`, then install `react-native-offline` and finish with `pod install`.

Otherwise, the easiest way to link the library is using the CLI tool by running this command from the root of your project:

```
react-native link @react-native-community/netinfo
$ npm i react-native-offline
$ npm i @react-native-community/netinfo
# extra step for iOS
$ (cd ios && pod install)
```

If you can't or don't want to use the CLI tool, you can also manually link the library using the instructions below (click on the arrow to show them):

<details>
<summary>Manually link the library on iOS</summary>

Either follow the [instructions in the React Native documentation](https://facebook.github.io/react-native/docs/linking-libraries-ios#manual-linking) to manually link the framework or link using [Cocoapods](https://cocoapods.org) by adding this to your `Podfile`:

```ruby
pod 'react-native-netinfo', :path => '../node_modules/@react-native-community/netinfo'
```

</details>

<details>
<summary>Manually link the library on Android</summary>

Make the following changes:

#### `android/settings.gradle`
```groovy
include ':react-native-community-netinfo'
project(':react-native-community-netinfo').projectDir = new File(rootProject.projectDir, '../node_modules/@react-native-community/netinfo/android')
```

#### `android/app/build.gradle`
```groovy
dependencies {
...
implementation project(':react-native-community-netinfo')
}
```
On RN 0.60, for Android, you may need to use [jetifier](https://github.com/mikehardy/jetifier) to convert the native dependency to AndroidX.

#### `android/app/src/main/.../MainApplication.java`
On top, where imports are:

```java
import com.reactnativecommunity.netinfo.NetInfoPackage;
```

Add the `NetInfoPackage` class to your list of exported packages.

```java
@Override
protected List<ReactPackage> getPackages() {
return Arrays.asList(
new MainReactPackage(),
new NetInfoPackage()
);
}
```

</details>
#### Android
To request network info in Android an extra step is required, so you should add the following line to your app's `AndroidManifest.xml` as well:

Last but not list, you need to use [jetifier](https://github.com/mikehardy/jetifier) to convert the native dependency to AndroidX.
`<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />`

### RN >= 0.55.x && RN <= 0.58.x
Make sure to have `react-redux` version 6.x.x or 7.x.x installed.
```
$ yarn add react-native-offline@4.3.2
### Expo >= 35
If you are using the [managed workflow](https://docs.expo.io/versions/latest/introduction/managed-vs-bare/#managed-workflow), you don't need to install any extra dependency. Expo SDK already ships in with `NetInfo`.
```bash
$ yarn add react-native-offline

# Or if you use npm
$ npm i --save react-native-offline@4.3.2
$ npm i react-native-offline
```

#### Android
To request network info in Android an extra step is required, so you should add the following line to your app's `AndroidManifest.xml` as well:

`<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />`

## API

### Component Utilities
Expand Down

0 comments on commit 61717f4

Please sign in to comment.