From 746fd278daf8ca5e4e5df4c31816ce0ad39d854f Mon Sep 17 00:00:00 2001 From: Matthew Chen Date: Fri, 29 Mar 2019 14:25:17 -0400 Subject: [PATCH] Restart typing indicators animations after app returns from background. --- Signal/src/views/TypingIndicatorView.swift | 29 ++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/Signal/src/views/TypingIndicatorView.swift b/Signal/src/views/TypingIndicatorView.swift index 4e3014519..a90200b19 100644 --- a/Signal/src/views/TypingIndicatorView.swift +++ b/Signal/src/views/TypingIndicatorView.swift @@ -38,8 +38,31 @@ self.axis = .horizontal self.spacing = kDotMaxHSpacing self.alignment = .center + + NotificationCenter.default.addObserver(self, + selector: #selector(didBecomeActive), + name: NSNotification.Name.OWSApplicationDidBecomeActive, + object: nil) + } + + deinit { + NotificationCenter.default.removeObserver(self) + } + + // MARK: - Notifications + + @objc func didBecomeActive() { + AssertIsOnMainThread() + + // CoreAnimation animations are stopped in the background, so ensure + // animations are restored if necessary. + if isAnimating { + startAnimation() + } } + // MARK: - + @objc public override func sizeThatFits(_ size: CGSize) -> CGSize { return CGSize(width: TypingIndicatorView.kMaxRadiusPt * 3 + kDotMaxHSpacing * 2, height: TypingIndicatorView.kMaxRadiusPt) @@ -49,8 +72,12 @@ return [dot1, dot2, dot3] } + private var isAnimating = false + @objc public func startAnimation() { + isAnimating = true + for dot in dots() { dot.startAnimation() } @@ -58,6 +85,8 @@ @objc public func stopAnimation() { + isAnimating = false + for dot in dots() { dot.stopAnimation() }