Skip to content

Commit a638cd6

Browse files
authored
Merge pull request #429 from NativeScript/niliev/revamp
docs: Components module revamp
2 parents 59a1a29 + b046706 commit a638cd6

File tree

9 files changed

+96
-81
lines changed

9 files changed

+96
-81
lines changed

app/ng-framework-modules-category/connectivity/connectivity-examples.component.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { Component, ChangeDetectionStrategy } from "@angular/core";
22
import { Link } from "./../../link";
33

44
let menuLinks = [
5-
new Link("Using Connectivity", "/connectivity/using-connectivity"),
5+
new Link("Usage", "/connectivity/usage"),
66
];
77

88
@Component({

app/ng-framework-modules-category/connectivity/connectivity-examples.module.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { NgModule, NO_ERRORS_SCHEMA } from "@angular/core";
22
import { NativeScriptRouterModule } from "nativescript-angular/router";
33
import { NativeScriptCommonModule } from "nativescript-angular/common";
44
import { ConnectivityExamplesComponent } from "./connectivity-examples.component";
5-
import { UsingConnectivityExampleComponent } from "./using-connectivity/using-connectivity.component";
5+
import { UsageComponent } from "./usage/usage.component";
66
import { TitleAndNavButtonModule } from "../../directives/title-and-nav-button.module";
77

88
export const routerConfig = [
@@ -11,9 +11,9 @@ export const routerConfig = [
1111
component: ConnectivityExamplesComponent
1212
},
1313
{
14-
path: "using-connectivity",
15-
component: UsingConnectivityExampleComponent,
16-
data: { title: "Using connectivity" }
14+
path: "usage",
15+
component: UsageComponent,
16+
data: { title: "Usage" }
1717
}
1818
];
1919

@@ -25,7 +25,7 @@ export const routerConfig = [
2525
NativeScriptRouterModule,
2626
NativeScriptRouterModule.forChild(routerConfig)
2727
],
28-
declarations: [ConnectivityExamplesComponent, UsingConnectivityExampleComponent]
28+
declarations: [ConnectivityExamplesComponent, UsageComponent]
2929
})
3030

3131
export class ConnectivityExamplesModule {
Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,20 @@
1+
## Methods
12

2-
**API Reference for the** [Connectivity Class](https://docs.nativescript.org/api-reference/modules/_connectivity_.html)
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 & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
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: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<snippet id='connectivity-start-code'/>
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
// >> connectivity-start-code
2+
import { Component, OnInit, OnDestroy } from "@angular/core";
3+
import {
4+
getConnectionType,
5+
startMonitoring,
6+
stopMonitoring
7+
} from "tns-core-modules/connectivity";
8+
import * as connectivityModule from "tns-core-modules/connectivity";
9+
10+
@Component({
11+
moduleId: module.id,
12+
templateUrl: "./usage.component.html"
13+
})
14+
15+
export class UsageComponent implements OnInit, OnDestroy {
16+
connectionType: string;
17+
18+
constructor() {
19+
let type = getConnectionType();
20+
21+
switch (type) {
22+
case connectivityModule.connectionType.none:
23+
this.connectionType = "None";
24+
break;
25+
case connectivityModule.connectionType.wifi:
26+
this.connectionType = "Wi-Fi";
27+
break;
28+
case connectivityModule.connectionType.mobile:
29+
this.connectionType = "Mobile";
30+
break;
31+
case connectivityModule.connectionType.bluetooth:
32+
this.connectionType = "Bluetooth";
33+
break;
34+
default:
35+
break;
36+
}
37+
}
38+
39+
ngOnInit() {
40+
startMonitoring((type) => {
41+
switch (type) {
42+
case connectivityModule.connectionType.none:
43+
this.connectionType = "None";
44+
console.log("Connection type changed to none.");
45+
break;
46+
case connectivityModule.connectionType.wifi:
47+
this.connectionType = "Wi-Fi";
48+
console.log("Connection type changed to WiFi.");
49+
break;
50+
case connectivityModule.connectionType.mobile:
51+
this.connectionType = "Mobile";
52+
console.log("Connection type changed to mobile.");
53+
break;
54+
case connectivityModule.connectionType.bluetooth:
55+
this.connectionType = "Bluetooth";
56+
console.log("Connection type changed to Bluetooth.");
57+
break;
58+
default:
59+
break;
60+
}
61+
});
62+
}
63+
64+
ngOnDestroy() {
65+
// Stoping the connection monitoring
66+
stopMonitoring();
67+
}
68+
}
69+
// << connectivity-start-code

app/ng-framework-modules-category/connectivity/using-connectivity/article.md

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

app/ng-framework-modules-category/connectivity/using-connectivity/using-connectivity.component.ts

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

0 commit comments

Comments
 (0)