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: use global frame on wireframe views #250

Merged
merged 6 commits into from
Nov 18, 2024
Merged
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
## Next

- fix: mangled wireframe layouts ([#250](https://github.com/PostHog/posthog-ios/pull/250))
- recording: do not rotate the session id for hybrid SDKs ([#253](https://github.com/PostHog/posthog-ios/pull/253))

## 3.15.2 - 2024-11-13
Expand Down
19 changes: 13 additions & 6 deletions PostHog/Replay/PostHogReplayIntegration.swift
Original file line number Diff line number Diff line change
Expand Up @@ -146,14 +146,19 @@
style.paddingLeft = Int(insets.left)
}

private func createBasicWireframe(_ window: UIView) -> RRWireframe {
private func createBasicWireframe(_ view: UIView) -> RRWireframe {
ioannisj marked this conversation as resolved.
Show resolved Hide resolved
let wireframe = RRWireframe()

wireframe.id = window.hash
wireframe.posX = Int(window.frame.origin.x)
wireframe.posY = Int(window.frame.origin.y)
wireframe.width = Int(window.frame.size.width)
wireframe.height = Int(window.frame.size.height)
// since FE will render each node of the wireframe with position: fixed
// we need to convert bounds to global screen coordinates
// otherwise each view of depth > 1 will likely have an origin of 0,0 (which is the local origin)
let frame = view.toAbsoluteRect(view.window)

wireframe.id = view.hash
wireframe.posX = Int(frame.origin.x)
wireframe.posY = Int(frame.origin.y)
wireframe.width = Int(frame.size.width)
wireframe.height = Int(frame.size.height)

return wireframe
}
Expand Down Expand Up @@ -448,6 +453,8 @@
wireframe.disabled = !button.isEnabled

if let text = button.titleLabel?.text {
// NOTE: this will create a ghosting effect since text will also be captured in child UILabel
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

will create an issue

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

// We also may be masking this UIButton but child UILabel may remain unmasked
wireframe.value = isButtonSensitive(button) ? text.mask() : text
}
}
Expand Down
2 changes: 1 addition & 1 deletion PostHog/Replay/UIView+Util.swift
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@
}

// you need this because of SwiftUI otherwise the coordinates always zeroed for some reason
func toAbsoluteRect(_ window: UIWindow) -> CGRect {
func toAbsoluteRect(_ window: UIWindow?) -> CGRect {
convert(bounds, to: window)
}
}
Expand Down
6 changes: 2 additions & 4 deletions PostHog/Utils/UIApplication+.swift
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,8 @@
}
} else {
// check scene.windows.isKeyWindow
for window in scene.windows {
if window.isKeyWindow {
return window
}
for window in scene.windows where window.isKeyWindow {
return window
}
}

Expand Down
Loading