Skip to content

Commit a293931

Browse files
Refactoring backgroundColor(withDistanceRatio:)
1 parent c68f4a2 commit a293931

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

Gemini/GeminiAnimationModel.swift

+6-4
Original file line numberDiff line numberDiff line change
@@ -180,15 +180,17 @@ final class GeminiAnimationModel {
180180

181181
func backgroundColor(withDistanceRatio ratio: CGFloat) -> UIColor? {
182182
// sc = Start backgroundColor components
183-
let sc = startBackgroundColor?.cgColor.components ?? []
183+
let startColorComponents = startBackgroundColor?.cgColor.components ?? []
184184
// ec = End backgroundColor components
185-
let ec = endBackgroundColor?.cgColor.components ?? []
185+
let endColorComponents = endBackgroundColor?.cgColor.components ?? []
186186

187-
if sc.isEmpty || sc.count < 3 || ec.isEmpty || ec.count < 3 {
187+
if startColorComponents.isEmpty || startColorComponents.count < 3 || endColorComponents.isEmpty || endColorComponents.count < 3 {
188188
return nil
189189
}
190190

191-
let components = (0...3).map { (ec[$0] - sc[$0]) * abs(ratio) + sc[$0] }
191+
let components = (0...3).map { index -> CGFloat in
192+
(endColorComponents[index] - startColorComponents[index]) * abs(ratio) + startColorComponents[index]
193+
}
192194
return UIColor(red: components[0], green: components[1], blue: components[2], alpha: components[3])
193195
}
194196

0 commit comments

Comments
 (0)