コード例 #1
0
 Image.prototype._createImageSourceFromSrc = function () {
     var imageView = this._android;
     if (!imageView || !this.src) {
         return;
     }
     var value = this.src;
     var async = this.loadMode === ASYNC;
     var owner = new WeakRef(this);
     var listener = new org.nativescript.widgets.image.Worker.OnImageLoadedListener({
         onImageLoaded: function (success) {
             var that = owner.get();
             if (that) {
                 that._setValue(Image.isLoadingProperty, false);
             }
         }
     });
     this._resetValue(Image.imageSourceProperty);
     if (types.isString(value)) {
         value = value.trim();
         this._setValue(Image.isLoadingProperty, true);
         if (utils.isDataURI(value)) {
             _super.prototype._createImageSourceFromSrc.call(this);
         }
         else if (imageSource.isFileOrResourcePath(value)) {
             if (value.indexOf(utils.RESOURCE_PREFIX) === 0) {
                 imageView.setUri(value, this.decodeWidth, this.decodeHeight, this.useCache, async, listener);
             }
             else {
                 var fileName = value;
                 if (fileName.indexOf("~/") === 0) {
                     fileName = fs.path.join(fs.knownFolders.currentApp().path, fileName.replace("~/", ""));
                 }
                 imageView.setUri(FILE_PREFIX + fileName, this.decodeWidth, this.decodeHeight, this.useCache, async, listener);
             }
         }
         else {
             imageView.setUri(value, this.decodeWidth, this.decodeHeight, this.useCache, true, listener);
         }
     }
     else {
         _super.prototype._createImageSourceFromSrc.call(this);
     }
 };
コード例 #2
0
function onBackgroundImagePropertyChanged(data) {
    var style = data.object;
    var url = data.newValue;
    var currentBackground = style._getValue(exports.backgroundInternalProperty);
    var isValid = false;
    if (types.isString(data.newValue)) {
        var pattern = /url\(('|")(.*?)\1\)/;
        var match = url.match(pattern);
        if (match && match[2]) {
            url = match[2];
        }
        if (utils.isDataURI(url)) {
            var base64Data = url.split(",")[1];
            if (types.isDefined(base64Data)) {
                style._setValue(exports.backgroundInternalProperty, currentBackground.withImage(imageSource.fromBase64(base64Data)));
                isValid = true;
            }
        }
        else if (utils.isFileOrResourcePath(url)) {
            style._setValue(exports.backgroundInternalProperty, currentBackground.withImage(imageSource.fromFileOrResource(url)));
            isValid = true;
        }
        else if (url.indexOf("http") !== -1) {
            style["_url"] = url;
            style._setValue(exports.backgroundInternalProperty, currentBackground.withImage(undefined));
            imageSource.fromUrl(url).then(function (r) {
                if (style && style["_url"] === url) {
                    style._setValue(exports.backgroundInternalProperty, currentBackground.withImage(r));
                }
            });
            isValid = true;
        }
    }
    if (!isValid) {
        style._setValue(exports.backgroundInternalProperty, currentBackground.withImage(undefined));
    }
}
コード例 #3
0
function onBackgroundImagePropertyChanged(data) {
    var style = data.object;
    if (types.isString(data.newValue)) {
        var pattern = /url\(('|")(.*?)\1\)/;
        var match = data.newValue && data.newValue.match(pattern);
        var url = match && match[2];
        if (types.isDefined(url)) {
            if (utils.isDataURI(url)) {
                var base64Data = url.split(",")[1];
                if (types.isDefined(base64Data)) {
                    style._setValue(exports.backgroundImageSourceProperty, imageSource.fromBase64(base64Data), observable.ValueSource.Local);
                }
            }
            else if (utils.isFileOrResourcePath(url)) {
                style._setValue(exports.backgroundImageSourceProperty, imageSource.fromFileOrResource(url), observable.ValueSource.Local);
            }
            else {
                imageSource.fromUrl(url).then(function (r) {
                    style._setValue(exports.backgroundImageSourceProperty, r, observable.ValueSource.Local);
                });
            }
        }
    }
}