Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

fix(android): handle width and height as strings in ImageAsset options #10728

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
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 26 additions & 2 deletions 28 packages/core/image-asset/index.android.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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({
Expand Down
Morty Proxy This is a proxified and sanitized view of the page, visit original site.