diff --git a/CHANGELOG.md b/CHANGELOG.md index dc0d6baf9..89fa591d8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/PostHog/Replay/PostHogReplayIntegration.swift b/PostHog/Replay/PostHogReplayIntegration.swift index a2b6e7757..7d1168bd8 100644 --- a/PostHog/Replay/PostHogReplayIntegration.swift +++ b/PostHog/Replay/PostHogReplayIntegration.swift @@ -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 } @@ -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 } } diff --git a/PostHog/Replay/UIView+Util.swift b/PostHog/Replay/UIView+Util.swift index 283782197..35e9f1c0c 100644 --- a/PostHog/Replay/UIView+Util.swift +++ b/PostHog/Replay/UIView+Util.swift @@ -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) } } diff --git a/PostHog/Utils/UIApplication+.swift b/PostHog/Utils/UIApplication+.swift index 440a57d01..d9403df78 100644 --- a/PostHog/Utils/UIApplication+.swift +++ b/PostHog/Utils/UIApplication+.swift @@ -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 } }