Skip to content

adding extended example, which shows how to use ActivityIndicator dur… #254

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

Merged
merged 1 commit into from
Jan 12, 2018
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
15 changes: 15 additions & 0 deletions app/App_Resources/iOS/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -48,5 +48,20 @@
<key>NSAllowsArbitraryLoads</key>
<true/>
</dict>
<key>NSAppTransportSecurity</key>
<dict>
<key>NSExceptionDomains</key>
<dict>
<key>fakeresponse.com</key>
<dict>
<key>NSIncludesSubdomains</key>
<true/>
<key>NSTemporaryExceptionAllowsInsecureHTTPLoads</key>
<true/>
<key>NSTemporaryExceptionMinimumTLSVersion</key>
<string>TLSv1.1</string>
</dict>
</dict>
</dict>
</dict>
</plist>
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ import { Component, ChangeDetectionStrategy } from "@angular/core";
import { Link } from "./../../link";

let menuLinks = [
new Link("Set busy property", "/activity-indicator/setting-busy")
new Link("Set busy property", "/activity-indicator/setting-busy"),
new Link("Set busy property(during HTTP Request)", "/activity-indicator/setting-busy-http-request")
];

@Component({
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import { NgModule, NO_ERRORS_SCHEMA } from "@angular/core";
import { NativeScriptRouterModule } from "nativescript-angular/router";
import { NativeScriptCommonModule } from "nativescript-angular/common";
import { NativeScriptHttpClientModule } from "nativescript-angular/http-client";
import { ActivityIndicatorExamplesComponent } from "./activity-indicator-examples.component";
import { SettingBusyComponent } from "./setting-busy/setting-busy.component";
import { SettingBusyHttpRequestComponent } from "./setting-busy-http-request/setting-busy-http-request.component";
import { TitleAndNavButtonModule } from "../../directives/title-and-nav-button.module";

export const routerConfig = [
Expand All @@ -14,6 +16,11 @@ export const routerConfig = [
path: "setting-busy",
component: SettingBusyComponent,
data: { title: "Set busy property" }
},
{
path: "setting-busy-http-request",
component: SettingBusyHttpRequestComponent,
data: { title: "Set busy property(during HTTP Request)" }
}
];

Expand All @@ -23,11 +30,13 @@ export const routerConfig = [
TitleAndNavButtonModule,
NativeScriptCommonModule,
NativeScriptRouterModule,
NativeScriptHttpClientModule,
NativeScriptRouterModule.forChild(routerConfig)
],
declarations: [
ActivityIndicatorExamplesComponent,
SettingBusyComponent
SettingBusyComponent,
SettingBusyHttpRequestComponent
]
})

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
Extended example, desmostrating how to use ActivityIndicator during HTTP request

Setting an activity indicator in the HTML:
<snippet id='activity-indicator-setting-busy-html'/>

Setting an activity indicator’s `busy` property value:
<snippet id='activity-indicator-setting-busy-code'/>
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<GridLayout sdkExampleTitle sdkToggleNavButton rows=" auto auto, auto, auto, auto" columns="*, 2*">
<!-- >> activity-indicator-setting-busy-html -->
<Label class="p-15" row="0" col="0" colSpan="2" textAlignment="center" text="The response of the HTTP request will be returned with 5 sec. delay." textWrap="true"></Label>

<Label class="p-15" row="1" col="0" text="IP" textWrap="true"></Label>
<Label class="p-15" row="2" col="0" text="Status" textWrap="true"></Label>
<Label class="p-15" row="3" col="0" text="Slept" textWrap="true"></Label>
<Label class="p-15" row="4" col="0" text="Response" textWrap="true"></Label>

<Label class="p-15" row="1" col="1" [text]="originatingIp" textWrap="true"></Label>
<Label class="p-15" row="2" col="1" [text]="status" textWrap="true"></Label>
<Label class="p-15" row="3" col="1" text="{{ slept + ' seconds'}}" textWrap="true"></Label>
<Label class="p-15" row="4" col="1" [text]="response" textWrap="true"></Label>

<ActivityIndicator row="0" rowSpan="5" colSpan="2" #activityIndicator [busy]="isBusy" class="activity-indicator"></ActivityIndicator>
<!-- << activity-indicator-setting-busy-html -->
</GridLayout>
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
// >> activity-indicator-setting-busy-code
import { Component, AfterViewInit } from "@angular/core";
import { HttpClient, HttpHeaders, HttpResponse } from "@angular/common/http";

@Component({
moduleId: module.id,
templateUrl: "./setting-busy-http-request.component.html"
})
export class SettingBusyHttpRequestComponent implements AfterViewInit {
public originatingIp = "";
public status = "";
public slept = "_";
public response = "";
public isBusy = true;
private serverUrl = "http://www.fakeresponse.com/api/?sleep=5";

constructor(private http: HttpClient) {}

ngAfterViewInit() {
let headers = this.createRequestHeader();
this.http.get(this.serverUrl, { headers: headers })
.subscribe(
data => {
this.originatingIp = data["meta"]["originating_ip"];
this.status = data["status"];
this.slept = data["slept"];
this.response = data["response"];
this.isBusy = false;
},
err => {
console.log("Error occured.");
console.log(err);
}
);
}

private createRequestHeader() {
let headers = new HttpHeaders();
// set headers here e.g.
headers.append("AuthKey", "my-key");
headers.append("AuthToken", "my-token");
headers.append("Content-Type", "application/json");

return headers;
}
}
// << activity-indicator-setting-busy-code