Skip to content

Conversation

@VeinDevTtv
Copy link
Contributor

Problem

On Android, ImageAssetOptions.width/height provided as strings like "300" were parsed with optInt(), which resolves string values to 0. This caused oversized decode/scale operations that could crash older Android APIs (e.g., API 22) with "bitmap size exceeds 32 bits" error.

Fixes #6289

Changes

Android (packages/ui-mobile-base/android/widgets/src/main/java/org/nativescript/widgets/Utils.java)

  • Added parsePositiveInt(JSONObject, String) method to safely parse numeric strings and numbers
  • Updated loadImageAsync to use parsePositiveInt for width/height options instead of optInt
  • Invalid values (non-numeric strings, negatives) fall back to 0 for default sizing

TypeScript (packages/core/image-asset/image-asset-common.ts)

  • Added normalizeImageAssetOptions() to coerce string dimensions to positive integers
  • Added toPositiveInt() helper for robust string-to-number conversion
  • Updated ImageAssetBase.options setter to normalize options
  • Updated getRequestedImageSize() to use normalized options

Tests (packages/core/image-asset/__tests__/image-asset-options.spec.ts)

  • Added regression tests for string width/height coercion
  • Added tests for invalid string fallback behavior
  • Added tests for aspect ratio preservation with string dimensions

Verification

  • ✅ Core package builds successfully
  • ✅ New regression tests pass
  • ✅ Repro case with imagepicker using { width: "300", height: "300" } no longer crashes on Android API 22
  • ✅ String dimensions now behave identically to numeric inputs

Backwards Compatibility

  • Numeric width/height options unchanged
  • Invalid string values now gracefully fall back to defaults instead of crashing
  • All existing functionality preserved

@nx-cloud
Copy link

nx-cloud bot commented Oct 30, 2025

View your CI Pipeline Execution ↗ for commit a9c4097

Command Status Duration Result
nx test apps-automated -c=android ✅ Succeeded 5m 51s View ↗
nx run-many --target=test --configuration=ci --... ✅ Succeeded 3s View ↗

☁️ Nx Cloud last updated this comment at 2025-10-30 17:53:07 UTC

@NathanWalker NathanWalker merged commit 9db6369 into NativeScript:main Oct 30, 2025
3 of 4 checks passed
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.

Setting string value to width or height of ImageAssetOptions results in an error on android

2 participants