Use [srcProperty.native]

This commit is contained in:
vakrilov
2017-01-06 11:54:00 +02:00
parent 6eb1aee4d1
commit d17ff9ffbd
3 changed files with 18 additions and 8 deletions

View File

@@ -110,11 +110,7 @@ export abstract class ImageBase extends View implements ImageDefinition {
export const imageSourceProperty = new Property<ImageBase, ImageSource>({ name: "imageSource" }); export const imageSourceProperty = new Property<ImageBase, ImageSource>({ name: "imageSource" });
imageSourceProperty.register(ImageBase); imageSourceProperty.register(ImageBase);
function onSrcPropertyChanged(image: ImageBase, oldValue: string, newValue: string) { export const srcProperty = new Property<ImageBase, any>({ name: "src"});
image._createImageSourceFromSrc();
};
export const srcProperty = new Property<ImageBase, any>({ name: "src", valueChanged: onSrcPropertyChanged });
srcProperty.register(ImageBase); srcProperty.register(ImageBase);
export const loadModeProperty = new Property<ImageBase, "sync" | "async">({ name: "loadMode", defaultValue: "async" }); export const loadModeProperty = new Property<ImageBase, "sync" | "async">({ name: "loadMode", defaultValue: "async" });

View File

@@ -1,5 +1,5 @@
import { import {
ImageSource, ImageBase, stretchProperty, imageSourceProperty, tintColorProperty, unsetValue, Color, ImageSource, ImageBase, stretchProperty, imageSourceProperty, srcProperty, tintColorProperty, unsetValue, Color,
isDataURI, isFileOrResourcePath, RESOURCE_PREFIX isDataURI, isFileOrResourcePath, RESOURCE_PREFIX
} from "./image-common"; } from "./image-common";
import { path, knownFolders } from "file-system"; import { path, knownFolders } from "file-system";
@@ -38,7 +38,7 @@ export function initImageCache(context: android.content.Context, mode = CacheMod
} }
let params = new org.nativescript.widgets.image.Cache.CacheParams(); let params = new org.nativescript.widgets.image.Cache.CacheParams();
params.memoryCacheEnabled = mode !== CacheMode.none; params.memoryCacheEnabled = mode !== CacheMode.none;
params.setMemCacheSizePercent(memoryCacheSize); // Set memory cache to % of app memory params.setMemCacheSizePercent(memoryCacheSize); // Set memory cache to % of app memory
params.diskCacheEnabled = mode === CacheMode.diskAndMemory; params.diskCacheEnabled = mode === CacheMode.diskAndMemory;
params.diskCacheSize = diskCacheSize; params.diskCacheSize = diskCacheSize;
@@ -157,6 +157,13 @@ export class Image extends ImageBase {
set [imageSourceProperty.native](value: ImageSource) { set [imageSourceProperty.native](value: ImageSource) {
this._setNativeImage(value ? value.android : null); this._setNativeImage(value ? value.android : null);
} }
get [srcProperty.native](): any {
return undefined;
}
set [srcProperty.native](value: any) {
this._createImageSourceFromSrc();
}
} }
@Interfaces([org.nativescript.widgets.image.Worker.OnImageLoadedListener]) @Interfaces([org.nativescript.widgets.image.Worker.OnImageLoadedListener])

View File

@@ -1,5 +1,5 @@
import { import {
ImageSource, ImageBase, stretchProperty, imageSourceProperty, tintColorProperty, layout, Color, ImageSource, ImageBase, stretchProperty, imageSourceProperty, tintColorProperty, srcProperty, layout, Color,
traceEnabled, traceWrite, traceCategories traceEnabled, traceWrite, traceCategories
} from "./image-common"; } from "./image-common";
@@ -149,4 +149,11 @@ export class Image extends ImageBase {
set [imageSourceProperty.native](value: ImageSource) { set [imageSourceProperty.native](value: ImageSource) {
this._setNativeImage(value ? value.ios : null); this._setNativeImage(value ? value.ios : null);
} }
get [srcProperty.native](): any {
return undefined;
}
set [srcProperty.native](value: any) {
this._createImageSourceFromSrc();
}
} }