mirror of
https://github.com/NativeScript/NativeScript.git
synced 2025-08-16 03:31:45 +08:00
Imporvements and lint fix
This commit is contained in:
@ -1,4 +1,5 @@
|
|||||||
import http = require("http");
|
import http = require("http");
|
||||||
|
import types = require("utils/types");
|
||||||
|
|
||||||
// This is used for definition purposes only, it does not generate JavaScript for it.
|
// This is used for definition purposes only, it does not generate JavaScript for it.
|
||||||
import definition = require("image-source");
|
import definition = require("image-source");
|
||||||
@ -30,8 +31,22 @@ export function fromUrl(url: string): Promise<definition.ImageSource> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export function fromFileOrResource(path: string): definition.ImageSource {
|
export function fromFileOrResource(path: string): definition.ImageSource {
|
||||||
|
if (!isFileOrResourcePath(path)) {
|
||||||
|
throw new Error("Path \"" + "\" is not a valid file or resource.");
|
||||||
|
}
|
||||||
|
|
||||||
if (path.indexOf(RESOURCE_PREFIX) === 0) {
|
if (path.indexOf(RESOURCE_PREFIX) === 0) {
|
||||||
return fromResource(path.substr(RESOURCE_PREFIX.length));
|
return fromResource(path.substr(RESOURCE_PREFIX.length));
|
||||||
}
|
}
|
||||||
return fromFile(path);
|
return fromFile(path);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function isFileOrResourcePath(path: string): boolean {
|
||||||
|
if (!types.isString(path)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return path.indexOf("~/") === 0 || // relative to AppRoot
|
||||||
|
path.indexOf("/") === 0 || // absolute path
|
||||||
|
path.indexOf(RESOURCE_PREFIX) === 0; // resource
|
||||||
|
}
|
10
image-source/image-source.d.ts
vendored
10
image-source/image-source.d.ts
vendored
@ -4,8 +4,8 @@
|
|||||||
declare module "image-source" {
|
declare module "image-source" {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Encapsulates the common abstraction behind a platform specific object (typically a Bitmap) that is used as a source for images.
|
* Encapsulates the common abstraction behind a platform specific object (typically a Bitmap) that is used as a source for images.
|
||||||
*/
|
*/
|
||||||
export class ImageSource {
|
export class ImageSource {
|
||||||
/**
|
/**
|
||||||
* Gets the height of this instance. This is a read-only property.
|
* Gets the height of this instance. This is a read-only property.
|
||||||
@ -104,4 +104,10 @@ declare module "image-source" {
|
|||||||
* @param path The location of the file on the file system.
|
* @param path The location of the file on the file system.
|
||||||
*/
|
*/
|
||||||
export function fromFileOrResource(path: string): ImageSource;
|
export function fromFileOrResource(path: string): ImageSource;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns true if the specified path points to a resource or local file.
|
||||||
|
* @param path The path.
|
||||||
|
*/
|
||||||
|
export function isFileOrResourcePath(path: string): boolean
|
||||||
}
|
}
|
2
ui/enums/enums.d.ts
vendored
2
ui/enums/enums.d.ts
vendored
@ -311,8 +311,6 @@
|
|||||||
export var allCharacters: string;
|
export var allCharacters: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Defines the recognized image formats.
|
* Defines the recognized image formats.
|
||||||
*/
|
*/
|
||||||
|
@ -86,7 +86,6 @@ export module AutocapitalizationType {
|
|||||||
export var allCharacters: string = "allCharacters";
|
export var allCharacters: string = "allCharacters";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
export module ImageFormat {
|
export module ImageFormat {
|
||||||
export var png: string = "png";
|
export var png: string = "png";
|
||||||
export var jpeg: string = "jpeg";
|
export var jpeg: string = "jpeg";
|
||||||
|
@ -15,10 +15,6 @@ var IMAGE = "Image";
|
|||||||
var ISLOADING = "isLoading";
|
var ISLOADING = "isLoading";
|
||||||
var STRETCH = "stretch";
|
var STRETCH = "stretch";
|
||||||
|
|
||||||
function isUrl(value: string): boolean {
|
|
||||||
return value.indexOf("http://") === 0 || value.indexOf("https://") === 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
function isValidSrc(src: any): boolean {
|
function isValidSrc(src: any): boolean {
|
||||||
return types.isString(src);
|
return types.isString(src);
|
||||||
}
|
}
|
||||||
@ -34,16 +30,16 @@ function onSrcPropertyChanged(data: dependencyObservable.PropertyChangeData) {
|
|||||||
|
|
||||||
image._setValue(Image.isLoadingProperty, true);
|
image._setValue(Image.isLoadingProperty, true);
|
||||||
|
|
||||||
if (isUrl(value)) {
|
if (imageSource.isFileOrResourcePath(value)) {
|
||||||
|
image.imageSource = imageSource.fromFileOrResource(value);
|
||||||
|
image._setValue(Image.isLoadingProperty, false);
|
||||||
|
} else {
|
||||||
imageSource.fromUrl(value).then((r) => {
|
imageSource.fromUrl(value).then((r) => {
|
||||||
if (image["_url"] === value) {
|
if (image["_url"] === value) {
|
||||||
image.imageSource = r;
|
image.imageSource = r;
|
||||||
image._setValue(Image.isLoadingProperty, false);
|
image._setValue(Image.isLoadingProperty, false);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
} else {
|
|
||||||
image.imageSource = imageSource.fromFileOrResource(value);
|
|
||||||
image._setValue(Image.isLoadingProperty, false);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (value instanceof imageSource.ImageSource) {
|
else if (value instanceof imageSource.ImageSource) {
|
||||||
|
Reference in New Issue
Block a user