Skip to content

Commit fa6f4d5

Browse files
authored
Merge pull request #373 from NativeScript/niliev/application
docs: extend application article
2 parents abf321c + ff02076 commit fa6f4d5

File tree

5 files changed

+136
-0
lines changed

5 files changed

+136
-0
lines changed
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<GridLayout sdkExampleTitle sdkToggleNavButton>
2+
<Label class="body p-15" text="Refer to the component file for details on application events usage."
3+
textWrap="true"></Label>
4+
<!-- >> app-check-target-html -->
5+
<!-- << app-check-target-html -->
6+
</GridLayout>
Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
import { Component } from "@angular/core";
2+
3+
import {
4+
on,
5+
ApplicationEventData,
6+
launchEvent, LaunchEventData,
7+
resumeEvent,
8+
exitEvent,
9+
uncaughtErrorEvent, UnhandledErrorEventData,
10+
displayedEvent,
11+
lowMemoryEvent,
12+
orientationChangedEvent, OrientationChangedEventData,
13+
suspendEvent
14+
} from "tns-core-modules/application";
15+
16+
let launchListener,
17+
suspendListener,
18+
resumeListener,
19+
exitListener,
20+
displayedListener,
21+
lowMemoryListener,
22+
orientationChangedListener,
23+
uncaughtErrorListener;
24+
25+
@Component({
26+
moduleId: module.id,
27+
templateUrl: "./app-checking-target.component.html"
28+
})
29+
export class ApplicationEventsComponent {
30+
public isItemVisible: boolean;
31+
32+
constructor() {
33+
// >> application-events-launch-ng
34+
launchListener = (args: LaunchEventData) => {
35+
console.log("The appication was launched!");
36+
};
37+
on(launchEvent, launchListener);
38+
// << application-events-launch-ng
39+
40+
// >> application-events-suspend-ng
41+
suspendListener = (args: ApplicationEventData) => {
42+
console.log("The appication was suspended!");
43+
};
44+
on(suspendEvent, suspendListener);
45+
// << application-events-suspend-ng
46+
47+
// >> application-events-resume-ng
48+
resumeListener = (args: ApplicationEventData) => {
49+
console.log("The appication was resumed!");
50+
};
51+
on(resumeEvent, resumeListener);
52+
// << application-events-resume-ng
53+
54+
// >> application-events-exit-ng
55+
exitListener = (args: ApplicationEventData) => {
56+
console.log("The appication was closed!");
57+
};
58+
on(exitEvent, exitListener);
59+
// << application-events-exit-ng
60+
61+
// >> application-events-displayed-ng
62+
displayedListener = (args: ApplicationEventData) => {
63+
console.log("NativeScript displayedEvent!");
64+
};
65+
on(displayedEvent, displayedListener);
66+
// << application-events-displayed-ng
67+
68+
// >> application-events-low-memory-ng
69+
lowMemoryListener = (args: ApplicationEventData) => {
70+
// the instance that has raised the event
71+
console.log("Instance: ", args.object);
72+
};
73+
on(lowMemoryEvent, lowMemoryListener);
74+
// << application-events-low-memory-ng
75+
76+
// >> application-events-orientation-ng
77+
orientationChangedListener = (args: OrientationChangedEventData) => {
78+
// orientationChangedEventData.newValue: "portrait" | "landscape" | "unknown"
79+
console.log("Orientation: ", args.newValue);
80+
};
81+
on(orientationChangedEvent, orientationChangedListener);
82+
// << application-events-orientation-ng
83+
84+
// >> application-events-error-ng
85+
uncaughtErrorListener = (args: UnhandledErrorEventData) => {
86+
// UnhandledErrorEventData.error: NativeScriptError
87+
console.log("NativeScript Error: ", args.error);
88+
};
89+
on(uncaughtErrorEvent, uncaughtErrorListener);
90+
// << application-events-error-ng
91+
}
92+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
2+
The application module provides cross-platform application events to handle different application states.
3+
With the provided application events the user can handle launch, resume, suspend and exit states or provide logic
4+
related to the screen orientation, uncaught errors and low memory events.
5+
6+
Use the application method `on` to add event listeners.
7+
8+
### Launch Event
9+
<snippet id='application-events-launch-ng'/>
10+
11+
### Suspend Event
12+
<snippet id='application-events-suspend-ng'/>
13+
14+
### Resume Event
15+
<snippet id='application-events-resume-ng'/>
16+
17+
### Exit Event
18+
<snippet id='application-events-exit-ng'/>
19+
20+
### Displayed Event
21+
<snippet id='application-events-displayed-ng'/>
22+
23+
### Low Memory Event
24+
<snippet id='application-events-low-memory-ng'/>
25+
26+
### Orientation Changed Event
27+
<snippet id='application-events-orientation-ng'/>
28+
29+
### Uncaught Error Event
30+
<snippet id='application-events-error-ng'/>
31+

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ let menuLinks = [
55
new Link("Checking Target Platform", "/application/check-target"),
66
new Link("Using Android Specifics", "/application/using-android"),
77
new Link("Using iOS Specifics", "/application/using-ios"),
8+
new Link("Application Events", "/application/application-events")
89
];
910

1011
@Component({

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { ApplicationExamplesComponent } from "./application-examples.component";
55
import { AppCheckingTargetExampleComponent } from "./app-checking-target/app-checking-target.component";
66
import { AppUsingAndroidExampleComponent } from "./app-using-android-specifics/app-using-android-specifics.component";
77
import { AppUsingIosExampleComponent } from "./app-using-ios-specifics/app-using-ios-specifics.component";
8+
import { ApplicationEventsComponent } from "./application-events/application-events.component";
89
import { TitleAndNavButtonModule } from "../../directives/title-and-nav-button.module";
910

1011
export const routerConfig = [
@@ -26,6 +27,11 @@ export const routerConfig = [
2627
path: "using-ios",
2728
component: AppUsingIosExampleComponent,
2829
data: { title: "Using iOS Specifics" }
30+
},
31+
{
32+
path: "application-events",
33+
component: ApplicationEventsComponent,
34+
data: { title: "Application Events" }
2935
}
3036
];
3137

0 commit comments

Comments
 (0)