Skip to content

Commit 26903e0

Browse files
committed
Merge branch 'image-example'
2 parents 8dbfe76 + 430e25c commit 26903e0

File tree

6 files changed

+154
-2
lines changed

6 files changed

+154
-2
lines changed
9.62 KB
Loading

ng-sample/app/app.css

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,21 @@ button {
2424

2525
.even {
2626
background-color: lightseagreen;
27+
}
28+
29+
.btn {
30+
horizontal-align: stretch;
31+
text-align: center;
32+
color:#3F60F9;
33+
}
34+
35+
.btn-primary {
36+
background-color: #3F60F9;
37+
color: #fff;
38+
padding: 10px 20px;
39+
}
40+
41+
.input {
42+
margin: 30px;
43+
color:#444;
2744
}
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
import {Component} from 'angular2/core';
2+
3+
/* IMPORTANT
4+
In order to test out the full image example, to fix the App Transport Security error in iOS 9, you will need to follow this after adding the iOS platform:
5+
6+
https://blog.nraboy.com/2015/12/fix-ios-9-app-transport-security-issues-in-nativescript/
7+
*/
8+
9+
@Component({
10+
selector: 'image-test',
11+
template: `
12+
<StackLayout horizontalAlignment="center">
13+
<Image [src]="currentImage" width="300" height="300"></Image>
14+
<GridLayout columns="*, *" rows="auto">
15+
<Button text="Previous" (tap)="changeImage(-1)" row="0" col="0" cssClass="btn"></Button>
16+
<Button text="Next" (tap)="changeImage(1)" row="0" col="1" cssClass="btn"></Button>
17+
</GridLayout>
18+
19+
<TextField #url hint="Enter URL to any image" cssClass="input"></TextField>
20+
<Button text="Add Image" (tap)='addImage($event, url.text)' cssClass="btn-primary"></Button>
21+
</StackLayout>
22+
`
23+
})
24+
export class ImageTest {
25+
26+
public currentImage: string;
27+
private images: Array<string> = [
28+
'res://300x300.jpg',
29+
'~/examples/image/img/Default.png',
30+
'http://www.codeproject.com/KB/mobile/883465/NativeScript.png'
31+
];
32+
private cnt: number = 0;
33+
34+
constructor() {
35+
this.currentImage = this.images[this.cnt];
36+
}
37+
38+
changeImage(direction: number) {
39+
if (direction > 0) {
40+
this.cnt++;
41+
} else {
42+
this.cnt--;
43+
}
44+
if (this.cnt === this.images.length) {
45+
// start over
46+
this.cnt = 0;
47+
} else if (this.cnt < 0) {
48+
// go to end
49+
this.cnt = this.images.length - 1;
50+
}
51+
this.currentImage = this.images[this.cnt];
52+
}
53+
54+
addImage(e: any, name: string): void {
55+
if (name.indexOf('http') === -1) {
56+
alert(`Must be a valid url to an image starting with 'http'!`);
57+
} else {
58+
this.images.push(name);
59+
this.currentImage = this.images[this.images.length - 1];
60+
}
61+
}
62+
}
20.3 KB
Loading
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
import {Component, Input} from 'angular2/core';
2+
3+
class DataItem {
4+
constructor(public id: number, public name: string) { }
5+
}
6+
7+
@Component({
8+
selector: 'item-component',
9+
template: `
10+
<StackLayout [class.odd]="odd" [class.even]="even">
11+
<Label [text]='"id: " + data.id'></Label>
12+
<Label [text]='"name: " + data.name'></Label>
13+
</StackLayout>
14+
`
15+
})
16+
export class ItemComponent {
17+
@Input() data: DataItem;
18+
@Input() odd: boolean;
19+
@Input() even: boolean;
20+
constructor() { }
21+
}
22+
23+
@Component({
24+
selector: 'list-test',
25+
directives: [ItemComponent],
26+
template: `
27+
<GridLayout rows="auto, *, auto">
28+
<Label row="0" text="-==START==-" fontSize="20"></Label>
29+
<GridLayout row="1">
30+
<ListView [items]="myItems" (itemTap)="onItemTap($event)">
31+
<item-template>
32+
<template #item="item" #i="index" #odd="odd" #even="even">
33+
<StackLayout [class.odd]="odd" [class.even]="even">
34+
<Label [text]='"index: " + i'></Label>
35+
<Label [text]='"[" + item.id +"] " + item.name'></Label>
36+
</StackLayout>
37+
</template>
38+
</item-template>
39+
</ListView>
40+
</GridLayout>
41+
<Label row="2" text="-==END==-" fontSize="20"></Label>
42+
</GridLayout>
43+
`
44+
// TEMPLATE WITH COMPONENT
45+
// <template #item="item" #i="index" #odd="odd" #even="even">
46+
// <item-component [data]="item" [odd]='odd' [even]='even'></item-component>
47+
// </template>
48+
49+
// IN-PLACE TEMPLATE
50+
// <template #item="item" #i="index" #odd="odd" #even="even">
51+
// <StackLayout [class.odd]="odd" [class.even]="even">
52+
// <Label [text]='"index: " + i'></Label>
53+
// <Label [text]='"[" + item.id +"]" + item.name'></Label>
54+
// </StackLayout>
55+
// </template>
56+
})
57+
export class ListTest {
58+
public myItems: Array<DataItem>;
59+
60+
constructor() {
61+
this.myItems = [];
62+
for (var i = 0; i < 30; i++) {
63+
this.myItems.push(new DataItem(i, "data item " + i));
64+
}
65+
}
66+
67+
public onItemTap(args) {
68+
console.log("------------------------ ItemTapped: " + args.index);
69+
}
70+
}
71+

ng-sample/app/main-page.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ import {nativeScriptBootstrap} from './nativescript-angular/application';
77
// import {Benchmark} from './performance/benchmark';
88
// import {RendererTest} from './examples/renderer-test';
99
// import {ListTest} from './examples/list/list-test';
10-
import {ListTestAsync} from './examples/list/list-test-async';
10+
// import {ListTestAsync} from './examples/list/list-test-async';
11+
import {ImageTest} from './examples/image/image-test';
1112

1213
export function createPage() {
1314
var page = new Page();
@@ -21,7 +22,8 @@ export function createPage() {
2122
// nativeScriptBootstrap(Benchmark, []).then((appRef) => {
2223
// nativeScriptBootstrap(RendererTest, []).then((appRef) => {
2324
// nativeScriptBootstrap(ListTest, []).then((appRef) => {
24-
nativeScriptBootstrap(ListTestAsync, []).then((appRef) => {
25+
// nativeScriptBootstrap(ListTestAsync, []).then((appRef) => {
26+
nativeScriptBootstrap(ImageTest, []).then((appRef) => {
2527
profiling.stop('ng-bootstrap');
2628
console.log('ANGULAR BOOTSTRAP DONE.');
2729
}, (err) =>{

0 commit comments

Comments
 (0)