From 6e7aff6e3cf40c2e59e58a60f1cdecdae4ecbd27 Mon Sep 17 00:00:00 2001 From: Martin Guillon Date: Wed, 21 Aug 2019 17:20:44 +0200 Subject: [PATCH] fix: support ImageSource for uris --- src/image.android.ts | 16 ++++++++++------ src/image.d.ts | 7 ++++--- src/image.ios.ts | 15 ++++++++------- 3 files changed, 22 insertions(+), 16 deletions(-) diff --git a/src/image.android.ts b/src/image.android.ts index a0db671..956884c 100644 --- a/src/image.android.ts +++ b/src/image.android.ts @@ -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; diff --git a/src/image.d.ts b/src/image.d.ts index 810c394..d1e2c01 100644 --- a/src/image.d.ts +++ b/src/image.d.ts @@ -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) @@ -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. @@ -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: diff --git a/src/image.ios.ts b/src/image.ios.ts index 7424d5c..0875103 100644 --- a/src/image.ios.ts +++ b/src/image.ios.ts @@ -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;