https://github.com/manuelkch/react-native-network-connection-class
React Native Android Bridge to Facebook's Network Connection Class
https://github.com/manuelkch/react-native-network-connection-class
android-library react react-native react-native-app reactjs
Last synced: 5 months ago
JSON representation
React Native Android Bridge to Facebook's Network Connection Class
- Host: GitHub
- URL: https://github.com/manuelkch/react-native-network-connection-class
- Owner: manuelkch
- License: unlicense
- Created: 2017-02-06T09:36:58.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2017-02-06T19:12:44.000Z (over 9 years ago)
- Last Synced: 2025-08-09T14:44:00.950Z (11 months ago)
- Topics: android-library, react, react-native, react-native-app, reactjs
- Language: Java
- Size: 4.88 KB
- Stars: 3
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# React Native Network Connection Class
Android Bridge to Facebook's [Network Connection Class](https://github.com/facebook/network-connection-class)
>Network Connection Class is an Android library that allows you to figure out the quality of the current user's internet connection. The connection gets classified into several "Connection Classes" that make it easy to develop against.
[](https://www.npmjs.com/package/react-native-network-connection-class)
## Installation
```bash
1) npm i --save react-native-network-connection-class
or manually:
Add repository to package.json
"react-native-device-year-class": "git+ssh://git@github.com:manuelkch/react-native-network-connection-class.git"
2) Run
npm install
or manually:
git clone the directory to [node_modules/react-native-network-connection-class]
```
### Add it to your react-native project
#### React Native Link
`react-native link react-native-network-connection-class`
#### or manually
* In `android/setting.gradle`
```gradle
...
include ':react-native-network-connection-class'
project(':react-native-network-connection-class').projectDir = new File(settingsDir, '../node_modules/react-native-network-connection-class/android')
```
* In `android/app/build.gradle`
```gradle
...
dependencies {
...
compile project(':react-native-network-connection-class')
}
```
* register module in `MainApplication.java`
```java
import com.ymc.NetworkConnectionClass.Package;
...
protected List getPackages() {
return Arrays.asList(
new MainReactPackage(),
new Package() // <-- Add this line.
);
}
```
## Example
```javascript
...
import NetworkConnectionClass from 'react-native-network-connection-class'
...
//listen to connection class changes
DeviceEventEmitter.addListener('connectionClassChange', function(e: Event) {
// new state
console.warn(e.state)
})
...
//get current class string (POOR, MODERATE,GOOD or EXCELENT)
NetworkConnectionClass.getCurrentQuality().then((status) => {
//current state
console.warn(status)
})
...
//start/stop sampling bandwith data on newtork activities
NetworkConnectionClass.startSampling()
.fetch('https://jsonplaceholder.typicode.com/photos')
.then(function(response) {
NetworkConnectionClass.stopSampling()
...
})
...
// get boolean if sampling thread is running
NetworkConnectionClass.getSamplingState().then((isSampling) => {
console.warn(isSampling)
})
```