Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Restore NetInfo package changes from #1092 #1119

Merged
merged 1 commit into from
Jul 20, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 1 addition & 56 deletions docs/docs/apis/network.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,59 +7,4 @@ permalink: docs/apis/network.html
next: apis/platform
---

This interface provides information about network connectivity.

## Types
``` javascript
enum DeviceNetworkType {
Unknown,
None,
Wifi,
Mobile2G,
Mobile3G,
Mobile4G
}
```

## Methods
``` javascript
// Returns a promise that specifies whether the device currently
// has network connectivity
isConnected(): SyncTasks.Promise<boolean>;

// Returns the type of network
getType(): SyncTasks.Promise<DeviceNetworkType>;
```

## Events
``` javascript
// Triggered when the connectivity changes
connectivityChangedEvent: SubscribableEvent<(isConnected: boolean) => void>;
```

## Sample Usage

``` javascript
private isConnected: boolean;

constructor() {
// Query the initial connectivity state.
this.isConnected = false;
RX.Network.isConnected().then(isConnected => {
this.isConnected = isConnected;
});

RX.Network.connectivityChangedEvent.subscribe(isConnected => {
// Update the connectivity state.
this.isConnected = isConnected;
});
}
```

## Other Notes

On Android, the following permission must be added to make use of the network interfaces.

``` xml
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
```
This has been deprecated from ReactXP Core and moved to an extension (reactxp-netinfo) inline with the React Native Lean Core initiative.
2 changes: 1 addition & 1 deletion docs/docs/extensions/navigator.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ title: Navigator
layout: docs
category: Extensions
permalink: docs/extensions/navigator.html
next: extensions/restclient
next: extensions/netinfo
---

This component provides a way for the app to present a virtual stack of "cards", allowing the user to push or pop those cards onto the stack in an animated manner. The caller can control the animation type and direction.
Expand Down
65 changes: 65 additions & 0 deletions docs/docs/extensions/netinfo.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
---
id: extensions/netinfo
title: NetInfo
layout: docs
category: Extensions
permalink: docs/extensions/navigator.html
next: extensions/restclient
---

This interface provides information about network connectivity.

## Types
``` javascript
enum DeviceNetworkType {
Unknown,
None,
Wifi,
Mobile2G,
Mobile3G,
Mobile4G
}
```

## Methods
``` javascript
// Returns a promise that specifies whether the device currently
// has network connectivity
isConnected(): SyncTasks.Promise<boolean>;

// Returns the type of network
getType(): SyncTasks.Promise<DeviceNetworkType>;
```

## Events
``` javascript
// Triggered when the connectivity changes
connectivityChangedEvent: SubscribableEvent<(isConnected: boolean) => void>;
```

## Sample Usage

``` javascript
private isConnected: boolean;

constructor() {
// Query the initial connectivity state.
this.isConnected = false;
RXNetInfo.isConnected().then(isConnected => {
this.isConnected = isConnected;
});

RXNetInfo.connectivityChangedEvent.subscribe(isConnected => {
// Update the connectivity state.
this.isConnected = isConnected;
});
}
```

## Other Notes

On Android, the following permission must be added to make use of the network interfaces.

``` xml
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
```
20 changes: 20 additions & 0 deletions extensions/netinfo/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Logs
logs
*.log
npm-debug.log*

# Dependency directories
node_modules
package-lock.json

# Optional npm cache directory
.npm

# Build artifacts
**/dist

# Miscellaneous user files
*.user
.vscode
.DS_STORE

