Skip to content

Commit 04003fc

Browse files
committed
refactor: move orientation mapping to CGImagePropertyOrientation extension
1 parent fa2dd0b commit 04003fc

File tree

1 file changed

+18
-13
lines changed

1 file changed

+18
-13
lines changed

ios/HybridImageFactory.swift

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -89,19 +89,8 @@ class HybridImageFactory: HybridImageFactorySpec {
8989
if let error = info?[PHImageErrorKey] as? Error {
9090
continuation.resume(throwing: error)
9191
} else if let imageData = imageData,
92-
let cgImage = UIImage(data:imageData)?.cgImage {
93-
let uiImageOrientation: UIImage.Orientation
94-
switch orientation {
95-
case .up: uiImageOrientation = .up
96-
case .upMirrored: uiImageOrientation = .upMirrored
97-
case .down: uiImageOrientation = .down
98-
case .downMirrored: uiImageOrientation = .downMirrored
99-
case .left: uiImageOrientation = .left
100-
case .leftMirrored: uiImageOrientation = .leftMirrored
101-
case .right: uiImageOrientation = .right
102-
case .rightMirrored: uiImageOrientation = .rightMirrored
103-
}
104-
let uiImage = UIImage(cgImage: cgImage, scale: 1, orientation: uiImageOrientation)
92+
let cgImage = UIImage(data: imageData)?.cgImage {
93+
let uiImage = UIImage(cgImage: cgImage, scale: 1, orientation: orientation.uiImageOrientation)
10594
continuation.resume(returning: HybridImage(uiImage: uiImage))
10695
} else {
10796
continuation.resume(
@@ -187,3 +176,19 @@ class HybridImageFactory: HybridImageFactorySpec {
187176
}
188177
}
189178
}
179+
180+
extension CGImagePropertyOrientation {
181+
/// Converts `CGImagePropertyOrientation` to `UIImage.Orientation`
182+
var uiImageOrientation: UIImage.Orientation {
183+
switch self {
184+
case .up: return .up
185+
case .upMirrored: return .upMirrored
186+
case .down: return .down
187+
case .downMirrored: return .downMirrored
188+
case .left: return .left
189+
case .leftMirrored: return .leftMirrored
190+
case .right: return .right
191+
case .rightMirrored: return .rightMirrored
192+
}
193+
}
194+
}

0 commit comments

Comments
 (0)