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

Open
wants to merge 1 commit into
base: main
Choose a base branch
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!

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.

1 participant