mirror of
https://github.com/NativeScript/NativeScript.git
synced 2025-08-16 11:42:04 +08:00
Image src now can be set to Data URI
This commit is contained in:
@ -131,6 +131,31 @@ export var test_SettingImageSrcToFileWithinApp = function (done) {
|
||||
helper.buildUIAndRunTest(image, testFunc);
|
||||
}
|
||||
|
||||
export var test_SettingImageSrcToDataURI = function (done) {
|
||||
// <snippet module="ui/image" title="Image">
|
||||
// ### How to create an image and set its src to Data URI.
|
||||
// ``` JavaScript
|
||||
var image = new ImageModule.Image();
|
||||
image.src = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAQAAAAECAIAAAAmkwkpAAAAAXNSR0IArs4c6QAAABxpRE9UAAAAAgAAAAAAAAACAAAAKAAAAAIAAAACAAAARiS4uJEAAAASSURBVBgZYvjPwABHSMz/DAAAAAD//0GWpK0AAAAOSURBVGNgYPiPhBgQAACEvQv1D5y/pAAAAABJRU5ErkJggg==";
|
||||
// ```
|
||||
// </snippet>
|
||||
|
||||
var testFunc = function (views: Array<ViewModule.View>) {
|
||||
var testImage = <ImageModule.Image>views[0];
|
||||
TKUnit.waitUntilReady(() => !testImage.isLoading, 3);
|
||||
try {
|
||||
TKUnit.assertTrue(!testImage.isLoading, "isLoading should be false.");
|
||||
TKUnit.assertNotNull(testImage.imageSource);
|
||||
done(null);
|
||||
}
|
||||
catch (e) {
|
||||
done(e);
|
||||
}
|
||||
}
|
||||
|
||||
helper.buildUIAndRunTest(image, testFunc);
|
||||
}
|
||||
|
||||
export var test_SettingStretch_AspectFit = function () {
|
||||
// <snippet module="ui/image" title="Image">
|
||||
// ### How to set image stretching.
|
||||
|
@ -5,6 +5,8 @@ import imageSource = require("image-source");
|
||||
import definition = require("ui/image");
|
||||
import enums = require("ui/enums");
|
||||
import platform = require("platform");
|
||||
import utils = require("utils/utils");
|
||||
|
||||
import * as typesModule from "utils/types";
|
||||
|
||||
var SRC = "src";
|
||||
@ -30,7 +32,14 @@ function onSrcPropertyChanged(data: dependencyObservable.PropertyChangeData) {
|
||||
|
||||
image._setValue(Image.isLoadingProperty, true);
|
||||
|
||||
if (imageSource.isFileOrResourcePath(value)) {
|
||||
if (utils.isDataURI(value)) {
|
||||
var base64Data = value.split(",")[1];
|
||||
if (types.isDefined(base64Data)) {
|
||||
image.imageSource = imageSource.fromBase64(base64Data);
|
||||
image._setValue(Image.isLoadingProperty, false);
|
||||
}
|
||||
}
|
||||
else if (imageSource.isFileOrResourcePath(value)) {
|
||||
image.imageSource = imageSource.fromFileOrResource(value);
|
||||
image._setValue(Image.isLoadingProperty, false);
|
||||
} else {
|
||||
|
Reference in New Issue
Block a user