Skip to content

fix: parse width and height from string to int in ImageAsset options … #10763

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from

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
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy