mirror of
https://github.com/NativeScript/NativeScript.git
synced 2025-11-05 13:26:48 +08:00
async image loading from data, files and resources for ios
Use the tns_safeDecodeImageNamedCompletion from the widgets framework Add loadMode on Image with sync and async options for local images
This commit is contained in:
committed by
Panayot Cankov
parent
b8785afd74
commit
1b395aac7f
@@ -44,7 +44,7 @@ export class ImageSource implements definition.ImageSource {
|
||||
// Load BitmapDrawable with getDrawable to make use of Android internal caching
|
||||
var bitmapDrawable = <android.graphics.drawable.BitmapDrawable>res.getDrawable(identifier);
|
||||
if (bitmapDrawable && bitmapDrawable.getBitmap) {
|
||||
this.android = bitmapDrawable.getBitmap();
|
||||
this.android = bitmapDrawable.getBitmap();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -52,6 +52,12 @@ export class ImageSource implements definition.ImageSource {
|
||||
return this.android != null;
|
||||
}
|
||||
|
||||
public fromResource(name: string): Promise<boolean> {
|
||||
return new Promise<boolean>((resolve, reject) => {
|
||||
resolve(this.loadFromResource(name));
|
||||
});
|
||||
}
|
||||
|
||||
public loadFromFile(path: string): boolean {
|
||||
ensureFS();
|
||||
|
||||
@@ -64,11 +70,23 @@ export class ImageSource implements definition.ImageSource {
|
||||
return this.android != null;
|
||||
}
|
||||
|
||||
public fromFile(path: string): Promise<boolean> {
|
||||
return new Promise<boolean>((resolve, reject) => {
|
||||
resolve(this.loadFromFile(path));
|
||||
});
|
||||
}
|
||||
|
||||
public loadFromData(data: any): boolean {
|
||||
this.android = android.graphics.BitmapFactory.decodeStream(data);
|
||||
return this.android != null;
|
||||
}
|
||||
|
||||
public fromData(data: any): Promise<boolean> {
|
||||
return new Promise<boolean>((resolve, reject) => {
|
||||
resolve(this.loadFromData(data));
|
||||
});
|
||||
}
|
||||
|
||||
public loadFromBase64(source: string): boolean {
|
||||
if (types.isString(source)) {
|
||||
var bytes = android.util.Base64.decode(source, android.util.Base64.DEFAULT);
|
||||
@@ -77,6 +95,12 @@ export class ImageSource implements definition.ImageSource {
|
||||
return this.android != null;
|
||||
}
|
||||
|
||||
public fromBase64(data: any): Promise<boolean> {
|
||||
return new Promise<boolean>((resolve, reject) => {
|
||||
resolve(this.loadFromBase64(data));
|
||||
});
|
||||
}
|
||||
|
||||
public setNativeSource(source: any): boolean {
|
||||
this.android = source;
|
||||
return source != null;
|
||||
|
||||
Reference in New Issue
Block a user