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
Merged
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
13 changes: 9 additions & 4 deletions detox/ios/Detox/Utilities/ViewHierarchyGenerator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -129,8 +129,8 @@ struct ViewHierarchyGenerator {
) -> String {
var attributes: [String: String] = [
"class": "\(type(of: view))",
"width": "\(Int(view.frame.size.width))",
"height": "\(Int(view.frame.size.height))",
"width": "\(toClampedInt(view.frame.size.width))",
"height": "\(toClampedInt(view.frame.size.height))",
"visibility": view.isHidden ? "invisible" : "visible",
"alpha": "\(view.alpha)",
"focused": "\(view.isFocused)",
Expand All @@ -144,8 +144,9 @@ struct ViewHierarchyGenerator {

if let superview = view.superview {
let location = view.convert(view.bounds.origin, to: superview)
attributes["x"] = "\(Int(location.x))"
attributes["y"] = "\(Int(location.y))"
// todo: error
asafkorem marked this conversation as resolved.
Show resolved Hide resolved
attributes["x"] = "\(toClampedInt(location.x))"
attributes["y"] = "\(toClampedInt(location.y))"
}

if shouldInjectIdentifiers {
Expand Down Expand Up @@ -221,3 +222,7 @@ class WebViewHandler: NSObject, WKNavigationDelegate {
}
}
}

func toClampedInt(_ value: Double) -> Int {
return Int(min(max(value, Double(Int.min)), Double(Int.max)))
}
Loading