From a4aab0bdcd3a0547491f3cb13c37496b83dad57d Mon Sep 17 00:00:00 2001 From: Eric Bailey Date: Thu, 28 Aug 2025 15:08:55 -0500 Subject: [PATCH] Bump picker, add patch for next version --- package.json | 2 +- patches/expo-image-picker+17.0.4.patch | 81 +++++++++++++++++++++++ patches/expo-image-picker+17.0.4.patch.md | 7 ++ yarn.lock | 8 +-- 4 files changed, 93 insertions(+), 5 deletions(-) create mode 100644 patches/expo-image-picker+17.0.4.patch create mode 100644 patches/expo-image-picker+17.0.4.patch.md diff --git a/package.json b/package.json index 5dc5ef96a1..66f11f0732 100644 --- a/package.json +++ b/package.json @@ -146,7 +146,7 @@ "expo-image": "^2.4.0", "expo-image-crop-tool": "^0.1.8", "expo-image-manipulator": "~13.1.7", - "expo-image-picker": "^17.0.2", + "expo-image-picker": "17.0.4", "expo-intent-launcher": "^12.1.5", "expo-linear-gradient": "~14.1.5", "expo-linking": "~7.1.5", diff --git a/patches/expo-image-picker+17.0.4.patch b/patches/expo-image-picker+17.0.4.patch new file mode 100644 index 0000000000..5469495b6f --- /dev/null +++ b/patches/expo-image-picker+17.0.4.patch @@ -0,0 +1,81 @@ +diff --git a/node_modules/expo-image-picker/ios/ImageUtils.swift b/node_modules/expo-image-picker/ios/ImageUtils.swift +index 20c86d6..1adee0b 100644 +--- a/node_modules/expo-image-picker/ios/ImageUtils.swift ++++ b/node_modules/expo-image-picker/ios/ImageUtils.swift +@@ -350,25 +350,33 @@ internal struct ImageUtils { + } + + /* +- * Extracts the pixel dimensions from an image file. +- * This method efficiently reads metadata without loading the entire image into memory. ++ * Extracts the visual dimensions from an image file, accounting for EXIF orientation. ++ * This ensures portrait images return portrait dimensions (height > width). + * @param url The file URL of the image to analyze +- * @return A CGSize containing the width and height, or nil if the dimensions cannot be determined ++ * @return A CGSize containing the visual width and height, or nil if the dimensions cannot be determined + */ +- static func readSizeFrom(url: URL) -> CGSize? { +- // First, try to fetch the dimensions from the image metadata as this is the fastest way +- if let imageSource = CGImageSourceCreateWithURL(url as CFURL, nil), ++ static func readVisualSizeFrom(url: URL) -> CGSize? { ++ // Try to fetch the dimensions from the image metadata as this is the fastest way ++ guard let imageSource = CGImageSourceCreateWithURL(url as CFURL, nil), + let properties = CGImageSourceCopyPropertiesAtIndex(imageSource, 0, nil) as? [CFString: Any], + let width = properties[kCGImagePropertyPixelWidth] as? CGFloat, +- let height = properties[kCGImagePropertyPixelHeight] as? CGFloat { +- return CGSize(width: width, height: height) ++ let height = properties[kCGImagePropertyPixelHeight] as? CGFloat else { ++ // Fallback: minimally decode the image using UIImage when metadata is not available ++ if let img = UIImage(contentsOfFile: url.path) { ++ return CGSize(width: img.size.width, height: img.size.height) ++ } ++ return nil + } + +- // Fallback: minimally decode the image using UIImage when metadata is not available +- if let img = UIImage(contentsOfFile: url.path) { +- return CGSize(width: img.size.width, height: img.size.height) ++ // Check EXIF orientation to determine if dimensions should be swapped ++ let orientation = properties[kCGImagePropertyOrientation] as? Int ?? 1 ++ ++ // Orientations 5,6,7,8 (left/right rotated) need dimension swapping ++ if orientation >= 5 && orientation <= 8 { ++ return CGSize(width: height, height: width) // Swap for portrait + } + +- return nil ++ // Keep as is for landscape ++ return CGSize(width: width, height: height) + } + } +diff --git a/node_modules/expo-image-picker/ios/MediaHandler.swift b/node_modules/expo-image-picker/ios/MediaHandler.swift +index 72ae9ee..6e4fbe1 100644 +--- a/node_modules/expo-image-picker/ios/MediaHandler.swift ++++ b/node_modules/expo-image-picker/ios/MediaHandler.swift +@@ -97,7 +97,7 @@ internal struct MediaHandler { + imageData: imageData, orImageFileUrl: targetUrl, tryReadingFile: fileWasCopied) : nil + + let exif = options.exif ? await ImageUtils.readExifFrom(mediaInfo: mediaInfo) : nil +- let size = ImageUtils.readSizeFrom(url: targetUrl) ?? .zero ++ let size = CGSize(width: image.size.width, height: image.size.height) + + return AssetInfo( + assetId: asset?.localIdentifier, +@@ -144,7 +144,7 @@ internal struct MediaHandler { + let cachedUrl = targetUrl + let fileExtension = "." + cachedUrl.pathExtension + +- let size = ImageUtils.readSizeFrom(url: cachedUrl) ?? .zero ++ let size = ImageUtils.readVisualSizeFrom(url: cachedUrl) ?? .zero + let fileSize = getFileSize(from: cachedUrl) + let mimeType = getMimeType(from: cachedUrl.pathExtension) + let fileName = itemProvider.suggestedName.map { $0 + fileExtension } +@@ -197,7 +197,7 @@ internal struct MediaHandler { + let exif = options.exif ? ImageUtils.readExifFrom(data: rawData) : nil + let base64 = options.base64 ? imageData?.base64EncodedString() : nil + +- let size = ImageUtils.readSizeFrom(url: targetUrl) ?? .zero ++ let size = CGSize(width: image.size.width, height: image.size.height) + + return AssetInfo( + assetId: selectedImage.assetIdentifier, diff --git a/patches/expo-image-picker+17.0.4.patch.md b/patches/expo-image-picker+17.0.4.patch.md new file mode 100644 index 0000000000..e3589e584a --- /dev/null +++ b/patches/expo-image-picker+17.0.4.patch.md @@ -0,0 +1,7 @@ +## expo-image-picker + +Temp patch for iOS, fixes an issue where dimensions do not match the orientation +of the image. + +Can be removed once https://github.com/expo/expo/pull/39230 is merged and +published. diff --git a/yarn.lock b/yarn.lock index fa715c8940..130d92a729 100644 --- a/yarn.lock +++ b/yarn.lock @@ -11339,10 +11339,10 @@ expo-image-manipulator@~13.1.7: dependencies: expo-image-loader "~5.1.0" -expo-image-picker@^17.0.2: - version "17.0.2" - resolved "https://registry.yarnpkg.com/expo-image-picker/-/expo-image-picker-17.0.2.tgz#79af7192b2947e54686d0ece6ccbb5f6a178a809" - integrity sha512-O74FIrc37KB4ZxC/BMUL3fEZwdmIB60As0q5XczRlzPvWismBl7GG3pPy+o5SGUI2jcepTvQAa2PcNcMbUZNYg== +expo-image-picker@17.0.4: + version "17.0.4" + resolved "https://registry.yarnpkg.com/expo-image-picker/-/expo-image-picker-17.0.4.tgz#a251949d0c1f5508fac4cd32bdc2fd835a13e204" + integrity sha512-hBFtxAKbQRfOVjf1WdEXMfRJyDXi/YKqv26pVK4wiPZ2F3nFClGKW0OL6w52pyZ7z9hhVGCi5WrWy4CwyVxOEg== dependencies: expo-image-loader "~6.0.0"