Skip to content

Commit 6488b3f

Browse files
authored
Merge pull request #166 from NativeScript/revamp
feat: update connectivity example
2 parents d5686ec + e3259a8 commit 6488b3f

File tree

9 files changed

+43
-80
lines changed

9 files changed

+43
-80
lines changed

app/ns-framework-modules-category/connectivity/basics/article.md

Lines changed: 0 additions & 17 deletions
This file was deleted.

app/ns-framework-modules-category/connectivity/connectivity-page.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
const ListViewLinksModel = require("../../links-view-model");
22
const link = require("../../link");
33
const navigationLinks = [
4-
new link("Basics", "ns-framework-modules-category/connectivity/basics/basics-page")
4+
new link("Usage", "ns-framework-modules-category/connectivity/usage/usage-page")
55
];
66
const navigationLinksTsc = [
7-
new link("Basics", "ns-framework-modules-category/connectivity/basics/basics-ts-page")
7+
new link("Usage", "ns-framework-modules-category/connectivity/usage/usage-ts-page")
88
];
99

1010
function onNavigatingTo(args) {
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
## Methods
2+
3+
| Name | Type | Description |
4+
|----------|---------|----------------|
5+
| `getConnectionType` | `number` | Gets the type of connection. Returns a value from the `connectivityModule.connectionType` enumeration. To use this method on Android you need to have the **android.permission.ACCESS_NETWORK_STATE** permission added to the **AndroidManifest.xml** file. |
6+
| `startMonitoring(connectionTypeChangedCallback: function)` | `void` | Starts monitoring the connection type. |
7+
| `stopMonitoring` | `void` | Stops monitoring the connection type. |
8+
9+
## API References
10+
11+
| Name | Type |
12+
|----------|---------|
13+
| [tns-core-modules/connectivity](https://docs.nativescript.org/api-reference/modules/_connectivity_.html) | `Module` |
14+
| [connectionTypoe](https://docs.nativescript.org/api-reference/enums/_connectivity_.connectiontype) | `Enum` |
15+
16+
## Native Component
17+
18+
| Android | iOS |
19+
|:----------------------|:---------|
20+
| [CONNECTIVITY_SERVICE (android.content.Context)](https://developer.android.com/reference/android/content/Context) | [SCNetworkReachability](https://developer.apple.com/documentation/systemconfiguration/scnetworkreachability-g7d) |
Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1 @@
1-
The [connectivity](https://docs.nativescript.org/api-reference/modules/_connectivity_) module contains connectivity utility methods for observing the connection type and availability.
2-
3-
To control and monitor the Internet connectivity , you need to import the `tns-core-modules/connectivity` module.
4-
<snippet id='connectivity-require'/>
5-
<snippet id='connectivity-require-ts'/>
1+
The connectivity module provides a common abstraction of the functionality responsible for receiving information about the connection type and availability of the network.
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
<snippet id='connectivity-start-code-js'/>
2+
<snippet id='connectivity-start-code-ts'/>

app/ns-framework-modules-category/connectivity/basics/basics-page.js renamed to app/ns-framework-modules-category/connectivity/usage/usage-page.js

Lines changed: 6 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,57 +1,38 @@
1-
// >> connectivity-require
1+
// >> connectivity-start-code-js
22
const connectivityModule = require("tns-core-modules/connectivity");
3-
// << connectivity-require
3+
44

55
exports.onNavigatedTo = function(args) {
66
const page = args.object;
77
let connectionTypeString;
88

9-
// >> connectivity-type
10-
// result is ConnectionType enumeration (none, wifi or mobile)
11-
const myConnectionType = connectivityModule.getConnectionType();
9+
const type = connectivityModule.getConnectionType();
1210

13-
switch (myConnectionType) {
11+
switch (type) {
1412
case connectivityModule.connectionType.none:
15-
// Denotes no Internet connection.
1613
console.log("No connection");
17-
// >> (hide)
1814
connectionTypeString = "No Internet connectivity!";
19-
// << (hide)
2015
break;
2116
case connectivityModule.connectionType.wifi:
22-
// Denotes a WiFi connection.
2317
console.log("WiFi connection");
24-
// >> (hide)
2518
connectionTypeString = "WiFI connectivity!";
26-
// << (hide)
2719
break;
2820
case connectivityModule.connectionType.mobile:
29-
// Denotes a mobile connection, i.e. cellular network or WAN.
3021
console.log("Mobile connection");
31-
// >> (hide)
3222
connectionTypeString = "Mobile connectivity!";
33-
// << (hide)
3423
break;
3524
case connectivityModule.connectionType.ethernet:
36-
// Denotes a ethernet connection.
3725
console.log("Ethernet connection");
38-
// >> (hide)
3926
connectionTypeString = "Ethernet connectivity!";
40-
// << (hide)
4127
break;
4228
case connectivityModule.connectionType.bluetooth:
43-
// Denotes a bluetooth connection.
4429
console.log("Bluetooth connection");
45-
// >> (hide)
4630
connectionTypeString = "Bluetooth connectivity!";
47-
// << (hide)
4831
break;
4932
default:
5033
break;
5134
}
52-
// << connectivity-type
5335

54-
// >> connectivity-monitoring
5536
connectivityModule.startMonitoring((newConnectionType) => {
5637
switch (newConnectionType) {
5738
case connectivityModule.connectionType.none:
@@ -74,9 +55,9 @@ exports.onNavigatedTo = function(args) {
7455
}
7556
});
7657

77-
// Explicitly stopping the monitoring
58+
// Stoping the connection monitoring
7859
connectivityModule.stopMonitoring();
79-
// << connectivity-monitoring
8060

8161
page.bindingContext = { connectionType: connectionTypeString };
8262
};
63+
// << connectivity-start-code-js

app/ns-framework-modules-category/connectivity/basics/basics-ts-page.xml renamed to app/ns-framework-modules-category/connectivity/usage/usage-page.xml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<Page.actionBar>
33
<ActionBar title="Basics"/>
44
</Page.actionBar>
5-
<StackLayout verticalAlignment="middle" class="page">
6-
<Label text="{{ connectionType }}" textWrap="true" class="h2 text-center"/>
7-
</StackLayout>
5+
<GridLayout class="p-15" rows="*" columns="*">
6+
<Label text="{{ connectionType }}" textWrap="true" class="h1 p-15 text-center font-weight-bold"/>
7+
</GridLayout>
88
</Page>

app/ns-framework-modules-category/connectivity/basics/basics-ts-page.ts renamed to app/ns-framework-modules-category/connectivity/usage/usage-ts-page.ts

Lines changed: 6 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,57 +1,37 @@
1-
// >> connectivity-require-ts
1+
// >> connectivity-start-code-ts
22
import { connectionType, getConnectionType, startMonitoring, stopMonitoring }from "tns-core-modules/connectivity";
3-
// << connectivity-require-ts
43

54
export function onNavigatedTo(args) {
65
const page = args.object;
76
let connectionTypeString;
87

9-
// >> connectivity-type-ts
10-
// result is ConnectionType enumeration (none, wifi or mobile)
11-
const myConnectionType = getConnectionType();
8+
const type = getConnectionType();
129

13-
switch (myConnectionType) {
10+
switch (type) {
1411
case connectionType.none:
15-
// Denotes no Internet connection.
1612
console.log("No connection");
17-
// >> (hide)
1813
connectionTypeString = "No Internet connectivity!";
19-
// << (hide)
2014
break;
2115
case connectionType.wifi:
22-
// Denotes a WiFi connection.
2316
console.log("WiFi connection");
24-
// >> (hide)
2517
connectionTypeString = "WiFI connectivity!";
26-
// << (hide)
2718
break;
2819
case connectionType.mobile:
29-
// Denotes a mobile connection, i.e. cellular network or WAN.
3020
console.log("Mobile connection");
31-
// >> (hide)
3221
connectionTypeString = "Mobile connectivity!";
33-
// << (hide)
3422
break;
3523
case connectionType.ethernet:
36-
// Denotes a ethernet connection.
3724
console.log("Ethernet connection");
38-
// >> (hide)
3925
connectionTypeString = "Ethernet connectivity!";
40-
// << (hide)
4126
break;
4227
case connectionType.bluetooth:
43-
// Denotes a bluetooth connection.
4428
console.log("Bluetooth connection");
45-
// >> (hide)
4629
connectionTypeString = "Bluetooth connectivity!";
47-
// << (hide)
4830
break;
4931
default:
5032
break;
5133
}
52-
// << connectivity-type-ts
5334

54-
// >> connectivity-monitoring-ts
5535
startMonitoring((newConnectionType) => {
5636
switch (newConnectionType) {
5737
case connectionType.none:
@@ -74,8 +54,9 @@ export function onNavigatedTo(args) {
7454
}
7555
});
7656

77-
// Explicitly stopping the monitoring
57+
// Stoping the connection monitoring
7858
stopMonitoring();
79-
// << connectivity-monitoring-ts
59+
8060
page.bindingContext = { connectionType: connectionTypeString };
8161
}
62+
// << connectivity-start-code-ts

app/ns-framework-modules-category/connectivity/basics/basics-page.xml renamed to app/ns-framework-modules-category/connectivity/usage/usage-ts-page.xml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<Page.actionBar>
33
<ActionBar title="Basics"/>
44
</Page.actionBar>
5-
<StackLayout verticalAlignment="middle" class="page">
6-
<Label text="{{ connectionType }}" textWrap="true" class="h2 text-center"/>
7-
</StackLayout>
5+
<GridLayout class="p-15" rows="*" columns="*">
6+
<Label text="{{ connectionType }}" textWrap="true" class="h1 p-15 text-center font-weight-bold"/>
7+
</GridLayout>
88
</Page>

0 commit comments

Comments
 (0)