mirror of
https://github.com/NativeScript/NativeScript.git
synced 2025-08-16 11:42:04 +08:00
Common UI module implemented & used in cuteness.io
This commit is contained in:
@ -473,6 +473,7 @@
|
|||||||
<TypeScriptCompile Include="ui\action-bar\action-bar.ios.ts">
|
<TypeScriptCompile Include="ui\action-bar\action-bar.ios.ts">
|
||||||
<DependentUpon>action-bar.d.ts</DependentUpon>
|
<DependentUpon>action-bar.d.ts</DependentUpon>
|
||||||
</TypeScriptCompile>
|
</TypeScriptCompile>
|
||||||
|
<TypeScriptCompile Include="ui\ui.d.ts" />
|
||||||
<TypeScriptCompile Include="ui\html-view\html-view-common.ts" />
|
<TypeScriptCompile Include="ui\html-view\html-view-common.ts" />
|
||||||
<TypeScriptCompile Include="ui\html-view\html-view.android.ts" />
|
<TypeScriptCompile Include="ui\html-view\html-view.android.ts" />
|
||||||
<TypeScriptCompile Include="ui\html-view\html-view.d.ts" />
|
<TypeScriptCompile Include="ui\html-view\html-view.d.ts" />
|
||||||
@ -688,6 +689,7 @@
|
|||||||
<DependentUpon>text-field.d.ts</DependentUpon>
|
<DependentUpon>text-field.d.ts</DependentUpon>
|
||||||
</TypeScriptCompile>
|
</TypeScriptCompile>
|
||||||
<TypeScriptCompile Include="ui\text-view\text-view.d.ts" />
|
<TypeScriptCompile Include="ui\text-view\text-view.d.ts" />
|
||||||
|
<TypeScriptCompile Include="ui\ui.ts" />
|
||||||
<TypeScriptCompile Include="utils\android_constants.ts" />
|
<TypeScriptCompile Include="utils\android_constants.ts" />
|
||||||
<TypeScriptCompile Include="utils\module-merge.ts" />
|
<TypeScriptCompile Include="utils\module-merge.ts" />
|
||||||
<TypeScriptCompile Include="utils\utils.android.ts">
|
<TypeScriptCompile Include="utils\utils.android.ts">
|
||||||
@ -1746,6 +1748,7 @@
|
|||||||
<Content Include="ui\html-view\package.json">
|
<Content Include="ui\html-view\package.json">
|
||||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||||
</Content>
|
</Content>
|
||||||
|
<Content Include="ui\package.json" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<None Include="build\tslint.json" />
|
<None Include="build\tslint.json" />
|
||||||
|
@ -1,10 +1,10 @@
|
|||||||
import pages = require("ui/page");
|
import {Page} from "ui";
|
||||||
import observable = require("data/observable");
|
import {EventData as ObservableEventData} from "data/observable";
|
||||||
|
|
||||||
// Event handler for Page "navigatedTo" event attached in details-page.xml
|
// Event handler for Page "navigatedTo" event attached in details-page.xml
|
||||||
export function pageNavigatedTo(args: observable.EventData) {
|
export function pageNavigatedTo(args: ObservableEventData) {
|
||||||
// Get the event sender
|
// Get the event sender
|
||||||
var page = <pages.Page>args.object;
|
var page = <Page>args.object;
|
||||||
|
|
||||||
page.bindingContext = page.navigationContext;
|
page.bindingContext = page.navigationContext;
|
||||||
}
|
}
|
||||||
|
@ -1,34 +1,31 @@
|
|||||||
import observable = require("data/observable");
|
import {EventData as ObservableEventData} from "data/observable";
|
||||||
import pages = require("ui/page");
|
import {Page, ItemEventData, topmost as topmostFrame, ItemEventData as ListViewItemEventData} from "ui";
|
||||||
import frames = require("ui/frame");
|
import {AppViewModel} from "./reddit-app-view-model";
|
||||||
import listView = require("ui/list-view");
|
|
||||||
|
|
||||||
import redditAppViewModel = require("./reddit-app-view-model");
|
var appViewModel = new AppViewModel();
|
||||||
|
|
||||||
var appViewModel = new redditAppViewModel.AppViewModel();
|
|
||||||
|
|
||||||
// Event handler for Page "loaded" event attached in main-page.xml
|
// Event handler for Page "loaded" event attached in main-page.xml
|
||||||
export function pageLoaded(args: observable.EventData) {
|
export function pageLoaded(args: ObservableEventData) {
|
||||||
// Get the event sender
|
// Get the event sender
|
||||||
var page = <pages.Page>args.object;
|
var page = <Page>args.object;
|
||||||
|
|
||||||
page.bindingContext = appViewModel;
|
page.bindingContext = appViewModel;
|
||||||
|
|
||||||
// Enable platform specific feature (in this case Android page caching)
|
// Enable platform specific feature (in this case Android page caching)
|
||||||
if (frames.topmost().android) {
|
if (topmostFrame().android) {
|
||||||
frames.topmost().android.cachePagesOnNavigate = true;
|
topmostFrame().android.cachePagesOnNavigate = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export function listViewItemTap(args: listView.ItemEventData) {
|
export function listViewItemTap(args: ListViewItemEventData) {
|
||||||
// Navigate to the details page with context set to the data item for specified index
|
// Navigate to the details page with context set to the data item for specified index
|
||||||
frames.topmost().navigate({
|
topmostFrame().navigate({
|
||||||
moduleName: "./details-page",
|
moduleName: "./details-page",
|
||||||
context: appViewModel.redditItems.getItem(args.index)
|
context: appViewModel.redditItems.getItem(args.index)
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
export function listViewLoadMoreItems(args: observable.EventData) {
|
export function listViewLoadMoreItems(args: ObservableEventData) {
|
||||||
// Increase model items length with model items loadSize property value
|
// Increase model items length with model items loadSize property value
|
||||||
appViewModel.redditItems.length += appViewModel.redditItems.loadSize;
|
appViewModel.redditItems.length += appViewModel.redditItems.loadSize;
|
||||||
}
|
}
|
||||||
|
@ -1,53 +1,49 @@
|
|||||||
import imageSource = require("image-source");
|
import {ImageSource, fromFile as imageSourceFromFile} from "image-source";
|
||||||
import virtualArray = require("data/virtual-array");
|
import {VirtualArray, ItemsLoading as virtualArrayItemsLoadingData} from "data/virtual-array";
|
||||||
import http = require("http");
|
import {Observable} from "data/observable";
|
||||||
import observable = require("data/observable");
|
import {Cache as ImageCache} from "ui/image-cache";
|
||||||
import imageCache = require("ui/image-cache");
|
|
||||||
|
|
||||||
import redditModel = require("./reddit-model");
|
import {Data as RedditData} from "./reddit-model";
|
||||||
import redditViewModel = require("./reddit-item-view-model");
|
import {RedditViewModel} from "./reddit-item-view-model";
|
||||||
|
|
||||||
var aboutText = "Cuteness is a proof of concept app demonstrating the Telerik's NativeScript for writing native mobile applications using JavaScript.";
|
var aboutText = "Cuteness is a proof of concept app demonstrating the Telerik's NativeScript for writing native mobile applications using JavaScript.";
|
||||||
export var defaultThumbnailImageSource = imageSource.fromFile("~/res/reddit-logo.png");
|
export var defaultThumbnailImageSource = imageSourceFromFile("~/res/reddit-logo.png");
|
||||||
export var defaultNoThumbnailImageSource = imageSource.fromFile("~/res/no-image.png");
|
export var defaultNoThumbnailImageSource = imageSourceFromFile("~/res/no-image.png");
|
||||||
|
|
||||||
var redditUrl = "http://www.reddit.com/r/aww.json?limit=";
|
var redditUrl = "http://www.reddit.com/r/aww.json?limit=";
|
||||||
var after: string;
|
var after: string;
|
||||||
var ISSCROLLING = "isLoading";
|
var ISSCROLLING = "isLoading";
|
||||||
|
|
||||||
// initialize the image cache for the main list
|
// initialize the image cache for the main list
|
||||||
export var cache = new imageCache.Cache();
|
export var cache = new ImageCache();
|
||||||
cache.placeholder = defaultThumbnailImageSource;
|
cache.placeholder = defaultThumbnailImageSource;
|
||||||
cache.maxRequests = 5;
|
cache.maxRequests = 5;
|
||||||
|
|
||||||
export class AppViewModel extends observable.Observable {
|
export class AppViewModel extends Observable {
|
||||||
|
|
||||||
private _redditItems: virtualArray.VirtualArray<redditViewModel.RedditViewModel>;
|
private _redditItems: VirtualArray<RedditViewModel>;
|
||||||
get redditItems(): virtualArray.VirtualArray<redditViewModel.RedditViewModel> {
|
get redditItems(): VirtualArray<RedditViewModel> {
|
||||||
if (!this._redditItems) {
|
if (!this._redditItems) {
|
||||||
this._redditItems = new virtualArray.VirtualArray<redditViewModel.RedditViewModel>(1000);
|
this._redditItems = new VirtualArray<RedditViewModel>(1000);
|
||||||
this._redditItems.loadSize = 50;
|
this._redditItems.loadSize = 50;
|
||||||
this._redditItems.on(virtualArray.VirtualArray.itemsLoadingEvent, (args: virtualArray.ItemsLoading) => {
|
this._redditItems.on(VirtualArray.itemsLoadingEvent, (args: virtualArrayItemsLoadingData) => {
|
||||||
|
|
||||||
http.getJSON<redditModel.Data>(redditUrl + args.count +
|
fetch(redditUrl + args.count + (after ? "&after=" + after : "")).then<RedditData>(response=> response.json()).then(result => {
|
||||||
(after ? "&after=" + after : "")).then(result => {
|
|
||||||
|
|
||||||
var itemsToLoad = result.data.children.map(i=> {
|
var itemsToLoad = result.data.children.map(i=> {
|
||||||
return new redditViewModel.RedditViewModel(i.data);
|
return new RedditViewModel(i.data);
|
||||||
});
|
|
||||||
|
|
||||||
this._redditItems.load(args.index, itemsToLoad);
|
|
||||||
|
|
||||||
var lastItem = itemsToLoad[itemsToLoad.length - 1];
|
|
||||||
if (lastItem) {
|
|
||||||
after = itemsToLoad[itemsToLoad.length - 1].source.name;
|
|
||||||
}
|
|
||||||
|
|
||||||
}, (e) => { console.log(e.message) })
|
|
||||||
.catch(function(e) {
|
|
||||||
setTimeout(function() { throw e; });
|
|
||||||
});
|
});
|
||||||
;
|
|
||||||
|
this._redditItems.load(args.index, itemsToLoad);
|
||||||
|
|
||||||
|
var lastItem = itemsToLoad[itemsToLoad.length - 1];
|
||||||
|
if (lastItem) {
|
||||||
|
after = itemsToLoad[itemsToLoad.length - 1].source.name;
|
||||||
|
}
|
||||||
|
|
||||||
|
}).catch(e => {
|
||||||
|
setTimeout(() => { throw e; });
|
||||||
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -69,7 +65,7 @@ export class AppViewModel extends observable.Observable {
|
|||||||
cache.enableDownload();
|
cache.enableDownload();
|
||||||
}
|
}
|
||||||
|
|
||||||
this.notify({ object: this, eventName: observable.Observable.propertyChangeEvent, propertyName: ISSCROLLING, value: value });
|
this.notify({ object: this, eventName: Observable.propertyChangeEvent, propertyName: ISSCROLLING, value: value });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -77,11 +73,11 @@ export class AppViewModel extends observable.Observable {
|
|||||||
return aboutText;
|
return aboutText;
|
||||||
}
|
}
|
||||||
|
|
||||||
get defaultThumbnailImageSource(): imageSource.ImageSource {
|
get defaultThumbnailImageSource(): ImageSource {
|
||||||
return defaultThumbnailImageSource;
|
return defaultThumbnailImageSource;
|
||||||
}
|
}
|
||||||
|
|
||||||
get defaultNoThumbnailImageSource(): imageSource.ImageSource {
|
get defaultNoThumbnailImageSource(): ImageSource {
|
||||||
return defaultNoThumbnailImageSource;
|
return defaultNoThumbnailImageSource;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,20 +1,20 @@
|
|||||||
import observable = require("data/observable");
|
import {Observable} from "data/observable";
|
||||||
import imageSource = require("image-source");
|
import {ImageSource, fromFile as imageSourceFromFile, fromUrl as imageSourceFromUrl} from "image-source";
|
||||||
|
|
||||||
import redditModel = require("./reddit-model");
|
import {ItemData} from "./reddit-model";
|
||||||
import redditAppViewModel = require("./reddit-app-view-model");
|
import {defaultThumbnailImageSource, defaultNoThumbnailImageSource, cache} from "./reddit-app-view-model";
|
||||||
|
|
||||||
var firstThumbnailImageSource = imageSource.fromFile("~/res/first-image.png");
|
var firstThumbnailImageSource = imageSourceFromFile("~/res/first-image.png");
|
||||||
var defaultImageSource = imageSource.fromFile("~/res/reddit-logo-transparent.png");
|
var defaultImageSource = imageSourceFromFile("~/res/reddit-logo-transparent.png");
|
||||||
|
|
||||||
var ISLOADING = "isLoading";
|
var ISLOADING = "isLoading";
|
||||||
var THUMBNAIL_IMAGE = "thumbnailImage";
|
var THUMBNAIL_IMAGE = "thumbnailImage";
|
||||||
var IMAGE_SOURCE = "imageSource";
|
var IMAGE_SOURCE = "imageSource";
|
||||||
|
|
||||||
export class RedditViewModel extends observable.Observable {
|
export class RedditViewModel extends Observable {
|
||||||
|
|
||||||
private _source: redditModel.ItemData;
|
private _source: ItemData;
|
||||||
constructor(source: redditModel.ItemData) {
|
constructor(source: ItemData) {
|
||||||
super();
|
super();
|
||||||
|
|
||||||
this._source = source;
|
this._source = source;
|
||||||
@ -27,7 +27,7 @@ export class RedditViewModel extends observable.Observable {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
get source(): redditModel.ItemData {
|
get source(): ItemData {
|
||||||
return this._source;
|
return this._source;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -38,13 +38,13 @@ export class RedditViewModel extends observable.Observable {
|
|||||||
set isLoading(value: boolean) {
|
set isLoading(value: boolean) {
|
||||||
if (this._isLoading !== value) {
|
if (this._isLoading !== value) {
|
||||||
this._isLoading = value;
|
this._isLoading = value;
|
||||||
this.notify({ object: this, eventName: observable.Observable.propertyChangeEvent, propertyName: ISLOADING, value: value });
|
this.notify({ object: this, eventName: Observable.propertyChangeEvent, propertyName: ISLOADING, value: value });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
get thumbnailImage(): imageSource.ImageSource {
|
get thumbnailImage(): ImageSource {
|
||||||
if (!this._source) {
|
if (!this._source) {
|
||||||
return redditAppViewModel.defaultThumbnailImageSource;
|
return defaultThumbnailImageSource;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this._source.title === "reddit 101") {
|
if (this._source.title === "reddit 101") {
|
||||||
@ -54,30 +54,30 @@ export class RedditViewModel extends observable.Observable {
|
|||||||
var url = this._source.thumbnail;
|
var url = this._source.thumbnail;
|
||||||
|
|
||||||
if (!_isValidImageUrl(url)) {
|
if (!_isValidImageUrl(url)) {
|
||||||
return redditAppViewModel.defaultNoThumbnailImageSource
|
return defaultNoThumbnailImageSource
|
||||||
}
|
}
|
||||||
|
|
||||||
var image = redditAppViewModel.cache.get(url);
|
var image = cache.get(url);
|
||||||
if (image) {
|
if (image) {
|
||||||
return image;
|
return image;
|
||||||
}
|
}
|
||||||
|
|
||||||
this.isLoading = true;
|
this.isLoading = true;
|
||||||
redditAppViewModel.cache.push({
|
cache.push({
|
||||||
key: url,
|
key: url,
|
||||||
url: url,
|
url: url,
|
||||||
completed: (image: any, key: string) => {
|
completed: (image: any, key: string) => {
|
||||||
if (url === key) {
|
if (url === key) {
|
||||||
this.isLoading = false;
|
this.isLoading = false;
|
||||||
this.notify({ object: this, eventName: observable.Observable.propertyChangeEvent, propertyName: THUMBNAIL_IMAGE, value: image });
|
this.notify({ object: this, eventName: Observable.propertyChangeEvent, propertyName: THUMBNAIL_IMAGE, value: image });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
return redditAppViewModel.defaultThumbnailImageSource;
|
return defaultThumbnailImageSource;
|
||||||
}
|
}
|
||||||
|
|
||||||
get imageSource(): imageSource.ImageSource {
|
get imageSource(): ImageSource {
|
||||||
if (this._source) {
|
if (this._source) {
|
||||||
var url;
|
var url;
|
||||||
try {
|
try {
|
||||||
@ -91,9 +91,9 @@ export class RedditViewModel extends observable.Observable {
|
|||||||
|
|
||||||
this.isLoading = true;
|
this.isLoading = true;
|
||||||
|
|
||||||
imageSource.fromUrl(url).then(result => {
|
imageSourceFromUrl(url).then(result => {
|
||||||
this.isLoading = false;
|
this.isLoading = false;
|
||||||
this.notify({ object: this, eventName: observable.Observable.propertyChangeEvent, propertyName: IMAGE_SOURCE, value: result });
|
this.notify({ object: this, eventName: Observable.propertyChangeEvent, propertyName: IMAGE_SOURCE, value: result });
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
2
ui/package.json
Normal file
2
ui/package.json
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
{ "name" : "ui",
|
||||||
|
"main" : "ui.js" }
|
56
ui/ui.d.ts
vendored
Normal file
56
ui/ui.d.ts
vendored
Normal file
@ -0,0 +1,56 @@
|
|||||||
|
/**
|
||||||
|
* Contains the all UI classes.
|
||||||
|
*/
|
||||||
|
declare module "ui" {
|
||||||
|
export * from "ui/action-bar";
|
||||||
|
export * from "ui/activity-indicator";
|
||||||
|
export * from "ui/builder";
|
||||||
|
export * from "ui/button";
|
||||||
|
export * from "ui/content-view";
|
||||||
|
export * from "ui/core/bindable";
|
||||||
|
export * from "ui/core/control-state-change";
|
||||||
|
export * from "ui/core/dependency-observable";
|
||||||
|
export * from "ui/core/proxy";
|
||||||
|
export * from "ui/core/view";
|
||||||
|
export * from "ui/core/weak-event-listener";
|
||||||
|
export * from "ui/dialogs";
|
||||||
|
export * from "ui/date-picker";
|
||||||
|
export * from "ui/editable-text-base";
|
||||||
|
export * from "ui/enums";
|
||||||
|
export * from "ui/frame";
|
||||||
|
export * from "ui/gestures";
|
||||||
|
export * from "ui/html-view";
|
||||||
|
export * from "ui/image";
|
||||||
|
export * from "ui/image-cache";
|
||||||
|
export * from "ui/label";
|
||||||
|
export * from "ui/layouts/layout";
|
||||||
|
export * from "ui/layouts/absolute-layout";
|
||||||
|
export * from "ui/layouts/dock-layout";
|
||||||
|
export * from "ui/layouts/grid-layout";
|
||||||
|
export * from "ui/layouts/stack-layout";
|
||||||
|
export * from "ui/layouts/wrap-layout";
|
||||||
|
export * from "ui/list-picker";
|
||||||
|
export * from "ui/list-view";
|
||||||
|
export * from "ui/page";
|
||||||
|
export * from "ui/placeholder";
|
||||||
|
export * from "ui/progress";
|
||||||
|
export * from "ui/repeater";
|
||||||
|
export * from "ui/scroll-view";
|
||||||
|
export * from "ui/search-bar";
|
||||||
|
export * from "ui/segmented-bar";
|
||||||
|
export * from "ui/slider";
|
||||||
|
export * from "ui/styling";
|
||||||
|
export * from "ui/styling/background";
|
||||||
|
export * from "ui/styling/css-selector";
|
||||||
|
export * from "ui/styling/font";
|
||||||
|
export * from "ui/styling/style-property";
|
||||||
|
export * from "ui/styling/stylers";
|
||||||
|
export * from "ui/styling/visual-state-constants";
|
||||||
|
export * from "ui/switch";
|
||||||
|
export * from "ui/tab-view";
|
||||||
|
export * from "ui/text-base";
|
||||||
|
export * from "ui/text-field";
|
||||||
|
export * from "ui/text-view";
|
||||||
|
export * from "ui/time-picker";
|
||||||
|
export * from "ui/web-view";
|
||||||
|
}
|
51
ui/ui.ts
Normal file
51
ui/ui.ts
Normal file
@ -0,0 +1,51 @@
|
|||||||
|
export * from "ui/action-bar";
|
||||||
|
export * from "ui/activity-indicator";
|
||||||
|
export * from "ui/builder";
|
||||||
|
export * from "ui/button";
|
||||||
|
export * from "ui/content-view";
|
||||||
|
export * from "ui/core/bindable";
|
||||||
|
export * from "ui/core/control-state-change";
|
||||||
|
export * from "ui/core/dependency-observable";
|
||||||
|
export * from "ui/core/proxy";
|
||||||
|
export * from "ui/core/view";
|
||||||
|
export * from "ui/core/weak-event-listener";
|
||||||
|
export * from "ui/dialogs";
|
||||||
|
export * from "ui/date-picker";
|
||||||
|
export * from "ui/editable-text-base";
|
||||||
|
export * from "ui/enums";
|
||||||
|
export * from "ui/frame";
|
||||||
|
export * from "ui/gestures";
|
||||||
|
export * from "ui/html-view";
|
||||||
|
export * from "ui/image";
|
||||||
|
export * from "ui/image-cache";
|
||||||
|
export * from "ui/label";
|
||||||
|
export * from "ui/layouts/layout";
|
||||||
|
export * from "ui/layouts/absolute-layout";
|
||||||
|
export * from "ui/layouts/dock-layout";
|
||||||
|
export * from "ui/layouts/grid-layout";
|
||||||
|
export * from "ui/layouts/stack-layout";
|
||||||
|
export * from "ui/layouts/wrap-layout";
|
||||||
|
export * from "ui/list-picker";
|
||||||
|
export * from "ui/list-view";
|
||||||
|
export * from "ui/page";
|
||||||
|
export * from "ui/placeholder";
|
||||||
|
export * from "ui/progress";
|
||||||
|
export * from "ui/repeater";
|
||||||
|
export * from "ui/scroll-view";
|
||||||
|
export * from "ui/search-bar";
|
||||||
|
export * from "ui/segmented-bar";
|
||||||
|
export * from "ui/slider";
|
||||||
|
export * from "ui/styling";
|
||||||
|
export * from "ui/styling/background";
|
||||||
|
export * from "ui/styling/css-selector";
|
||||||
|
export * from "ui/styling/font";
|
||||||
|
export * from "ui/styling/style-property";
|
||||||
|
export * from "ui/styling/stylers";
|
||||||
|
export * from "ui/styling/visual-state-constants";
|
||||||
|
export * from "ui/switch";
|
||||||
|
export * from "ui/tab-view";
|
||||||
|
export * from "ui/text-base";
|
||||||
|
export * from "ui/text-field";
|
||||||
|
export * from "ui/text-view";
|
||||||
|
export * from "ui/time-picker";
|
||||||
|
export * from "ui/web-view";
|
Reference in New Issue
Block a user