Skip to content

Commit

Permalink
fix: support ImageSource for uris
Browse files Browse the repository at this point in the history
  • Loading branch information
farfromrefug committed Aug 21, 2019
1 parent 5a8f84b commit 6e7aff6
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 16 deletions.
16 changes: 10 additions & 6 deletions src/image.android.ts
Original file line number Diff line number Diff line change
Expand Up @@ -679,14 +679,18 @@ export class Img extends ImageBase {
}
}

private getDrawable(path: string) {
private getDrawable(path: string | ImageSource) {
let drawable: android.graphics.drawable.BitmapDrawable;
if (utils.isFileOrResourcePath(path)) {
if (path.indexOf(utils.RESOURCE_PREFIX) === 0) {
drawable = this.getDrawableFromResource(path);
} else {
drawable = this.getDrawableFromLocalFile(path);
if (typeof path === 'string') {
if (utils.isFileOrResourcePath(path)) {
if (path.indexOf(utils.RESOURCE_PREFIX) === 0) {
drawable = this.getDrawableFromResource(path);
} else {
drawable = this.getDrawableFromLocalFile(path);
}
}
} else {
drawable = new android.graphics.drawable.BitmapDrawable(path.android);
}

return drawable;
Expand Down
7 changes: 4 additions & 3 deletions src/image.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import * as viewModule from 'tns-core-modules/ui/core/view';
import { ImageSource } from 'tns-core-modules/image-source/image-source';

export const debug: boolean;
declare function setDebug(value: boolean)
Expand Down Expand Up @@ -68,7 +69,7 @@ export class Img extends viewModule.View {
/**
* String value used for the image URI.
*/
src: string;
src: string | ImageSource;

/**
* String value used for the lower res image URI.
Expand All @@ -78,12 +79,12 @@ export class Img extends viewModule.View {
/**
* String value used for the placeholder image URI.
*/
placeholderImageUri: string;
placeholderImageUri: string | ImageSource;

/**
* String value used for the failure image URI.
*/
failureImageUri: string;
failureImageUri: string | ImageSource;

/**
* String value used by Image image scale type. This property can be set to:
Expand Down
15 changes: 8 additions & 7 deletions src/image.ios.ts
Original file line number Diff line number Diff line change
Expand Up @@ -532,18 +532,19 @@ export class Img extends ImageBase {
this.handleImageProgress(totalSize > 0 ? currentSize / totalSize : -1, totalSize);
};

private getUIImage(path: string) {
private getUIImage(path: string | ImageSource) {
if (!path) {
return null;
}
let image;
if (utils.isFileOrResourcePath(path)) {
// if (path.indexOf(utils.RESOURCE_PREFIX) === 0) {
// image = imageSource.fromFileOrResource(path);
// } else {
image = fromFileOrResource(path);
// }
if (typeof path === 'string') {
if (utils.isFileOrResourcePath(path)) {
image = fromFileOrResource(path);
}
} else {
image = path;
}

// console.log("getUIImage", path, !!image, !!image && !!image.ios);
if (image) {
image = image.ios;
Expand Down

0 comments on commit 6e7aff6

Please sign in to comment.