@@ -30,91 +30,132 @@ class StrokeTextView: RCTView {
3030
3131 @objc var width : NSNumber = 0 {
3232 didSet {
33- self . label. customWidth = CGFloat ( truncating: width)
33+ if width != oldValue {
34+ self . label. customWidth = CGFloat ( truncating: width)
35+ label. setNeedsDisplay ( )
36+ }
3437 }
3538 }
3639
3740 @objc var text : String = " " {
3841 didSet {
39- label. text = text
42+ if text != oldValue {
43+ label. text = text
44+ label. setNeedsDisplay ( )
45+ }
4046 }
4147 }
4248
4349 @objc var fontSize : NSNumber = 14 {
4450 didSet {
45- label. font = label. font. withSize ( CGFloat ( truncating: fontSize) )
51+ if fontSize != oldValue {
52+ label. font = label. font. withSize ( CGFloat ( truncating: fontSize) )
53+ label. setNeedsDisplay ( )
54+ }
4655 }
4756 }
4857
4958 @objc var color : String = " #000000 " {
5059 didSet {
51- label. textColor = hexStringToUIColor ( hexColor: color)
60+ if color != oldValue {
61+ label. textColor = colorStringToUIColor ( colorString: color)
62+ label. setNeedsDisplay ( )
63+ }
5264 }
5365 }
5466
5567 @objc var strokeColor : String = " #FFFFFF " {
5668 didSet {
57- label. outlineColor = hexStringToUIColor ( hexColor: strokeColor)
69+ if strokeColor != oldValue {
70+ label. outlineColor = colorStringToUIColor ( colorString: strokeColor)
71+ label. setNeedsDisplay ( )
72+ }
5873 }
5974 }
6075
6176 @objc var strokeWidth : NSNumber = 1 {
6277 didSet {
63- label. outlineWidth = CGFloat ( truncating: strokeWidth)
78+ if strokeWidth != oldValue {
79+ label. outlineWidth = CGFloat ( truncating: strokeWidth)
80+ label. setNeedsDisplay ( )
81+ }
6482 }
6583 }
6684
6785 @objc var fontFamily : String = " Helvetica " {
6886 didSet {
69- if let font = UIFont ( name: fontFamily, size: CGFloat ( truncating: fontSize) ) {
70- label. font = font
87+ if fontFamily != oldValue {
88+ if let font = UIFont ( name: fontFamily, size: CGFloat ( truncating: fontSize) ) {
89+ label. font = font
90+ }
91+ label. setNeedsDisplay ( )
7192 }
7293 }
7394 }
7495
7596 @objc var align : String = " center " {
7697 didSet {
77- if align == " left " {
78- label. align = . left
79- } else if align == " right " {
80- label. align = . right
81- } else {
82- label. align = . center
98+ if align != oldValue {
99+ if align == " left " {
100+ label. align = . left
101+ } else if align == " right " {
102+ label. align = . right
103+ } else {
104+ label. align = . center
105+ }
106+
107+ label. setNeedsDisplay ( )
83108 }
84109 }
85110 }
86111
87112 @objc var ellipsis : Bool = false {
88113 didSet {
89- label. ellipsis = ellipsis
114+ if ellipsis != oldValue {
115+ label. ellipsis = ellipsis
116+ label. setNeedsDisplay ( )
117+ }
90118 }
91119 }
92120
93121 @objc var numberOfLines : NSNumber = 0 {
94122 didSet {
95- label. numberOfLines = Int ( truncating: numberOfLines)
123+ if numberOfLines != oldValue {
124+ label. numberOfLines = Int ( truncating: numberOfLines)
125+ label. setNeedsDisplay ( )
126+ }
96127 }
97128 }
98129
99- private func hexStringToUIColor ( hexColor : String ) -> UIColor {
100- var cString : String = hexColor . trimmingCharacters ( in: . whitespacesAndNewlines) . uppercased ( )
130+ private func colorStringToUIColor ( colorString : String ) -> UIColor {
131+ var string = colorString . trimmingCharacters ( in: . whitespacesAndNewlines) . uppercased ( )
101132
102- if cString. hasPrefix ( " # " ) {
103- cString. removeFirst ( )
104- }
105-
106- if cString. count != 6 {
107- return UIColor . gray
133+ if string. hasPrefix ( " # " ) {
134+ if string. count == 4 {
135+ string = " # " + string. dropFirst ( ) . map { " \( $0) \( $0) " } . joined ( )
136+ }
137+ if string. count == 7 {
138+ var rgbValue : UInt64 = 0
139+ Scanner ( string: String ( string. dropFirst ( ) ) ) . scanHexInt64 ( & rgbValue)
140+ return UIColor (
141+ red: CGFloat ( ( rgbValue & 0xFF0000 ) >> 16 ) / 255.0 ,
142+ green: CGFloat ( ( rgbValue & 0x00FF00 ) >> 8 ) / 255.0 ,
143+ blue: CGFloat ( rgbValue & 0x0000FF ) / 255.0 ,
144+ alpha: 1.0
145+ )
146+ }
147+ } else if string. hasPrefix ( " RGBA " ) {
148+ let components = string. dropFirst ( 5 ) . dropLast ( 1 ) . split ( separator: " , " ) . map { CGFloat ( Double ( $0. trimmingCharacters ( in: . whitespaces) ) ?? 0 ) }
149+ if components. count == 4 {
150+ return UIColor ( red: components [ 0 ] / 255.0 , green: components [ 1 ] / 255.0 , blue: components [ 2 ] / 255.0 , alpha: components [ 3 ] )
151+ }
152+ } else if string. hasPrefix ( " RGB " ) {
153+ let components = string. dropFirst ( 4 ) . dropLast ( 1 ) . split ( separator: " , " ) . map { CGFloat ( Double ( $0. trimmingCharacters ( in: . whitespaces) ) ?? 0 ) }
154+ if components. count == 3 {
155+ return UIColor ( red: components [ 0 ] / 255.0 , green: components [ 1 ] / 255.0 , blue: components [ 2 ] / 255.0 , alpha: 1.0 )
156+ }
108157 }
109158
110- var rgbValue : UInt64 = 0
111- Scanner ( string: cString) . scanHexInt64 ( & rgbValue)
112-
113- return UIColor (
114- red: CGFloat ( ( rgbValue & 0xFF0000 ) >> 16 ) / 255.0 ,
115- green: CGFloat ( ( rgbValue & 0x00FF00 ) >> 8 ) / 255.0 ,
116- blue: CGFloat ( rgbValue & 0x0000FF ) / 255.0 ,
117- alpha: CGFloat ( 1.0 )
118- )
159+ return UIColor . gray
119160 }
120161}
0 commit comments