Skip to content

Commit

Permalink
Merge pull request #20998 from wordpress-mobile/fix-memory-leak-in-no…
Browse files Browse the repository at this point in the history
…tification-observers-4

Capture weak references in some notification observers
  • Loading branch information
crazytonyli authored Jul 4, 2023
2 parents 99c5e0a + 36b961f commit c55f6ab
Showing 1 changed file with 6 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -759,19 +759,22 @@ extension CollapsableHeaderViewController: UIScrollViewDelegate {
// MARK: - Keyboard Adjustments
extension CollapsableHeaderViewController {
private func startObservingKeyboardChanges() {
let willShowObserver = NotificationCenter.default.addObserver(forName: UIResponder.keyboardWillShowNotification, object: nil, queue: .main) { (notification) in
let willShowObserver = NotificationCenter.default.addObserver(forName: UIResponder.keyboardWillShowNotification, object: nil, queue: .main) { [weak self] (notification) in
guard let self else { return }
UIView.animate(withKeyboard: notification) { (_, endFrame) in
self.scrollableContainerBottomConstraint.constant = endFrame.height - self.footerHeight
}
}

let willHideObserver = NotificationCenter.default.addObserver(forName: UIResponder.keyboardWillHideNotification, object: nil, queue: .main) { (notification) in
let willHideObserver = NotificationCenter.default.addObserver(forName: UIResponder.keyboardWillHideNotification, object: nil, queue: .main) { [weak self] (notification) in
guard let self else { return }
UIView.animate(withKeyboard: notification) { (_, _) in
self.scrollableContainerBottomConstraint.constant = 0
}
}

let willChangeFrameObserver = NotificationCenter.default.addObserver(forName: UIResponder.keyboardWillChangeFrameNotification, object: nil, queue: .main) { (notification) in
let willChangeFrameObserver = NotificationCenter.default.addObserver(forName: UIResponder.keyboardWillChangeFrameNotification, object: nil, queue: .main) { [weak self] (notification) in
guard let self else { return }
UIView.animate(withKeyboard: notification) { (_, endFrame) in
self.scrollableContainerBottomConstraint.constant = endFrame.height - self.footerHeight
}
Expand Down

0 comments on commit c55f6ab

Please sign in to comment.