From 3d0882ffa7857a7f6468b67ac0956f3dad7f93e0 Mon Sep 17 00:00:00 2001 From: Rossen Hristov Date: Wed, 15 Apr 2015 16:27:27 +0300 Subject: [PATCH 01/12] Rewrote image-cache to use the native image caching features, i.e. LruCache and NSCache. --- apps/cuteness.io/reddit-item-view-model.ts | 13 ++++-- .../tests/ui/image-cache/image-cache-tests.ts | 12 +++--- ui/image-cache/image-cache-common.ts | 42 ++++++++---------- ui/image-cache/image-cache.android.ts | 43 +++++++++++++++---- ui/image-cache/image-cache.d.ts | 8 ++-- ui/image-cache/image-cache.ios.ts | 34 ++++++++++++--- 6 files changed, 101 insertions(+), 51 deletions(-) diff --git a/apps/cuteness.io/reddit-item-view-model.ts b/apps/cuteness.io/reddit-item-view-model.ts index 9004c30e1..3c36bc9ed 100644 --- a/apps/cuteness.io/reddit-item-view-model.ts +++ b/apps/cuteness.io/reddit-item-view-model.ts @@ -50,7 +50,11 @@ export class RedditViewModel extends observable.Observable { } else if (redditAppViewModel.cache) { var url = this._source.thumbnail; - var imgSource = redditAppViewModel.cache.get(url); + var imgSource: imageSource.ImageSource; + var image = redditAppViewModel.cache.get(url); + if (image) { + imgSource = imageSource.fromNativeSource(image); + } if (imgSource) { this._thumbnailImageSource = imgSource; @@ -61,11 +65,12 @@ export class RedditViewModel extends observable.Observable { redditAppViewModel.cache.push({ key: url, url: url, - completed: (result: imageSource.ImageSource, key: string) => { + completed: (image: any, key: string) => { if (url === key) { this.isLoading = false; - this._thumbnailImageSource = result; - this.notify({ object: this, eventName: observable.knownEvents.propertyChange, propertyName: THUMBNAIL_IMAGE_SOURCE, value: result }); + var imgSource = imageSource.fromNativeSource(image); + this._thumbnailImageSource = imgSource; + this.notify({ object: this, eventName: observable.knownEvents.propertyChange, propertyName: THUMBNAIL_IMAGE_SOURCE, value: imgSource }); } } }); diff --git a/apps/tests/ui/image-cache/image-cache-tests.ts b/apps/tests/ui/image-cache/image-cache-tests.ts index 5b937accd..faa239d70 100644 --- a/apps/tests/ui/image-cache/image-cache-tests.ts +++ b/apps/tests/ui/image-cache/image-cache-tests.ts @@ -19,22 +19,22 @@ export function test_DummyTestForSnippetOnly() { //// Enable download while not scrolling cache.enableDownload(); - var src: imageSource.ImageSource; + var imgSouce: imageSource.ImageSource; var url = "https://github.com/NativeScript.png"; //// Try to read the image from the cache - var result = cache.get(url); - if (result) { + var image = cache.get(url); + if (image) { //// If present -- use it. - src = result; + imgSouce = imageSource.fromNativeSource(image); } else { //// If not present -- request its download. cache.push({ key: url, url: url, - completed: (result: imageSource.ImageSource, key: string) => { + completed: (image: any, key: string) => { if (url === key) { - src = result; + imgSouce = imageSource.fromNativeSource(image); } } }); diff --git a/ui/image-cache/image-cache-common.ts b/ui/image-cache/image-cache-common.ts index 8c243a137..45ba2414b 100644 --- a/ui/image-cache/image-cache-common.ts +++ b/ui/image-cache/image-cache-common.ts @@ -9,7 +9,7 @@ export module knownEvents { export interface DownloadRequest { url: string; key: string; - completed?: (result: imageSource.ImageSource, key: string) => void; + completed?: (image: any, key: string) => void; } export class Cache extends observable.Observable implements definition.Cache { @@ -17,7 +17,6 @@ export class Cache extends observable.Observable implements definition.Cache { public maxRequests = 5; private _enabled = true; - private _cache = {}; private _pendingDownloads = {}; private _queue: Array = []; private _currentDownloads = 0; @@ -98,47 +97,42 @@ export class Cache extends observable.Observable implements definition.Cache { } } - public get(key: string): imageSource.ImageSource { - var value = this._cache[key]; - if (value) { - return value; - } - - return undefined; + public get(key: string): any { + // This method is intended to be overridden by the android and ios implementations + throw new Error("Abstract"); } - public set(key: string, source: imageSource.ImageSource): void { - this._cache[key] = source; + public set(key: string, image: any): void { + // This method is intended to be overridden by the android and ios implementations + throw new Error("Abstract"); } public remove(key: string): void { - delete this._cache[key]; + // This method is intended to be overridden by the android and ios implementations + throw new Error("Abstract"); } public clear() { - var keys = Object.keys(this._cache); - var i; - var length = keys.length; - - for (i = 0; i < length; i++) { - delete this._cache[keys[i]]; - } + // This method is intended to be overridden by the android and ios implementations + throw new Error("Abstract"); } /* tslint:disable:no-unused-variable */ public _downloadCore(request: definition.DownloadRequest) { // This method is intended to be overridden by the android and ios implementations + throw new Error("Abstract"); } /* tslint:enable:no-unused-variable */ - public _onDownloadCompleted(key: string, result: imageSource.ImageSource) { + public _onDownloadCompleted(key: string, image: any) { var request = this._pendingDownloads[key]; - this._cache[request.key] = result; + this.set(request.key, image); + this._currentDownloads--; if (request.completed) { - request.completed(result, request.key); + request.completed(image, request.key); } if (this.hasListeners(knownEvents.downloaded)) { @@ -146,7 +140,7 @@ export class Cache extends observable.Observable implements definition.Cache { eventName: knownEvents.downloaded, object: this, key: key, - image: result + image: image }); } @@ -156,7 +150,7 @@ export class Cache extends observable.Observable implements definition.Cache { } private _shouldDownload(request: definition.DownloadRequest, onTop: boolean): boolean { - if (request.key in this._cache || request.key in this._pendingDownloads) { + if (this.get(request.key) || request.key in this._pendingDownloads) { return false; } diff --git a/ui/image-cache/image-cache.android.ts b/ui/image-cache/image-cache.android.ts index 6615776b9..763446ceb 100644 --- a/ui/image-cache/image-cache.android.ts +++ b/ui/image-cache/image-cache.android.ts @@ -1,20 +1,38 @@ import common = require("ui/image-cache/image-cache-common"); -import imageSource = require("image-source"); module.exports.knownEvents = common.knownEvents; +class LruBitmapCache extends android.util.LruCache { + constructor(cacheSize: number) { + super(cacheSize); + return global.__native(this); + } + + protected sizeOf(key: string, bitmap: android.graphics.Bitmap): number { + // The cache size will be measured in kilobytes rather than + // number of items. + var result = Math.round(bitmap.getByteCount() / 1024); + return result; + } +}; + export class Cache extends common.Cache { private _callback: any; + private _cache: LruBitmapCache; constructor() { super(); + var maxMemory = java.lang.Runtime.getRuntime().maxMemory() / 1024; + var cacheSize = maxMemory / 8; + this._cache = new LruBitmapCache(cacheSize); + var that = new WeakRef(this); this._callback = new (com).tns.Async.CompleteCallback({ onComplete: function (result: any, context: any) { var instance = that.get(); if (instance) { - instance._onBitmapDownloaded(result, context); + instance._onDownloadCompleted(context, result) } } }); @@ -24,11 +42,20 @@ export class Cache extends common.Cache { (com).tns.Async.DownloadImage(request.url, this._callback, request.key); } - /* tslint:disable:no-unused-variable */ - private _onBitmapDownloaded(result: android.graphics.Bitmap, context: any) { - // as a context we are receiving the key of the request - var source = imageSource.fromNativeSource(result); - this._onDownloadCompleted(context, source); + public get(key: string): any { + var result = this._cache.get(key); + return result; + } + + public set(key: string, image: any): void { + this._cache.put(key, image); + } + + public remove(key: string): void { + this._cache.remove(key); + } + + public clear() { + this._cache.evictAll(); } - /* tslint:enable:no-unused-variable */ } \ No newline at end of file diff --git a/ui/image-cache/image-cache.d.ts b/ui/image-cache/image-cache.d.ts index ce69ca354..0ed9bff65 100644 --- a/ui/image-cache/image-cache.d.ts +++ b/ui/image-cache/image-cache.d.ts @@ -20,7 +20,7 @@ declare module "ui/image-cache" { /** * An optional function to be called when the download is complete. */ - completed?: (result: imageSource.ImageSource, key: string) => void; + completed?: (image: any, key: string) => void; } /** @@ -57,11 +57,11 @@ declare module "ui/image-cache" { /** * Gets the image for the specified key. May be undefined if the key is not present in the cache. */ - get(key: string): imageSource.ImageSource; + get(key: string): any; /** * Sets the image for the specified key. */ - set(key: string, source: imageSource.ImageSource): void; + set(key: string, image: any): void; /** * Removes the cache for the specified key. */ @@ -73,7 +73,7 @@ declare module "ui/image-cache" { //@private _downloadCore(request: DownloadRequest); - _onDownloadCompleted(key: string, result: imageSource.ImageSource); + _onDownloadCompleted(key: string, image: any); //@endprivate } diff --git a/ui/image-cache/image-cache.ios.ts b/ui/image-cache/image-cache.ios.ts index cfff270d1..e9dd60330 100644 --- a/ui/image-cache/image-cache.ios.ts +++ b/ui/image-cache/image-cache.ios.ts @@ -1,15 +1,39 @@ import common = require("ui/image-cache/image-cache-common"); -import imageSource = require("image-source"); +import httpRequest = require("http/http-request"); module.exports.knownEvents = common.knownEvents; export class Cache extends common.Cache { + private _cache: NSCache; + + constructor() { + super(); + + this._cache = new NSCache(); + } + public _downloadCore(request: common.DownloadRequest) { - // TODO: WeakRef? var that = this; - imageSource.fromUrl(request.url). - then(function (value) { - that._onDownloadCompleted(request.key, value); + httpRequest.request({ url: request.url, method: "GET" }) + .then(response => { + var image = UIImage.imageWithData(response.content.raw); + that._onDownloadCompleted(request.key, image); }); } + + public get(key: string): any { + return this._cache.objectForKey(key); + } + + public set(key: string, image: any): void { + this._cache.setObjectForKey(image, key); + } + + public remove(key: string): void { + this._cache.removeObjectForKey(key); + } + + public clear() { + this._cache.removeAllObjects(); + } } \ No newline at end of file From 4d2a708c20daee7c13f824b4d2430f734d305942 Mon Sep 17 00:00:00 2001 From: Dimitar Topuzov Date: Thu, 16 Apr 2015 11:27:33 +0300 Subject: [PATCH 02/12] Add Changelog --- CHANGELOG.md | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 CHANGELOG.md diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 000000000..1e43f8562 --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,11 @@ +Cross Platform Modules Changelog +============================== + +0.10.0 (2015, April 17) +== + +### Fixed + +### New + +### Breaking Changes From f28ff80e63a704f6eb71c4447b39f5d679435449 Mon Sep 17 00:00:00 2001 From: Alexander Vakrilov Date: Thu, 16 Apr 2015 11:36:15 +0300 Subject: [PATCH 03/12] Braking changes in image and tab --- CHANGELOG.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1e43f8562..620496249 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,3 +9,9 @@ Cross Platform Modules Changelog ### New ### Breaking Changes + + * Image: `url` property renamed to `src` + * Image: `source` property renamed to `imageSource` + * TabView: `TabEntry` renamed to `TabViewItem ` + + From 267ce57d090d2265edc5328bd0b7a4a9cdfe3231 Mon Sep 17 00:00:00 2001 From: Nedyalko Nikolov Date: Thu, 16 Apr 2015 15:38:59 +0300 Subject: [PATCH 04/12] Added keep aspect ratio parameter to camera.takePicture method. --- CrossPlatformModules.csproj | 3 +++ camera/camera-common.ts | 11 +++++++++++ camera/camera.android.ts | 25 +++++++++++++++++++++---- camera/camera.d.ts | 3 ++- camera/camera.ios.ts | 24 ++++++++++++++++++------ ui/enums/enums.d.ts | 4 ++-- 6 files changed, 57 insertions(+), 13 deletions(-) create mode 100644 camera/camera-common.ts diff --git a/CrossPlatformModules.csproj b/CrossPlatformModules.csproj index c87ba9a84..cd05937ca 100644 --- a/CrossPlatformModules.csproj +++ b/CrossPlatformModules.csproj @@ -722,6 +722,9 @@ Designer + + camera.d.ts + camera.d.ts diff --git a/camera/camera-common.ts b/camera/camera-common.ts new file mode 100644 index 000000000..383bc18d7 --- /dev/null +++ b/camera/camera-common.ts @@ -0,0 +1,11 @@ +export function getAspectSafeDimensions(sourceWidth, sourceHeight, reqWidth, reqHeight) { + var widthCoef = sourceWidth / reqWidth; + var heightCoef = sourceHeight / reqHeight; + + var aspectCoef = widthCoef > heightCoef ? widthCoef : heightCoef; + + return { + width: Math.floor(sourceWidth / aspectCoef), + height: Math.floor(sourceHeight / aspectCoef) + }; +} \ No newline at end of file diff --git a/camera/camera.android.ts b/camera/camera.android.ts index ed66dbaa1..5088c6207 100644 --- a/camera/camera.android.ts +++ b/camera/camera.android.ts @@ -1,14 +1,17 @@ import imageSource = require("image-source"); import appModule = require("application"); import fileSystem = require("file-system"); +import utils = require("utils/utils"); +import common = require("./camera-common"); var REQUEST_IMAGE_CAPTURE = 3453; -export var takePicture = function (width?, height?): Promise { +export var takePicture = function (width?, height?, keepAspectRatio?): Promise { return new Promise((resolve, reject) => { try { - var reqWidth = width || 0; - var reqHeight = height || reqWidth; + var density = utils.layout.getDisplayDensity(); + var reqWidth = width ? width * density : 0; + var reqHeight = height ? height * density : reqWidth; var takePictureIntent = new android.content.Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE); var dateStamp = createDateTimeStamp(); var tempPicturePath = fileSystem.path.join(appModule.android.currentContext.getExternalFilesDir(null).getAbsolutePath(), "cameraPicture_" + dateStamp + ".jpg"); @@ -31,7 +34,21 @@ export var takePicture = function (width?, height?): Promise 0 && reqWidth > 0) { + if (shouldKeepAspectRatio) { + var aspectSafeSize = common.getAspectSafeDimensions(bitmap.getWidth(), bitmap.getHeight(), reqWidth, reqHeight); + scaledSizeImage = android.graphics.Bitmap.createScaledBitmap(bitmap, aspectSafeSize.width, aspectSafeSize.height, true); + } + else { + scaledSizeImage = android.graphics.Bitmap.createScaledBitmap(bitmap, reqWidth, reqHeight, true); + } + } + else { + scaledSizeImage = bitmap; + } + resolve(imageSource.fromNativeSource(scaledSizeImage)); } }; diff --git a/camera/camera.d.ts b/camera/camera.d.ts index 45cffabac..c4dc90fd8 100644 --- a/camera/camera.d.ts +++ b/camera/camera.d.ts @@ -9,6 +9,7 @@ declare module "camera" { * Take a photo using the camera. * @param width - Optional parameter which defines the required width of the taken picture. * @param height - Optional parameter which defines the required height of the taken picture. + * @param keepAspectRatio - Optional parameter which controls if the result picture will keep the aspect ratio of the picture taken by camera. */ - export function takePicture(width?: number, heigth?: number): Promise; + export function takePicture(width?: number, heigth?: number, keepAspectRatio?: boolean): Promise; } diff --git a/camera/camera.ios.ts b/camera/camera.ios.ts index e3b46da41..5bf3cfbb9 100644 --- a/camera/camera.ios.ts +++ b/camera/camera.ios.ts @@ -1,5 +1,6 @@ import imageSource = require("image-source"); import frame = require("ui/frame"); +import common = require("./camera-common"); class UIImagePickerControllerDelegateImpl extends NSObject implements UIImagePickerControllerDelegate { public static ObjCProtocols = [UIImagePickerControllerDelegate]; @@ -12,16 +13,20 @@ class UIImagePickerControllerDelegateImpl extends NSObject implements UIImagePic private _width: number; private _height: number; + private _keepAspectRatio: boolean; public initWithCallback(callback: (result?: imageSource.ImageSource) => void): UIImagePickerControllerDelegateImpl { this._callback = callback; return this; } - public initWithCallbackWidthAndHeight(callback: (result?: imageSource.ImageSource) => void, width, height): UIImagePickerControllerDelegateImpl { + public initWithCallbackAndOptions(callback: (result?: imageSource.ImageSource) => void, options?): UIImagePickerControllerDelegateImpl { this._callback = callback; - this._width = width; - this._height = height; + if (options) { + this._width = options.width; + this._height = options.height; + this._keepAspectRatio = (options.keepAspectRatio === null || options.keepAspectRatio === undefined) ? true : options.keepAspectRatio; + } return this; } @@ -31,7 +36,14 @@ class UIImagePickerControllerDelegateImpl extends NSObject implements UIImagePic if (source) { var image = null; if (this._width || this._height) { - var newSize = CGSizeMake(this._width, this._height); + var newSize = null; + if (this._keepAspectRatio) { + var aspectSafeSize = common.getAspectSafeDimensions(source.size.width, source.size.height, this._width, this._height); + newSize = CGSizeMake(aspectSafeSize.width, aspectSafeSize.height); + } + else { + newSize = CGSizeMake(this._width, this._height); + } UIGraphicsBeginImageContextWithOptions(newSize, false, 0.0); source.drawInRect(CGRectMake(0, 0, newSize.width, newSize.height)); image = UIGraphicsGetImageFromCurrentImageContext(); @@ -53,14 +65,14 @@ class UIImagePickerControllerDelegateImpl extends NSObject implements UIImagePic } } -export var takePicture = function (width?, height?): Promise { +export var takePicture = function (width?, height?, keepAspectRatio?): Promise { return new Promise((resolve, reject) => { var imagePickerController = new UIImagePickerController(); var listener = null; var reqWidth = width || 0; var reqHeight = height || reqWidth; if (reqWidth && reqHeight) { - listener = UIImagePickerControllerDelegateImpl.new().initWithCallbackWidthAndHeight(resolve, reqWidth, reqHeight); + listener = UIImagePickerControllerDelegateImpl.new().initWithCallbackAndOptions(resolve, { width: reqWidth, height: reqHeight, keepAspectRatio: keepAspectRatio }); } else { listener = UIImagePickerControllerDelegateImpl.new().initWithCallback(resolve); diff --git a/ui/enums/enums.d.ts b/ui/enums/enums.d.ts index ca2dc60f8..1d73cd395 100644 --- a/ui/enums/enums.d.ts +++ b/ui/enums/enums.d.ts @@ -164,12 +164,12 @@ export var none: string; /** - * The image is resized to fit in the destination dimensions while it preserves its native aspect ratio. + * The image is resized to fill in the destination dimensions while it preserves its native aspect ratio. */ export var aspectFill: string; /** - * The image is resized to fill the destination dimensions while it preserves + * The image is resized to fit the destination dimensions while it preserves * its native aspect ratio. If the aspect ratio of the destination rectangle differs from the image, * the image is clipped to fit in the destination */ From d86a19cb289bc50e64ec202e543f509f5e81dc39 Mon Sep 17 00:00:00 2001 From: Nedyalko Nikolov Date: Thu, 16 Apr 2015 16:50:14 +0300 Subject: [PATCH 05/12] camera takePicture parameters wrapped in an option object. --- camera/camera.android.ts | 11 +++++++---- camera/camera.d.ts | 8 +++++++- camera/camera.ios.ts | 13 ++++++++++--- 3 files changed, 24 insertions(+), 8 deletions(-) diff --git a/camera/camera.android.ts b/camera/camera.android.ts index 5088c6207..72fa8da1b 100644 --- a/camera/camera.android.ts +++ b/camera/camera.android.ts @@ -2,16 +2,20 @@ import appModule = require("application"); import fileSystem = require("file-system"); import utils = require("utils/utils"); +import definition = require("camera"); import common = require("./camera-common"); var REQUEST_IMAGE_CAPTURE = 3453; -export var takePicture = function (width?, height?, keepAspectRatio?): Promise { +export var takePicture = function (options?: definition.CameraOptions): Promise { return new Promise((resolve, reject) => { try { var density = utils.layout.getDisplayDensity(); - var reqWidth = width ? width * density : 0; - var reqHeight = height ? height * density : reqWidth; + if (options) { + var reqWidth = options.width ? options.width * density : 0; + var reqHeight = options.height ? options.height * density : reqWidth; + var shouldKeepAspectRatio = (options.keepAspectRatio === null || options.keepAspectRatio === undefined) ? true : options.keepAspectRatio; + } var takePictureIntent = new android.content.Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE); var dateStamp = createDateTimeStamp(); var tempPicturePath = fileSystem.path.join(appModule.android.currentContext.getExternalFilesDir(null).getAbsolutePath(), "cameraPicture_" + dateStamp + ".jpg"); @@ -34,7 +38,6 @@ export var takePicture = function (width?, height?, keepAspectRatio?): Promise 0 && reqWidth > 0) { if (shouldKeepAspectRatio) { diff --git a/camera/camera.d.ts b/camera/camera.d.ts index c4dc90fd8..0d86af126 100644 --- a/camera/camera.d.ts +++ b/camera/camera.d.ts @@ -11,5 +11,11 @@ declare module "camera" { * @param height - Optional parameter which defines the required height of the taken picture. * @param keepAspectRatio - Optional parameter which controls if the result picture will keep the aspect ratio of the picture taken by camera. */ - export function takePicture(width?: number, heigth?: number, keepAspectRatio?: boolean): Promise; + export function takePicture(options?: CameraOptions): Promise; + + export interface CameraOptions { + width?: number; + height?: number; + keepAspectRatio?: boolean; + } } diff --git a/camera/camera.ios.ts b/camera/camera.ios.ts index 5bf3cfbb9..30b7b3376 100644 --- a/camera/camera.ios.ts +++ b/camera/camera.ios.ts @@ -1,5 +1,6 @@ import imageSource = require("image-source"); import frame = require("ui/frame"); +import definition = require("camera"); import common = require("./camera-common"); class UIImagePickerControllerDelegateImpl extends NSObject implements UIImagePickerControllerDelegate { @@ -65,12 +66,18 @@ class UIImagePickerControllerDelegateImpl extends NSObject implements UIImagePic } } -export var takePicture = function (width?, height?, keepAspectRatio?): Promise { +export var takePicture = function (options?: definition.CameraOptions): Promise { return new Promise((resolve, reject) => { var imagePickerController = new UIImagePickerController(); var listener = null; - var reqWidth = width || 0; - var reqHeight = height || reqWidth; + var reqWidth = 0; + var reqHeight = 0; + var keepAspectRatio = true; + if (options) { + reqWidth = options.width || 0; + reqHeight = options.height || reqWidth; + keepAspectRatio = (options.keepAspectRatio === null || options.keepAspectRatio === undefined) ? true : options.keepAspectRatio; + } if (reqWidth && reqHeight) { listener = UIImagePickerControllerDelegateImpl.new().initWithCallbackAndOptions(resolve, { width: reqWidth, height: reqHeight, keepAspectRatio: keepAspectRatio }); } From 68c9a90226d0e2efc6fade7f8dd4bbb595b4e66e Mon Sep 17 00:00:00 2001 From: vakrilov Date: Thu, 16 Apr 2015 17:00:21 +0300 Subject: [PATCH 06/12] Fix: Device-specific code behinf JS files are not loaded --- ui/frame/frame-common.ts | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/ui/frame/frame-common.ts b/ui/frame/frame-common.ts index a569761a6..cf448ef3f 100644 --- a/ui/frame/frame-common.ts +++ b/ui/frame/frame-common.ts @@ -47,10 +47,13 @@ function resolvePageFromEntry(entry: definition.NavigationEntry): pages.Page { var moduleNamePath = fs.path.join(currentAppPath, entry.moduleName); var moduleExports; - - if (fs.File.exists(moduleNamePath + ".js")) { - trace.write("Loading JS file: " + moduleNamePath + ".js", trace.categories.Navigation); - moduleExports = require(moduleNamePath); + var moduleExportsResolvedPath = resolveFilePath(moduleNamePath, "js"); + if (moduleExportsResolvedPath) { + trace.write("Loading JS file: " + moduleExportsResolvedPath, trace.categories.Navigation); + + // Exclude extension when doing require. + moduleExportsResolvedPath = moduleExportsResolvedPath.substr(0, moduleExportsResolvedPath.length - 3) + moduleExports = require(moduleExportsResolvedPath); } if (moduleExports && moduleExports.createPage) { @@ -70,7 +73,7 @@ function resolvePageFromEntry(entry: definition.NavigationEntry): pages.Page { } var fileNameResolver: fileResolverModule.FileNameResolver; -function resolveFilePath(path, ext) { +function resolveFilePath(path, ext) : string { if (!fileNameResolver) { fileNameResolver = new fileResolverModule.FileNameResolver({ width: platform.screen.mainScreen.widthDIPs, From 96638ef9fd0a839cc7fb1843f85e07fdb7df0d28 Mon Sep 17 00:00:00 2001 From: Nedyalko Nikolov Date: Fri, 17 Apr 2015 16:00:17 +0300 Subject: [PATCH 07/12] Api reference added. --- camera/camera.android.ts | 6 +++--- camera/camera.d.ts | 20 +++++++++++++++++--- 2 files changed, 20 insertions(+), 6 deletions(-) diff --git a/camera/camera.android.ts b/camera/camera.android.ts index 72fa8da1b..fc2ec4942 100644 --- a/camera/camera.android.ts +++ b/camera/camera.android.ts @@ -80,9 +80,9 @@ var calculateInSampleSize = function (imageWidth, imageHeight, reqWidth, reqHeig var createDateTimeStamp = function() { var result = ""; - var date = new Date(); - result = date.getDate().toString() + - (date.getMonth() + 1).toString() + + var date = new Date(2015, 3, 3); + result = (date.getDate() < 10 ? "0" + date.getDate().toString() : date.getDate().toString())+ + ((date.getMonth() + 1) < 10 ? "0" + (date.getMonth() + 1).toString() : (date.getMonth() + 1).toString()) + date.getFullYear().toString() + date.getHours().toString() + date.getMinutes().toString() + diff --git a/camera/camera.d.ts b/camera/camera.d.ts index 0d86af126..0b9132892 100644 --- a/camera/camera.d.ts +++ b/camera/camera.d.ts @@ -7,15 +7,29 @@ declare module "camera" { /** * Take a photo using the camera. - * @param width - Optional parameter which defines the required width of the taken picture. - * @param height - Optional parameter which defines the required height of the taken picture. - * @param keepAspectRatio - Optional parameter which controls if the result picture will keep the aspect ratio of the picture taken by camera. + * @param options - Optional parameter for setting different camera options. */ export function takePicture(options?: CameraOptions): Promise; export interface CameraOptions { + /** + * Defines the desired width (in device independent pixels) of the taken image. It should be used with height property. + * If `keepAspectRatio` actual image width could be different in order to keep the aspect ratio of the original camera image. + * The actual image width will be greater than requested if the display density of the device is higher (than 1) (full HD+ resolutions). + */ width?: number; + + /** + * Defines the desired height (in device independent pixels) of the taken image. It should be used with width property. + * If `keepAspectRatio` actual image width could be different in order to keep the aspect ratio of the original camera image. + * The actual image height will be greater than requested if the display density of the device is higher (than 1) (full HD+ resolutions). + */ height?: number; + + /** + * Defines if camera picture aspect ratio should be kept during picture resizing. + * This property could affect width or heigth return values. + */ keepAspectRatio?: boolean; } } From 075e2ae6739e61ccf50ec85711bfadc0af2760e1 Mon Sep 17 00:00:00 2001 From: Nedyalko Nikolov Date: Fri, 17 Apr 2015 16:29:40 +0300 Subject: [PATCH 08/12] Removed test date. --- camera/camera.android.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/camera/camera.android.ts b/camera/camera.android.ts index fc2ec4942..f8acf8207 100644 --- a/camera/camera.android.ts +++ b/camera/camera.android.ts @@ -80,7 +80,7 @@ var calculateInSampleSize = function (imageWidth, imageHeight, reqWidth, reqHeig var createDateTimeStamp = function() { var result = ""; - var date = new Date(2015, 3, 3); + var date = new Date(); result = (date.getDate() < 10 ? "0" + date.getDate().toString() : date.getDate().toString())+ ((date.getMonth() + 1) < 10 ? "0" + (date.getMonth() + 1).toString() : (date.getMonth() + 1).toString()) + date.getFullYear().toString() + From 3a5433e6d854091d9c8e00540031c55a727cc228 Mon Sep 17 00:00:00 2001 From: Nedyalko Nikolov Date: Mon, 20 Apr 2015 10:40:50 +0300 Subject: [PATCH 09/12] Binding and camera changes added to change log. --- CHANGELOG.md | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 620496249..fbaaa609f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,10 +8,25 @@ Cross Platform Modules Changelog ### New +* In addition to binding converters introduced in version 0.42 is added a static (global) place for most common converters. This place is named `application.resources`. More information how to use it can be found in the special help topic regarding `Data binding`. + +* Using plain objects (numbers, strings also an entire object) as binding context via `$value`. More information can be found at the dedicated `Data binding` help topic. + ### Breaking Changes * Image: `url` property renamed to `src` * Image: `source` property renamed to `imageSource` * TabView: `TabEntry` renamed to `TabViewItem ` - +1.0 (2015, May) +== + +### Fixed + +* Taking a full size picture in Android with NativeScript camera module. + +### New + +* New options for camera module. Added a resizing options along with keep aspect ratio options. More information about how to use it can be found at the dedicated camera help article. + +### Breaking changes \ No newline at end of file From d2d540216081fcf7d82b9b63ad8f4e2b5018ee1d Mon Sep 17 00:00:00 2001 From: Erjan Gavalji Date: Mon, 20 Apr 2015 10:44:23 +0300 Subject: [PATCH 10/12] Minor changes in the CHANGELOG --- CHANGELOG.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index fbaaa609f..481cd761c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,7 +8,7 @@ Cross Platform Modules Changelog ### New -* In addition to binding converters introduced in version 0.42 is added a static (global) place for most common converters. This place is named `application.resources`. More information how to use it can be found in the special help topic regarding `Data binding`. +* In addition to binding converters introduced in version 0.42 static (global) place for most common converters is added. This place is named `application.resources`. More information how to use it can be found in the special help topic regarding `Data binding`. * Using plain objects (numbers, strings also an entire object) as binding context via `$value`. More information can be found at the dedicated `Data binding` help topic. @@ -27,6 +27,6 @@ Cross Platform Modules Changelog ### New -* New options for camera module. Added a resizing options along with keep aspect ratio options. More information about how to use it can be found at the dedicated camera help article. +* New options for camera module. Added a resizing options along with keep-aspect-ratio options. More information about how to use it can be found at the dedicated camera help article. -### Breaking changes \ No newline at end of file +### Breaking changes From 08ce45959c46e04f7c1f8f7e2f4478cf53c1341b Mon Sep 17 00:00:00 2001 From: Rossen Hristov Date: Mon, 20 Apr 2015 09:44:29 +0300 Subject: [PATCH 11/12] Fixed the memory leaks in iOS. --- apps/cuteness.io/main-page.xml | 2 +- apps/cuteness.io/reddit-item-view-model.ts | 70 ++++++++++------------ ui/image-cache/image-cache.ios.ts | 58 +++++++++++++++++- ui/image/image-common.ts | 19 +++--- ui/image/image.android.ts | 8 ++- ui/image/image.d.ts | 4 +- ui/image/image.ios.ts | 18 ++++-- 7 files changed, 120 insertions(+), 59 deletions(-) diff --git a/apps/cuteness.io/main-page.xml b/apps/cuteness.io/main-page.xml index 311245c70..e062e9486 100644 --- a/apps/cuteness.io/main-page.xml +++ b/apps/cuteness.io/main-page.xml @@ -7,7 +7,7 @@ - +