Skip to content

Commit 709da19

Browse files
authored
Upgrade to TNS 3.0 (#6)
Closes #4
1 parent a1d1c6a commit 709da19

13 files changed

+428
-293
lines changed

.vscode/tasks.json

+7-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,13 @@
1111
"taskName": "build",
1212
"args": [],
1313
"isBuildCommand": true,
14-
"problemMatcher": ["$tsc", "$tslint5"]
14+
"problemMatcher": [
15+
"$tsc",
16+
{
17+
"base": "$tslint5",
18+
"fileLocation": "relative"
19+
}
20+
]
1521
}
1622
]
1723
}

demo-ng/package.json

+16-16
Original file line numberDiff line numberDiff line change
@@ -5,36 +5,36 @@
55
"repository": "<fill-your-repository-here>",
66
"nativescript": {
77
"id": "com.tangrainc.imageswipedemong",
8-
"tns-android": {
9-
"version": "2.5.0"
10-
},
118
"tns-ios": {
12-
"version": "2.5.0"
9+
"version": "3.0.1"
10+
},
11+
"tns-android": {
12+
"version": "3.0.1"
1313
}
1414
},
1515
"dependencies": {
16-
"@angular/animations": "~4.0.3",
17-
"@angular/common": "~4.0.3",
18-
"@angular/compiler": "~4.0.3",
19-
"@angular/core": "~4.0.3",
20-
"@angular/forms": "~4.0.3",
21-
"@angular/http": "~4.0.3",
22-
"@angular/platform-browser": "~4.0.3",
23-
"@angular/router": "~4.0.3",
24-
"nativescript-angular": "~1.5.2",
16+
"@angular/animations": "~4.1.0",
17+
"@angular/common": "~4.1.0",
18+
"@angular/compiler": "~4.1.0",
19+
"@angular/core": "~4.1.0",
20+
"@angular/forms": "~4.1.0",
21+
"@angular/http": "~4.1.0",
22+
"@angular/platform-browser": "~4.1.0",
23+
"@angular/router": "~4.1.0",
24+
"nativescript-angular": "~3.0.0",
2525
"nativescript-image-swipe": "file:../bin/dist",
2626
"nativescript-theme-core": "~1.0.2",
2727
"reflect-metadata": "~0.1.8",
2828
"rxjs": "~5.3.0",
29-
"tns-core-modules": "~2.5.2",
29+
"tns-core-modules": "~3.0.0",
3030
"zone.js": "~0.8.2"
3131
},
3232
"devDependencies": {
3333
"babel-traverse": "6.24.1",
3434
"babel-types": "6.24.1",
3535
"babylon": "6.17.0",
3636
"lazy": "1.0.11",
37-
"nativescript-dev-typescript": "~0.3.5",
38-
"typescript": "~2.1.6"
37+
"nativescript-dev-typescript": "~0.4.5",
38+
"typescript": "~2.2.0"
3939
}
4040
}

demo/.vscode/launch.json

+41
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
{
2+
"version": "0.2.0",
3+
"configurations": [
4+
{
5+
"name": "Launch on iOS",
6+
"type": "nativescript",
7+
"request": "launch",
8+
"platform": "ios",
9+
"appRoot": "${workspaceRoot}",
10+
"sourceMaps": true,
11+
"watch": true
12+
},
13+
{
14+
"name": "Attach on iOS",
15+
"type": "nativescript",
16+
"request": "attach",
17+
"platform": "ios",
18+
"appRoot": "${workspaceRoot}",
19+
"sourceMaps": true,
20+
"watch": false
21+
},
22+
{
23+
"name": "Launch on Android",
24+
"type": "nativescript",
25+
"request": "launch",
26+
"platform": "android",
27+
"appRoot": "${workspaceRoot}",
28+
"sourceMaps": true,
29+
"watch": true
30+
},
31+
{
32+
"name": "Attach on Android",
33+
"type": "nativescript",
34+
"request": "attach",
35+
"platform": "android",
36+
"appRoot": "${workspaceRoot}",
37+
"sourceMaps": true,
38+
"watch": false
39+
}
40+
]
41+
}

