-
Notifications
You must be signed in to change notification settings - Fork 895
/
Copy pathAnimatedBadgeView.swift
50 lines (36 loc) · 1.32 KB
/
AnimatedBadgeView.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
//
// AnimatedBadgeView.swift
// Telegram
//
// Created by Mikhail Filimonov on 30.12.2020.
// Copyright © 2020 Telegram. All rights reserved.
//
import Foundation
import TGUIKit
import SwiftSignalKit
final class AnimatedBadgeView : View {
private let textView: DynamicCounterTextView = DynamicCounterTextView()
override init() {
super.init(frame: .zero)
addSubview(textView)
}
required init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
required init(frame frameRect: NSRect) {
fatalError("init(frame:) has not been implemented")
}
func update(dynamicValue: DynamicCounterTextView.Value, backgroundColor: NSColor, animated: Bool, frame: NSRect) {
textView.update(dynamicValue, animated: animated)
let textFrame = frame.focus(dynamicValue.size)
self.change(size: frame.size, animated: animated)
self.change(pos: frame.origin, animated: animated)
textView.change(size: textFrame.size, animated: animated)
textView.change(pos: textFrame.origin, animated: animated)
self.backgroundColor = backgroundColor
if animated {
layer?.animateBackground()
}
layer?.cornerRadius = frame.height / 2
}
}