@@ -49,69 +49,43 @@ class LoaderKitView : UIView {
4949 " CircleStrokeSpin " : NVActivityIndicatorType . circleStrokeSpin,
5050 ]
5151
52- var loader : NVActivityIndicatorView !
53- var currentSize = 48.0
52+ private var loader = NVActivityIndicatorView ( frame: . zero, type: NVActivityIndicatorView . DEFAULT_TYPE)
5453
5554 override init ( frame: CGRect ) {
5655 super. init ( frame: frame)
5756
58- let frameObj = CGRect ( x: 0 , y: 0 , width: 200 , height: 200 )
59- self . loader = NVActivityIndicatorView ( frame: frameObj, type: NVActivityIndicatorView . DEFAULT_TYPE)
60- self . addSubview ( self . loader)
61- self . loader. startAnimating ( )
57+ addSubview ( loader)
58+
59+ loader. translatesAutoresizingMaskIntoConstraints = false
60+ NSLayoutConstraint . activate ( [
61+ loader. leadingAnchor. constraint ( equalTo: leadingAnchor) ,
62+ loader. trailingAnchor. constraint ( equalTo: trailingAnchor) ,
63+ loader. topAnchor. constraint ( equalTo: topAnchor) ,
64+ loader. bottomAnchor. constraint ( equalTo: bottomAnchor) ,
65+ ] )
66+
67+ loader. startAnimating ( )
6268 }
6369
6470 required init ? ( coder aDecoder: NSCoder ) {
6571 fatalError ( " init(coder:) has not been implemented " )
6672 }
6773
68- @objc
69- var size : NSNumber ? {
70- set {
71- if newValue != nil {
72- self . loader. stopAnimating ( )
73- let frameObj = CGRect ( x: 0 , y: 0 , width: newValue!. doubleValue, height: newValue!. doubleValue)
74- self . loader. frame = frameObj
75- self . loader. startAnimating ( )
76-
77- self . currentSize = newValue!. doubleValue
78- }
79- }
80- get {
81- return nil ;
82- }
83- }
84-
8574 @objc
8675 var name : NSString ? {
87- set {
88- if newValue != nil && animations [ newValue! as String ] != nil {
89- self . loader. stopAnimating ( )
90- let frameObj = CGRect ( x: 0 , y: 0 , width: self . currentSize, height: self . currentSize)
91- self . loader. frame = frameObj
92- self . loader. type = animations [ newValue! as String ] !
93- self . loader. startAnimating ( )
94-
95- }
96- }
97- get {
98- return nil ;
76+ didSet {
77+ loader. stopAnimating ( )
78+ loader. type = ( name != nil ? animations [ name! as String ] : animations [ " BallPulse " ] ) !
79+ loader. startAnimating ( )
9980 }
10081 }
10182
10283 @objc
10384 var color : NSNumber ? {
104- set {
105- if newValue != nil {
106- self . loader. stopAnimating ( )
107- let frameObj = CGRect ( x: 0 , y: 0 , width: self . currentSize, height: self . currentSize)
108- self . loader. frame = frameObj
109- self . loader. color = RCTConvert . uiColor ( newValue)
110- self . loader. startAnimating ( )
111- }
112- }
113- get {
114- return nil ;
85+ didSet {
86+ loader. stopAnimating ( )
87+ loader. color = color != nil ? RCTConvert . uiColor ( color) : . white
88+ loader. startAnimating ( )
11589 }
11690 }
11791}
0 commit comments