mirror of
https://github.com/NativeScript/NativeScript.git
synced 2025-11-05 13:26:48 +08:00
Image-source modules refactoring
This commit is contained in:
committed by
Vladimir Enchev
parent
2e782aecc5
commit
ae8b285fc0
30
ui/enums/enums.d.ts
vendored
30
ui/enums/enums.d.ts
vendored
@@ -9,25 +9,25 @@
|
||||
* iOS: [UIKeyboardTypeNumbersAndPunctuation](https://developer.apple.com/library/ios/documentation/UIKit/Reference/UITextInputTraits_Protocol/index.html#//apple_ref/c/tdef/UIKeyboardType)
|
||||
*/
|
||||
export var datetime: string;
|
||||
|
||||
|
||||
/**
|
||||
* Android: [TYPE_CLASS_PHONE](http://developer.android.com/reference/android/text/InputType.html#TYPE_CLASS_PHONE)
|
||||
* iOS: [UIKeyboardTypePhonePad](https://developer.apple.com/library/ios/documentation/UIKit/Reference/UITextInputTraits_Protocol/index.html#//apple_ref/c/tdef/UIKeyboardType)
|
||||
*/
|
||||
export var phone: string;
|
||||
|
||||
|
||||
/**
|
||||
* Android: [TYPE_CLASS_NUMBER](http://developer.android.com/reference/android/text/InputType.html#TYPE_CLASS_NUMBER) | android.text.InputType.TYPE_NUMBER_VARIATION_NORMAL | [TYPE_NUMBER_FLAG_SIGNED](http://developer.android.com/reference/android/text/InputType.html#TYPE_NUMBER_FLAG_SIGNED) | [TYPE_NUMBER_FLAG_DECIMAL](http://developer.android.com/reference/android/text/InputType.html#TYPE_NUMBER_FLAG_DECIMAL)
|
||||
* iOS: [UIKeyboardTypeNumbersAndPunctuation](https://developer.apple.com/library/ios/documentation/UIKit/Reference/UITextInputTraits_Protocol/index.html#//apple_ref/c/tdef/UIKeyboardType)
|
||||
*/
|
||||
export var number: string;
|
||||
|
||||
|
||||
/**
|
||||
* Android: [TYPE_CLASS_TEXT](http://developer.android.com/reference/android/text/InputType.html#TYPE_CLASS_TEXT) | [TYPE_TEXT_VARIATION_URI](http://developer.android.com/reference/android/text/InputType.html#TYPE_TEXT_VARIATION_URI)
|
||||
* iOS: [UIKeyboardTypeURL](https://developer.apple.com/library/ios/documentation/UIKit/Reference/UITextInputTraits_Protocol/index.html#//apple_ref/c/tdef/UIKeyboardType)
|
||||
*/
|
||||
export var url: string;
|
||||
|
||||
|
||||
/**
|
||||
* Android: [TYPE_CLASS_TEXT](http://developer.android.com/reference/android/text/InputType.html#TYPE_CLASS_TEXT) | [TYPE_TEXT_VARIATION_EMAIL_ADDRESS](http://developer.android.com/reference/android/text/InputType.html#TYPE_TEXT_VARIATION_EMAIL_ADDRESS)
|
||||
* iOS: [UIKeyboardTypeEmailAddress](https://developer.apple.com/library/ios/documentation/UIKit/Reference/UITextInputTraits_Protocol/index.html#//apple_ref/c/tdef/UIKeyboardType)
|
||||
@@ -56,13 +56,13 @@
|
||||
* iOS: [UIReturnKeyGo](https://developer.apple.com/library/ios/documentation/UIKit/Reference/UITextInputTraits_Protocol/index.html#//apple_ref/c/tdef/UIReturnKeyType)
|
||||
*/
|
||||
export var go: string;
|
||||
|
||||
|
||||
/**
|
||||
* Android: [IME_ACTION_SEARCH](http://developer.android.com/reference/android/view/inputmethod/EditorInfo.html#IME_ACTION_SEARCH)
|
||||
* iOS: [UIReturnKeySearch](https://developer.apple.com/library/ios/documentation/UIKit/Reference/UITextInputTraits_Protocol/index.html#//apple_ref/c/tdef/UIReturnKeyType)
|
||||
*/
|
||||
export var search: string;
|
||||
|
||||
|
||||
/**
|
||||
* Android: [IME_ACTION_SEND](http://developer.android.com/reference/android/view/inputmethod/EditorInfo.html#IME_ACTION_SEND)
|
||||
* iOS: [UIReturnKeySend](https://developer.apple.com/library/ios/documentation/UIKit/Reference/UITextInputTraits_Protocol/index.html#//apple_ref/c/tdef/UIReturnKeyType)
|
||||
@@ -304,11 +304,27 @@
|
||||
* Capitalize the first letter of each sentence automatically.
|
||||
*/
|
||||
export var sentences: string;
|
||||
|
||||
|
||||
/**
|
||||
* Capitalize all characters automatically.
|
||||
*/
|
||||
export var allCharacters: string;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Defines the recognized image formats.
|
||||
*/
|
||||
module ImageFormat {
|
||||
/**
|
||||
* The W3C Portable Network Graphics (PNG) image format.
|
||||
*/
|
||||
export var png: string;
|
||||
|
||||
/**
|
||||
* The Joint Photographic Experts Group (JPEG) image format.
|
||||
*/
|
||||
export var jpeg: string;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -84,4 +84,10 @@ export module AutocapitalizationType {
|
||||
export var words: string = "words";
|
||||
export var sentences: string = "sentences";
|
||||
export var allCharacters: string = "allCharacters";
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
export module ImageFormat {
|
||||
export var png: string = "png";
|
||||
export var jpeg: string = "jpeg";
|
||||
}
|
||||
|
||||
@@ -15,54 +15,35 @@ var IMAGE = "Image";
|
||||
var ISLOADING = "isLoading";
|
||||
var STRETCH = "stretch";
|
||||
|
||||
var RESOURCE_PREFIX = "res://";
|
||||
|
||||
function isResource(value: string): boolean {
|
||||
return value.indexOf(RESOURCE_PREFIX) === 0;
|
||||
}
|
||||
|
||||
function isUrl(value: string): boolean {
|
||||
return value.indexOf("http://") === 0 || value.indexOf("https://") === 0;
|
||||
}
|
||||
|
||||
function isAppFile(value: string): boolean {
|
||||
return value.indexOf("~/") === 0;
|
||||
}
|
||||
|
||||
function isValidUrl(url: any): boolean {
|
||||
if (!types.isString(url)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
var value = url ? url.trim() : "";
|
||||
return value !== "" && (isResource(value) || isAppFile(value) || isUrl(value));
|
||||
function isValidSrc(src: any): boolean {
|
||||
return types.isString(src);
|
||||
}
|
||||
|
||||
function onSrcPropertyChanged(data: dependencyObservable.PropertyChangeData) {
|
||||
var image = <Image>data.object;
|
||||
var value = data.newValue;
|
||||
|
||||
if (isValidUrl(value)) {
|
||||
if (isValidSrc(value)) {
|
||||
value = value.trim();
|
||||
image.imageSource = null;
|
||||
image["_url"] = value;
|
||||
|
||||
image._setValue(Image.isLoadingProperty, true);
|
||||
|
||||
if (isResource(value)) {
|
||||
image.imageSource = imageSource.fromResource(value.substr(RESOURCE_PREFIX.length));
|
||||
image._setValue(Image.isLoadingProperty, false);
|
||||
}
|
||||
else if (isAppFile(value)) {
|
||||
image.imageSource = imageSource.fromFile(value);
|
||||
image._setValue(Image.isLoadingProperty, false);
|
||||
} else {
|
||||
if (isUrl(value)) {
|
||||
imageSource.fromUrl(value).then((r) => {
|
||||
if (image["_url"] === value) {
|
||||
image.imageSource = r;
|
||||
image._setValue(Image.isLoadingProperty, false);
|
||||
}
|
||||
});
|
||||
} else {
|
||||
image.imageSource = imageSource.fromFileOrResource(value);
|
||||
image._setValue(Image.isLoadingProperty, false);
|
||||
}
|
||||
}
|
||||
else if (value instanceof imageSource.ImageSource) {
|
||||
|
||||
Reference in New Issue
Block a user