Skip to content

Commit 6e7aff6

Browse files
committed
fix: support ImageSource for uris
1 parent 5a8f84b commit 6e7aff6

File tree

3 files changed

+22
-16
lines changed

3 files changed

+22
-16
lines changed

src/image.android.ts

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -679,14 +679,18 @@ export class Img extends ImageBase {
679679
}
680680
}
681681

682-
private getDrawable(path: string) {
682+
private getDrawable(path: string | ImageSource) {
683683
let drawable: android.graphics.drawable.BitmapDrawable;
684-
if (utils.isFileOrResourcePath(path)) {
685-
if (path.indexOf(utils.RESOURCE_PREFIX) === 0) {
686-
drawable = this.getDrawableFromResource(path);
687-
} else {
688-
drawable = this.getDrawableFromLocalFile(path);
684+
if (typeof path === 'string') {
685+
if (utils.isFileOrResourcePath(path)) {
686+
if (path.indexOf(utils.RESOURCE_PREFIX) === 0) {
687+
drawable = this.getDrawableFromResource(path);
688+
} else {
689+
drawable = this.getDrawableFromLocalFile(path);
690+
}
689691
}
692+
} else {
693+
drawable = new android.graphics.drawable.BitmapDrawable(path.android);
690694
}
691695

692696
return drawable;

src/image.d.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import * as viewModule from 'tns-core-modules/ui/core/view';
2+
import { ImageSource } from 'tns-core-modules/image-source/image-source';
23

34
export const debug: boolean;
45
declare function setDebug(value: boolean)
@@ -68,7 +69,7 @@ export class Img extends viewModule.View {
6869
/**
6970
* String value used for the image URI.
7071
*/
71-
src: string;
72+
src: string | ImageSource;
7273

7374
/**
7475
* String value used for the lower res image URI.
@@ -78,12 +79,12 @@ export class Img extends viewModule.View {
7879
/**
7980
* String value used for the placeholder image URI.
8081
*/
81-
placeholderImageUri: string;
82+
placeholderImageUri: string | ImageSource;
8283

8384
/**
8485
* String value used for the failure image URI.
8586
*/
86-
failureImageUri: string;
87+
failureImageUri: string | ImageSource;
8788

8889
/**
8990
* String value used by Image image scale type. This property can be set to:

src/image.ios.ts

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -532,18 +532,19 @@ export class Img extends ImageBase {
532532
this.handleImageProgress(totalSize > 0 ? currentSize / totalSize : -1, totalSize);
533533
};
534534

535-
private getUIImage(path: string) {
535+
private getUIImage(path: string | ImageSource) {
536536
if (!path) {
537537
return null;
538538
}
539539
let image;
540-
if (utils.isFileOrResourcePath(path)) {
541-
// if (path.indexOf(utils.RESOURCE_PREFIX) === 0) {
542-
// image = imageSource.fromFileOrResource(path);
543-
// } else {
544-
image = fromFileOrResource(path);
545-
// }
540+
if (typeof path === 'string') {
541+
if (utils.isFileOrResourcePath(path)) {
542+
image = fromFileOrResource(path);
543+
}
544+
} else {
545+
image = path;
546546
}
547+
547548
// console.log("getUIImage", path, !!image, !!image && !!image.ios);
548549
if (image) {
549550
image = image.ios;

0 commit comments

Comments
 (0)