demo/package.json

+5-5
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@
66
"nativescript": {
77
"id": "com.tangrainc.imageswipedemo",
88
"tns-ios": {
9-
"version": "2.5.0"
9+
"version": "3.0.1"
1010
},
1111
"tns-android": {
12-
"version": "2.5.0"
12+
"version": "3.0.1"
1313
}
1414
},
1515
"scripts": {
@@ -18,15 +18,15 @@
1818
},
1919
"dependencies": {
2020
"nativescript-image-swipe": "file:../bin/dist",
21-
"tns-core-modules": "2.5.2"
21+
"tns-core-modules": "^3.0.1"
2222
},
2323
"devDependencies": {
2424
"babel-traverse": "6.24.1",
2525
"babel-types": "6.24.1",
2626
"babylon": "6.17.0",
2727
"lazy": "1.0.11",
2828
"nativescript-dev-android-snapshot": "^0.*.*",
29-
"nativescript-dev-typescript": "~0.3.5",
30-
"typescript": "~2.1.0"
29+
"nativescript-dev-typescript": "~0.4.5",
30+
"typescript": "~2.2.0"
3131
}
3232
}

demo/tsconfig.json

+12-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,18 @@
55
"experimentalDecorators": true,
66
"emitDecoratorMetadata": true,
77
"noEmitHelpers": true,
8-
"noEmitOnError": true
8+
"noEmitOnError": true,
9+
"lib": [
10+
"es6",
11+
"dom"
12+
],
13+
"baseUrl": ".",
14+
"paths": {
15+
"*": [
16+
"./node_modules/tns-core-modules/*",
17+
"./node_modules/*"
18+
]
19+
}
920
},
1021
"exclude": [
1122
"node_modules",

gruntfile.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@
4848
cmd: "./node_modules/.bin/tsc --project tsconfig.json --outDir " + localConfig.outDir
4949
},
5050
tslint: {
51-
cmd: "./node_modules/.bin/tslint --project tsconfig.json"
51+
cmd: "./node_modules/.bin/tslint --project tsconfig.json --type-check"
5252
},
5353
npm_publish: {
5454
cmd: "npm publish",

image-swipe-common.ts

+64-80
Original file line numberDiff line numberDiff line change
@@ -1,101 +1,85 @@
1-
import { EventData } from "data/observable";
2-
import { Property, PropertyChangeData, PropertyMetadataSettings } from "ui/core/dependency-observable";
3-
import { PropertyMetadata } from "ui/core/proxy";
4-
import { Cache } from "ui/image-cache";
5-
import { ScrollView } from "ui/scroll-view";
1+
/*! *****************************************************************************
2+
Copyright (c) 2017 Tangra Inc.
63
7-
const IMAGESCROLLER = "ImageScroller";
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
87
9-
function onItemsPropertyChanged(data: PropertyChangeData) {
10-
const imageSwipe = data.object as ImageSwipeBase;
11-
imageSwipe.refresh();
12-
}
8+
http://www.apache.org/licenses/LICENSE-2.0
139
14-
function onPagePropertyChanged(data: PropertyChangeData) {
15-
const imageScroller = data.object as ImageSwipeBase;
16-
imageScroller.loadCurrentPage();
17-
imageScroller.notify({
18-
eventName: ImageSwipeBase.pageChangedEvent,
19-
object: imageScroller,
20-
page: data.newValue
21-
} as PageChangeEventData);
22-
}
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
***************************************************************************** */
16+
import { CoercibleProperty, Property } from "ui/core/view";
17+
import { Cache } from "ui/image-cache";
18+
import { ItemsSource } from "ui/list-picker";
19+
import { ScrollView } from "ui/scroll-view";
20+
import { ImageSwipe as ImageSwipeDefinition } from ".";
2321

24-
export interface PageChangeEventData extends EventData {
25-
eventName: string;
26-
object: ImageSwipeBase;
27-
page: number;
28-
}
22+
export * from "ui/scroll-view";
2923

30-
export abstract class ImageSwipeBase extends ScrollView {
24+
export class ImageSwipeBase extends ScrollView implements ImageSwipeDefinition {
3125
public static pageChangedEvent: string = "pageChanged";
3226

33-
public static itemsProperty = new Property(
34-
"items",
35-
IMAGESCROLLER,
36-
new PropertyMetadata(
37-
undefined,
38-
PropertyMetadataSettings.AffectsLayout,
39-
onItemsPropertyChanged
40-
)
41-
);
42-
43-
public static imageUrlPropertyProperty = new Property(
44-
"imageUrlProperty",
45-
IMAGESCROLLER,
46-
new PropertyMetadata(
47-
"",
48-
PropertyMetadataSettings.AffectsLayout
49-
)
50-
);
51-
52-
public static pageNumberProperty = new Property(
53-
"pageNumber",
54-
IMAGESCROLLER,
55-
new PropertyMetadata(
56-
0,
57-
PropertyMetadataSettings.AffectsLayout,
58-
onPagePropertyChanged
59-
)
60-
);
61-
6227
public static _imageCache: Cache;
63-
// private _itemsChanged: (args: EventData) => void;
6428

65-
get items(): any {
66-
return this._getValue(ImageSwipeBase.itemsProperty);
67-
}
68-
set items(value: any) {
69-
this._setValue(ImageSwipeBase.itemsProperty, value);
70-
}
71-
72-
get imageUrlProperty(): string {
73-
return this._getValue(ImageSwipeBase.imageUrlPropertyProperty);
74-
}
75-
set imageUrlProperty(value: string) {
76-
this._setValue(ImageSwipeBase.imageUrlPropertyProperty, value);
77-
}
78-
79-
get pageNumber(): number {
80-
return this._getValue(ImageSwipeBase.pageNumberProperty);
81-
}
82-
set pageNumber(value: number) {
83-
this._setValue(ImageSwipeBase.pageNumberProperty, value);
84-
}
29+
public items: any[] | ItemsSource;
30+
public pageNumber: number;
31+
public imageUrlProperty: string;
32+
public isItemsSourceIn: boolean;
8533

8634
constructor() {
8735
super();
88-
// this._itemsChanged = (args: EventData) => { this.refresh(); };
8936
if (!ImageSwipeBase._imageCache) {
9037
ImageSwipeBase._imageCache = new Cache();
9138
ImageSwipeBase._imageCache.maxRequests = 3;
9239
}
9340
}
9441

95-
public abstract refresh();
96-
public abstract loadCurrentPage();
97-
9842
public _getDataItem(index: number): any {
99-
return this.items.getItem ? this.items.getItem(index) : this.items[index];
43+
return this.isItemsSourceIn ? (this.items as ItemsSource).getItem(index) : this.items[index];
10044
}
10145
}
46+
47+
export const pageNumberProperty = new CoercibleProperty<ImageSwipeBase, number>({
48+
name: "pageNumber",
49+
defaultValue: 0,
50+
valueConverter: (v) => parseInt(v, 10),
51+
coerceValue: (target, value) => {
52+
const items = target.items;
53+
if (items && items.length !== 0) {
54+
const max = items.length - 1;
55+
if (value < 0) {
56+
value = 0;
57+
}
58+
if (value > max) {
59+
value = max;
60+
}
61+
}
62+
else {
63+
value = null;
64+
}
65+
66+
return value;
67+
}
68+
});
69+
pageNumberProperty.register(ImageSwipeBase);
70+
71+
export const itemsProperty = new Property<ImageSwipeBase, any[] | ItemsSource>({
72+
name: "items",
73+
valueChanged: (target, oldValue, newValue) => {
74+
const getItem = newValue && (newValue as ItemsSource).getItem;
75+
76+
target.isItemsSourceIn = typeof getItem === "function";
77+
}
78+
});
79+
itemsProperty.register(ImageSwipeBase);
80+
81+
export const imageUrlPropertyProperty = new Property<ImageSwipeBase, string>({
82+
name: "imageUrlProperty",
83+
defaultValue: ""
84+
});
85+
imageUrlPropertyProperty.register(ImageSwipeBase);

0 commit comments

Comments
 (0)