Skip to content

Commit

Permalink
♻️ Add displayName to AppcuesViewElement
Browse files Browse the repository at this point in the history
  • Loading branch information
mmaatttt committed Jun 6, 2023
1 parent 9e2b1d9 commit 281de41
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,20 @@ internal class UIKitElementSelector: AppcuesElementSelector {
try container.encode(tag, forKey: .tag)
}
}

func displayName(with type: String) -> String? {
if let appcuesID = appcuesID {
return appcuesID
} else if let accessibilityIdentifier = accessibilityIdentifier {
return accessibilityIdentifier
} else if let tag = tag {
return "\(type) (tag \(tag))"
} else if let accessibilityLabel = accessibilityLabel {
return "\(type) (\(accessibilityLabel))"
}

return nil
}
}

// UIKit implementation of element targeting that captures the UIView hierarchy for the current UIWindow,
Expand Down Expand Up @@ -131,14 +145,18 @@ internal extension UIView {
return $0.asViewElement(in: bounds)
}

let selector = appcuesSelector
let type = "\(type(of: self))"

return AppcuesViewElement(
x: absolutePosition.origin.x,
y: absolutePosition.origin.y,
width: absolutePosition.width,
height: absolutePosition.height,
type: "\(type(of: self))",
selector: appcuesSelector,
children: children.isEmpty ? nil : children
type: type,
selector: selector,
children: children.isEmpty ? nil : children,
displayName: selector?.displayName(with: type)
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ public class AppcuesViewElement: NSObject, Encodable {
/// The sub-views contained within this view, if any.
let children: [AppcuesViewElement]?

/// A user-readable textual representation of the view.
let displayName: String?

/// Creates an instance of an AppcuesViewElement.
/// - Parameters:
/// - x: The x-coordinate for view position, with origin in the upper-left corner, in screen coordinates.
Expand All @@ -61,7 +64,8 @@ public class AppcuesViewElement: NSObject, Encodable {
height: CGFloat,
type: String,
selector: AppcuesElementSelector?,
children: [AppcuesViewElement]?
children: [AppcuesViewElement]?,
displayName: String? = nil
) {
self.x = x
self.y = y
Expand All @@ -70,6 +74,7 @@ public class AppcuesViewElement: NSObject, Encodable {
self.type = type
self.selector = selector
self.children = children
self.displayName = displayName
}
}

Expand Down

0 comments on commit 281de41

Please sign in to comment.