mirror of
https://github.com/NativeScript/NativeScript.git
synced 2025-08-17 04:41:36 +08:00
http image download fixed
This commit is contained in:
@ -352,26 +352,35 @@ export var backgroundImageProperty = new styleProperty.Property("backgroundImage
|
||||
new observable.PropertyMetadata(undefined, observable.PropertyMetadataSettings.None, onBackgroundImagePropertyChanged));
|
||||
|
||||
function onBackgroundImagePropertyChanged(data: observable.PropertyChangeData) {
|
||||
var view: view.View = (<any>data.object)._view;
|
||||
var style = <Style>data.object;
|
||||
var url: string = data.newValue;
|
||||
|
||||
style._setValue(backgroundImageSourceProperty, undefined, observable.ValueSource.Local);
|
||||
|
||||
if (types.isString(data.newValue)) {
|
||||
var pattern: RegExp = /url\(('|")(.*?)\1\)/;
|
||||
var match = data.newValue && (<string>data.newValue).match(pattern);
|
||||
var url = match && match[2] || data.newValue;
|
||||
var match = url.match(pattern);
|
||||
if (match && match[2]) {
|
||||
url = match[2];
|
||||
}
|
||||
|
||||
if (!types.isNullOrUndefined(url)) {
|
||||
if (utils.isDataURI(url)) {
|
||||
var base64Data = url.split(",")[1];
|
||||
if (types.isDefined(base64Data)) {
|
||||
style._setValue(backgroundImageSourceProperty, imageSource.fromBase64(base64Data), observable.ValueSource.Local);
|
||||
}
|
||||
} else if (utils.isFileOrResourcePath(url)) {
|
||||
style._setValue(backgroundImageSourceProperty, imageSource.fromFileOrResource(url), observable.ValueSource.Local);
|
||||
} else {
|
||||
imageSource.fromUrl(url).then(r=> {
|
||||
style._setValue(backgroundImageSourceProperty, r, observable.ValueSource.Local);
|
||||
});
|
||||
if (utils.isDataURI(url)) {
|
||||
var base64Data = url.split(",")[1];
|
||||
if (types.isDefined(base64Data)) {
|
||||
style._setValue(backgroundImageSourceProperty, imageSource.fromBase64(base64Data), observable.ValueSource.Local);
|
||||
}
|
||||
} else if (utils.isFileOrResourcePath(url)) {
|
||||
style._setValue(backgroundImageSourceProperty, imageSource.fromFileOrResource(url), observable.ValueSource.Local);
|
||||
} else if (url.indexOf("http") !== -1) {
|
||||
if (view) {
|
||||
view["_url"] = url;
|
||||
}
|
||||
imageSource.fromUrl(url).then(r=> {
|
||||
if (view && view["_url"] === url) {
|
||||
style._setValue(backgroundImageSourceProperty, r, observable.ValueSource.Local);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user