From c0c1ee2f233cdba1fce0d91b60ce1c0462644207 Mon Sep 17 00:00:00 2001 From: thearnabsaha Date: Thu, 10 Apr 2025 15:21:17 +0530 Subject: [PATCH] fix(android): handle width and height as strings in ImageAsset options --- packages/core/image-asset/index.android.ts | 28 ++++++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) diff --git a/packages/core/image-asset/index.android.ts b/packages/core/image-asset/index.android.ts index 055caeff60..c83985f573 100644 --- a/packages/core/image-asset/index.android.ts +++ b/packages/core/image-asset/index.android.ts @@ -5,7 +5,7 @@ import { Screen } from '../platform'; export * from './image-asset-common'; export class ImageAsset extends ImageAssetBase { - private _android: string; //file name of the image + private _android: string; // file name of the image constructor(asset: string) { super(); @@ -26,10 +26,34 @@ export class ImageAsset extends ImageAssetBase { } public getImageAsync(callback: (image, error) => void) { + // Clone and sanitize the options before sending to Android + const options = { ...(this.options || {}) }; + + // Sanitize width and height (convert string to number if needed) + if (typeof options.width === 'string') { + const parsedWidth = parseInt(options.width, 10); + if (!isNaN(parsedWidth)) { + options.width = parsedWidth; + } else { + console.warn('Invalid width value provided:', options.width); + delete options.width; + } + } + + if (typeof options.height === 'string') { + const parsedHeight = parseInt(options.height, 10); + if (!isNaN(parsedHeight)) { + options.height = parsedHeight; + } else { + console.warn('Invalid height value provided:', options.height); + delete options.height; + } + } + org.nativescript.widgets.Utils.loadImageAsync( ad.getApplicationContext(), this.android, - JSON.stringify(this.options || {}), + JSON.stringify(options), Screen.mainScreen.widthPixels, Screen.mainScreen.heightPixels, new org.nativescript.widgets.Utils.AsyncImageCallback({