Skip to content

Commit

Permalink
Merge pull request #4621 from wix/fix/view-hierarchy-generator
Browse files Browse the repository at this point in the history
fix(iOS): clamp Double values before converting to Integer.
  • Loading branch information
asafkorem authored Oct 28, 2024
2 parents dd2ee8e + f7f7c1c commit 619fe4d
Showing 1 changed file with 9 additions and 4 deletions.
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
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)))
}

0 comments on commit 619fe4d

Please sign in to comment.