Restart typing indicators animations after app returns from background.

This commit is contained in:
Matthew Chen 2019-03-29 14:25:17 -04:00
parent a98bfee645
commit 746fd278da
1 changed files with 29 additions and 0 deletions

View File

@ -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()
}