Skip to content

Commit

Permalink
fix: flicker when sensitive text field is on screen (#270)
Browse files Browse the repository at this point in the history
  • Loading branch information
ioannisj authored Dec 4, 2024
1 parent 049f11c commit afcefab
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 8 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
## Next

- fix: screen flicker when capturing a screenshot when a sensitive text field is on screen ([#270](https://github.com/PostHog/posthog-ios/pull/270))

## 3.16.0 - 2024-12-03

- fix: deprecate `maskPhotoLibraryImages` due to unintended masking issues ([#268](https://github.com/PostHog/posthog-ios/pull/268))
Expand Down
8 changes: 3 additions & 5 deletions PostHog/Replay/UIView+Util.swift
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,9 @@
let renderer = UIGraphicsImageRenderer(size: size, format: rendererFormat)

let image = renderer.image { _ in
// true for afterScreenUpdates so that we capture view *after* any pending animations are committed
// As a side effect, we need to pause view tracker temporarily to avoid recursive calls since this option will cause subviews to layout, which will then trigger another capture
ViewLayoutTracker.paused = true
drawHierarchy(in: bounds, afterScreenUpdates: true)
ViewLayoutTracker.paused = false
/// Note: Always `false` for `afterScreenUpdates` since this will cause the screen to flicker when a sensitive text field is visible on screen
/// This can potentially affect capturing a snapshot during a screen transition but we want the lesser of the two evils here
drawHierarchy(in: bounds, afterScreenUpdates: false)
}

return image
Expand Down
3 changes: 0 additions & 3 deletions PostHog/Replay/ViewLayoutTracker.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,14 @@
import UIKit

enum ViewLayoutTracker {
static var paused = false
private(set) static var hasChanges = false
private static var hasSwizzled = false

static func viewDidLayout(view _: UIView) {
guard !paused else { return }
hasChanges = true
}

static func clear() {
guard !paused else { return }
hasChanges = false
}

Expand Down

0 comments on commit afcefab

Please sign in to comment.