5 changes: 5 additions & 0 deletions extensions/netinfo/.npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
/node_modules
/src/.vs
/src/bin
/src/obj
*.user
21 changes: 21 additions & 0 deletions extensions/netinfo/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# reactxp-netinfo
This module provides cross-platform support for detecting network ionformation within the [ReactXP](https://microsoft.github.io/reactxp/) library. This used to be a part of ReactXP core, but was extracted to be a standalone module inline with React Native `Lean Core` initiative. This exists as a standalone module to prevent users of ReactXP from having to link native modules when getting started.

## Getting Started
This module relies on [@react-native-community/netinfo](https://www.npmjs.com/packages/@react-native-community/netinfo) and will need to be linked into the react-native project.
This can be done by following the linking instructions in the React Native documentation or by running
```react-native link @react-native-community/netinfo```

## Documentation
For detailed documentation, look [here](https://microsoft.github.io/reactxp/docs/extensions/netinfo.html).

### Prerequisites
* [ReactXP](https://github.com/microsoft/reactxp/)

## Contributing
This project has adopted the [Microsoft Open Source Code of Conduct](https://opensource.microsoft.com/codeofconduct/). For more information see the [Code of Conduct FAQ](https://opensource.microsoft.com/codeofconduct/faq/) or contact [opencode@microsoft.com](mailto:opencode@microsoft.com) with any additional questions or comments.

You must sign a Contribution License Agreement (CLA) before your PR will be merged. This a one-time requirement for Microsoft projects in GitHub. You can read more about [Contribution License Agreements (CLA)](https://en.wikipedia.org/wiki/Contributor_License_Agreement) on Wikipedia. You can sign the Microsoft Contribution License Agreement by visiting https://cla.microsoft.com/. Use your GitHub account to login.

## License
This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details
3 changes: 3 additions & 0 deletions extensions/netinfo/index.android.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
'use strict';

module.exports = require('./dist/android/PluginBase.js');
3 changes: 3 additions & 0 deletions extensions/netinfo/index.ios.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
'use strict';

module.exports = require('./dist/ios/PluginBase.js');
4 changes: 4 additions & 0 deletions extensions/netinfo/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
'use strict';

// Export web by default. Other platforms have custom index.[platform].js files
module.exports = require('./dist/web/PluginBase.js');
3 changes: 3 additions & 0 deletions extensions/netinfo/index.macos.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
'use strict';

module.exports = require('./dist/macos/PluginBase.js');
3 changes: 3 additions & 0 deletions extensions/netinfo/index.windows.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
'use strict';

module.exports = require('./dist/windows/PluginBase.js');
28 changes: 28 additions & 0 deletions extensions/netinfo/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{
"name": "reactxp-netinfo",
"version": "0.0.1-alpha.1",
"description": "Plugin for ReactXP that provides information about network connectivity",
"author": "ReactXP Team <reactxp@microsoft.com>",
"license": "MIT",
"scripts": {
"build": "npm run tslint && tsc",
"tslint": "tslint -p tsconfig.json -r tslint.json -r ./node_modules/tslint-microsoft-contrib --fix || true"
},
"dependencies": {
"@react-native-community/netinfo": "^3.2.0",
"synctasks": "^0.3.3"
},
"peerDependencies": {
"reactxp": "^1.6.0",
"react-dom": "^16.4.0",
"react-native": "^0.55.0",
"react-native-windows": "^0.54.0"
},
"devDependencies": {
"reactxp": "^1.6.0",
"typescript": "3.4.5",
"tslint": "5.16.0",
"tslint-microsoft-contrib": "6.1.1"
},
"types": "dist/web/PluginBase.d.ts"
}
13 changes: 13 additions & 0 deletions extensions/netinfo/src/android/PluginBase.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
/*
* PluginBase.ts
*
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT license.
*
* Base export for the Android implementation of the plugin.
*/

import * as Types from '../common/Types';
import NetInfo from '../native-common/NetInfo';

export { NetInfo as default, Types };
26 changes: 26 additions & 0 deletions extensions/netinfo/src/common/Interfaces.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/*
* Interfaces.ts
*
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT license.
*
* Interface definition for cross-platform ReactXP plugin for gathering network/connectivity
* info. This was extracted from the reactxp core
*/

import * as SyncTasks from 'synctasks';
import SubscribableEvent from 'subscribableevent';

import * as Types from './Types';

export abstract class NetInfo {
abstract isConnected(): SyncTasks.Promise<boolean>;
abstract getType(): SyncTasks.Promise<Types.DeviceNetworkType>;
connectivityChangedEvent = new SubscribableEvent<(isConnected: boolean) => void>();
}

export interface PluginInterface {
Types: typeof Types;

default: NetInfo;
}
23 changes: 23 additions & 0 deletions extensions/netinfo/src/common/PluginBaseChecker.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/*
* PluginBaseChecker.ts
*
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT license.
*
* Type check all the pluginbase exports against the desired interface.
*/

import * as Interfaces from './Interfaces';
import * as AndroidPlugin from '../android/PluginBase';
import * as iOSPlugin from '../ios/PluginBase';
import * as macOSPlugin from '../macos/PluginBase';
import * as WebPlugin from '../web/PluginBase';
import * as WindowsPlugin from '../windows/PluginBase';

/* tslint:disable:no-unused-variable */
const _typeCheckerAndroid: Interfaces.PluginInterface = AndroidPlugin;
const _typeCheckeriOS: Interfaces.PluginInterface = iOSPlugin;
const _typeCheckermacOS: Interfaces.PluginInterface = macOSPlugin;
const _typeCheckerWeb: Interfaces.PluginInterface = WebPlugin;
const _typeCheckerWindows: Interfaces.PluginInterface = WindowsPlugin;
/* tslint:enable:no-unused-variable */
17 changes: 17 additions & 0 deletions extensions/netinfo/src/common/Types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/*
* Types.ts
*
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT license.
*
* Type definitions to support the plugin.
*/

export enum DeviceNetworkType {
Unknown,
None,
Wifi,
Mobile2G,
Mobile3G,
Mobile4G
}
13 changes: 13 additions & 0 deletions extensions/netinfo/src/ios/PluginBase.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
/*
* PluginBase.ts
*
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT license.
*
* Base export for the iOS implementation of the plugin.
*/

import * as Types from '../common/Types';
import NetInfo from '../native-common/NetInfo';

export { NetInfo as default, Types };
13 changes: 13 additions & 0 deletions extensions/netinfo/src/macos/PluginBase.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
/*
* PluginBase.ts
*
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT license.
*
* Base export for the Mac implementation of the plugin.
*/

import * as Types from '../common/Types';
import NetInfo from '../native-common/NetInfo';

export { NetInfo as default, Types };
Loading