Skip to content

Commit

Permalink
fix: use global frame on wireframe views (#250)
Browse files Browse the repository at this point in the history
  • Loading branch information
ioannisj authored Nov 18, 2024
1 parent 052971b commit 30e3ef0
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 11 deletions.
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 {
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
// 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

0 comments on commit 30e3ef0

Please sign in to comment.