Skip to content

Commit c5b79ee

Browse files
committed
fix(canvas-ios): scanHex warning
1 parent 1879168 commit c5b79ee

File tree

1 file changed

+21
-8
lines changed

1 file changed

+21
-8
lines changed

packages/canvas/src-native/canvas-ios/CanvasNative/Source/TNSColors.swift

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -205,14 +205,27 @@ extension UIColor {
205205
let fourth = cString[3..<4]
206206
cString = "" + first + first + second + second + third + third + fourth + fourth
207207
}
208-
var rgbValue:UInt32 = 0
209-
Scanner(string: cString).scanHexInt32(&rgbValue)
210-
self.init(
211-
red: CGFloat((rgbValue & 0xFF0000) >> 16) / 255.0,
212-
green: CGFloat((rgbValue & 0x00FF00) >> 8) / 255.0,
213-
blue: CGFloat(rgbValue & 0x0000FF) / 255.0,
214-
alpha: CGFloat(1.0)
215-
)
208+
209+
if #available(iOS 13.0, *){
210+
var rgbValue:UInt64 = 0
211+
Scanner(string: cString).scanHexInt64(&rgbValue)
212+
self.init(
213+
red: CGFloat((rgbValue & 0xFF0000) >> 16) / 255.0,
214+
green: CGFloat((rgbValue & 0x00FF00) >> 8) / 255.0,
215+
blue: CGFloat(rgbValue & 0x0000FF) / 255.0,
216+
alpha: CGFloat(1.0)
217+
)
218+
}else {
219+
var rgbValue:UInt32 = 0
220+
Scanner(string: cString).scanHexInt32(&rgbValue)
221+
self.init(
222+
red: CGFloat((rgbValue & 0xFF0000) >> 16) / 255.0,
223+
green: CGFloat((rgbValue & 0x00FF00) >> 8) / 255.0,
224+
blue: CGFloat(rgbValue & 0x0000FF) / 255.0,
225+
alpha: CGFloat(1.0)
226+
)
227+
}
228+
216229
}else if(string.starts(with: "rgba")){
217230
let rgba = string.replacingOccurrences(of: "rgba(", with: "").replacingOccurrences(of: ")", with: "").replacingOccurrences(of: " ", with: "").split(separator: ",")
218231
let formatter = NumberFormatter()

0 commit comments

Comments
 (0)