Skip to content

Conversation

kishore-144
Copy link

This fix ensures that the width and height options in the ImageAsset class are properly converted from string to integer before being passed to the native image loading utility.
Previously, if these values were provided as strings, it could cause unexpected behavior or errors during image processing on Android.

Added type checks and parsing of width and height in getImageAsync method

Ensured fallback to 0 if parsing fails, maintaining backward compatibility

This resolves issues related to incorrect image sizing and improves robustness in handling image options

Here is the code that i have changed in the getImageAsync function placed in index.android.ts

public getImageAsync(callback: (image, error) => void) {
if (this.options) {
if (typeof this.options.width === 'string') {
this.options.width = parseInt(this.options.width, 10) || 0;
}
if (typeof this.options.height === 'string') {
this.options.height = parseInt(this.options.height, 10) || 0;
}
}

	org.nativescript.widgets.Utils.loadImageAsync(
		ad.getApplicationContext(),
		this.android,
		JSON.stringify(this.options || {}),
		Screen.mainScreen.widthPixels,
		Screen.mainScreen.heightPixels,
		new org.nativescript.widgets.Utils.AsyncImageCallback({
			onSuccess(bitmap) {
				callback(bitmap, null);
			},
			onError(ex) {
				callback(null, ex);
			},
		})
	);
}

@kishore-144
Copy link
Author

Hi, could a maintainer please approve the workflow and review this PR when possible? Thank you!

@CatchABus
Copy link
Contributor

CatchABus commented Jul 14, 2025

Hi, could a maintainer please approve the workflow and review this PR when possible? Thank you!

We have already got an open PR about this: #10736
You can pass them as numeric arguments for the time being.

@kishore-144
Copy link
Author

Got it, thanks for clarifying! Since there’s already an open PR for this fix (#10736) and a workaround for now, I’ll close this one to avoid duplication.
Looking forward to contributing more — thanks for the review!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants