Skip to content
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

fix(iOS): clamp Double values before converting to Integer. #4621

Merged
merged 1 commit into from
Oct 28, 2024

Conversation

asafkorem
Copy link
Contributor

@asafkorem asafkorem commented Oct 28, 2024

After investigation, I discovered that when UIDatePicker is set to UIDatePickerStyle.wheels (Spinner mode), it assigns unusual coordinate values for off-screen wheel cells (falling below Int.min and above Int.max). This leads to a conversion error in ViewHierarchyGenerator when attempting to cast these Double values to Int, resulting in:

Double value cannot be converted to Int because the result would be less than Int.min

To address this, I kept the Int conversion but applied clamping (instead of representing it as a Double in the string) for the following reasons:

  • Double values can be excessively long, adding unnecessary complexity to the view hierarchy.
  • On 32-bit systems, Int ranges from -2,147,483,648 to 2,147,483,647, and on 64-bit systems, from -9,223,372,036,854,775,808 to 9,223,372,036,854,775,807, indicating an internal issue with these extreme values.
  • Any element positioned outside standard Int bounds is irrelevant to our use case, so these values can safely be ignored without impacting functionality.

To avoid Swift runtime failure:
`Double value cannot be converted to Int because the result would be less than Int.min`
@asafkorem asafkorem force-pushed the fix/view-hierarchy-generator branch from 400966d to f7f7c1c Compare October 28, 2024 06:11
@asafkorem asafkorem changed the title fix(iOS): avoid unnecessary conversion from Double to Int. fix(iOS): clamp Double values before converting to Integer. Oct 28, 2024
@asafkorem asafkorem self-assigned this Oct 28, 2024
@asafkorem asafkorem merged commit 619fe4d into master Oct 28, 2024
3 checks passed
@asafkorem asafkorem deleted the fix/view-hierarchy-generator branch October 28, 2024 07:11
asafkorem added a commit that referenced this pull request Oct 28, 2024
asafkorem added a commit that referenced this pull request Oct 28, 2024
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