mirror of
https://github.com/NativeScript/NativeScript.git
synced 2025-11-05 13:26:48 +08:00
Resource prefix v.01
This commit is contained in:
@@ -1,8 +1,12 @@
|
||||
<Page>
|
||||
<StackLayout>
|
||||
<Button horizontalAlignment="left" verticalAlignment="top" margin="10 0 10 20" text="top, left" />
|
||||
<Button horizontalAlignment="center" verticalAlignment="center" text="center, center" />
|
||||
<Button horizontalAlignment="right" verticalAlignment="bottom" margin="0 30" text="bottom, right" />
|
||||
<Button horizontalAlignment="stretch" verticalAlignment="stretch" margin="20" text="stretch, stretch" />
|
||||
<Label text="resource:" />
|
||||
<Image url="res://icon" stretch="none" horizontalAlignment="left"/>
|
||||
|
||||
<Label text="url:" />
|
||||
<Image url="http://www.google.com/images/errors/logo_sm_2.png" stretch="none" horizontalAlignment="left"/>
|
||||
|
||||
<Label text="app file:" />
|
||||
<Image url="~/app/logo.png" stretch="none" horizontalAlignment="left" />
|
||||
</StackLayout>
|
||||
</Page>
|
||||
@@ -13,25 +13,42 @@ 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: string): boolean {
|
||||
var value = url ? url.trim() : "";
|
||||
return value !== "" && (value.indexOf("~/") === 0 || value.indexOf("http://") === 0 || value.indexOf("https://") === 0);
|
||||
return value !== "" && (isResource(value) || isAppFile(value) || isUrl(value));
|
||||
}
|
||||
|
||||
function onUrlPropertyChanged(data: dependencyObservable.PropertyChangeData) {
|
||||
var image = <Image>data.object;
|
||||
var value = data.newValue;
|
||||
var value: string = data.newValue;
|
||||
|
||||
if (isValidUrl(value)) {
|
||||
value = value.trim();
|
||||
image.source = null;
|
||||
image["_url"] = value;
|
||||
|
||||
if (value !== "") {
|
||||
|
||||
image._setValue(Image.isLoadingProperty, true);
|
||||
|
||||
if (value.trim().indexOf("~/") === 0) {
|
||||
image.source = imageSource.fromFile(value.trim());
|
||||
if (isResource(value)) {
|
||||
image.source = imageSource.fromResource(value.substr(RESOURCE_PREFIX.length));
|
||||
image._setValue(Image.isLoadingProperty, false);
|
||||
}
|
||||
else if (isAppFile(value)) {
|
||||
image.source = imageSource.fromFile(value);
|
||||
image._setValue(Image.isLoadingProperty, false);
|
||||
} else {
|
||||
imageSource.fromUrl(value).then((r) => {
|
||||
@@ -42,7 +59,6 @@ function onUrlPropertyChanged(data: dependencyObservable.PropertyChangeData) {
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export class Image extends view.View implements definition.Image {
|
||||
|
||||
Reference in New Issue
Block a user