Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@ class ConnectionStatusIndicatorView : UIView {
self.setNeedsDisplay()
if state == .connecting {
if displayLink == nil {
let selector = #selector(setNeedsDisplay as () -> Void)
displayLink = CADisplayLink(target: self, selector:selector)
displayLink = CADisplayLink(target: self, selector: #selector(setNeedsDisplayProxy(_:)))
}
displayLink?.add(to: RunLoop.main, forMode: RunLoopMode.commonModes)
} else {
Expand Down Expand Up @@ -48,11 +47,11 @@ class ConnectionStatusIndicatorView : UIView {
context.fillPath()
}

fileprivate func timebasedValue() -> CGFloat {
private func timebasedValue() -> CGFloat {
return CGFloat(abs(sin(Date().timeIntervalSinceReferenceDate*4)))
}

fileprivate func fillColor() -> CGColor {
private func fillColor() -> CGColor {
switch state {
case .disconnected:
return UIColor.red.cgColor
Expand All @@ -62,4 +61,11 @@ class ConnectionStatusIndicatorView : UIView {
return UIColor.green.cgColor
}
}

// Needed because CADisplayLink(target:, selector:)
// waits for selector method having signature `(void)selector:(CADisplayLink *)sender`
// https://developer.apple.com/documentation/quartzcore/cadisplaylink/1621228-init
@objc private func setNeedsDisplayProxy(_ sender: CADisplayLink) {
setNeedsLayout()
}
}