-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathLoaderKitViewManager.swift
91 lines (79 loc) · 3.69 KB
/
LoaderKitViewManager.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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
import NVActivityIndicatorView
@objc(LoaderKitViewManager)
class LoaderKitViewManager: RCTViewManager {
override func view() -> (LoaderKitView) {
return LoaderKitView()
}
@objc override static func requiresMainQueueSetup() -> Bool {
return true
}
}
class LoaderKitView : UIView {
let animations = [
"BallPulse": NVActivityIndicatorType.ballPulse,
"BallGridPulse": NVActivityIndicatorType.ballGridPulse,
"BallClipRotate": NVActivityIndicatorType.ballClipRotate,
"SquareSpin": NVActivityIndicatorType.squareSpin,
"BallClipRotatePulse": NVActivityIndicatorType.ballClipRotatePulse,
"BallClipRotateMultiple": NVActivityIndicatorType.ballClipRotateMultiple,
"BallPulseRise": NVActivityIndicatorType.ballPulseRise,
"BallRotate": NVActivityIndicatorType.ballRotate,
"CubeTransition": NVActivityIndicatorType.cubeTransition,
"BallZigZag": NVActivityIndicatorType.ballZigZag,
"BallZigZagDeflect": NVActivityIndicatorType.ballZigZagDeflect,
"BallTrianglePath": NVActivityIndicatorType.ballTrianglePath,
"BallScale": NVActivityIndicatorType.ballScale,
"LineScale": NVActivityIndicatorType.lineScale,
"LineScaleParty": NVActivityIndicatorType.lineScaleParty,
"BallScaleMultiple": NVActivityIndicatorType.ballScaleMultiple,
"BallPulseSync": NVActivityIndicatorType.ballPulseSync,
"BallBeat": NVActivityIndicatorType.ballBeat,
"BallDoubleBounce": NVActivityIndicatorType.ballDoubleBounce,
"LineScalePulseOut": NVActivityIndicatorType.lineScalePulseOut,
"LineScalePulseOutRapid": NVActivityIndicatorType.lineScalePulseOutRapid,
"BallScaleRipple": NVActivityIndicatorType.ballScaleRipple,
"BallScaleRippleMultiple": NVActivityIndicatorType.ballScaleRippleMultiple,
"BallSpinFadeLoader": NVActivityIndicatorType.ballSpinFadeLoader,
"LineSpinFadeLoader": NVActivityIndicatorType.lineSpinFadeLoader,
"TriangleSkewSpin": NVActivityIndicatorType.triangleSkewSpin,
"Pacman": NVActivityIndicatorType.pacman,
"BallGridBeat": NVActivityIndicatorType.ballGridBeat,
"SemiCircleSpin": NVActivityIndicatorType.semiCircleSpin,
"BallRotateChase": NVActivityIndicatorType.ballRotateChase,
"Orbit": NVActivityIndicatorType.orbit,
"AudioEqualizer": NVActivityIndicatorType.audioEqualizer,
"CircleStrokeSpin": NVActivityIndicatorType.circleStrokeSpin,
]
private var loader = NVActivityIndicatorView(frame: .zero, type: NVActivityIndicatorView.DEFAULT_TYPE)
override init(frame: CGRect) {
super.init(frame: frame)
addSubview(loader)
loader.translatesAutoresizingMaskIntoConstraints = false
NSLayoutConstraint.activate([
loader.leadingAnchor.constraint(equalTo: leadingAnchor),
loader.trailingAnchor.constraint(equalTo: trailingAnchor),
loader.topAnchor.constraint(equalTo: topAnchor),
loader.bottomAnchor.constraint(equalTo: bottomAnchor),
])
loader.startAnimating()
}
required init?(coder aDecoder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
@objc
var name: NSString? {
didSet {
loader.stopAnimating()
loader.type = (name != nil ? animations[name! as String] : animations["BallPulse"])!
loader.startAnimating()
}
}
@objc
var color: NSNumber? {
didSet {
loader.stopAnimating()
loader.color = color != nil ? RCTConvert.uiColor(color) : .white
loader.startAnimating()
}
}
}