From 5d803ecab64211bc2ad2b34812f637982ebf7e8b Mon Sep 17 00:00:00 2001 From: Saad Najmi Date: Tue, 9 Jan 2024 12:14:08 -0800 Subject: [PATCH] Refactor to use UniformTypeIdentifiers framework --- .../Libraries/Image/RCTImageStoreManager.mm | 8 ++++---- .../Libraries/Image/RCTImageUtils.mm | 8 +++----- .../Libraries/Image/React-RCTImage.podspec | 1 + .../Libraries/Network/RCTFileRequestHandler.mm | 16 ++++++++-------- .../Libraries/Network/React-RCTNetwork.podspec | 2 +- .../Libraries/Text/React-RCTText.podspec | 2 +- .../Libraries/Text/Text/RCTTextView.mm | 8 +++----- .../Text/RCTParagraphComponentView.mm | 8 +++----- .../react-native/React/React-RCTFabric.podspec | 3 +-- packages/react-native/React/Views/RCTView.m | 4 ++-- 10 files changed, 27 insertions(+), 33 deletions(-) diff --git a/packages/react-native/Libraries/Image/RCTImageStoreManager.mm b/packages/react-native/Libraries/Image/RCTImageStoreManager.mm index 3b151604b8c3fd..52f4f653c940cc 100644 --- a/packages/react-native/Libraries/Image/RCTImageStoreManager.mm +++ b/packages/react-native/Libraries/Image/RCTImageStoreManager.mm @@ -12,9 +12,8 @@ #import #import -#if !TARGET_OS_OSX // [macOS] -#import -#endif // [macOS] +#import + #import #import #import @@ -177,7 +176,8 @@ - (id)sendRequest:(NSURLRequest *)request withDelegate:(id #import -#if !TARGET_OS_OSX // [macOS] -#import -#endif // [macOS] +#import #import #import @@ -356,10 +354,10 @@ BOOL RCTUpscalingRequired( if (RCTImageHasAlpha(cgImage)) { // get png data - destination = CGImageDestinationCreateWithData(imageData, kUTTypePNG, 1, NULL); + destination = CGImageDestinationCreateWithData(imageData, (__bridge CFStringRef)UTTypePNG.identifier, 1, NULL); } else { // get jpeg data - destination = CGImageDestinationCreateWithData(imageData, kUTTypeJPEG, 1, NULL); + destination = CGImageDestinationCreateWithData(imageData, (__bridge CFStringRef)UTTypeJPEG.identifier, 1, NULL); [properties setValue:@(quality) forKey:(id)kCGImageDestinationLossyCompressionQuality]; } if (!destination) { diff --git a/packages/react-native/Libraries/Image/React-RCTImage.podspec b/packages/react-native/Libraries/Image/React-RCTImage.podspec index 3946a21fdf3318..1376ab794f5abe 100644 --- a/packages/react-native/Libraries/Image/React-RCTImage.podspec +++ b/packages/react-native/Libraries/Image/React-RCTImage.podspec @@ -52,6 +52,7 @@ Pod::Spec.new do |s| "HEADER_SEARCH_PATHS" => header_search_paths.join(' ') } s.ios.framework = ["Accelerate", "UIKit"] # [macOS] Restrict UIKit to iOS + s.visionos.framework = ["Accelerate", "UIKit"] # [macOS] Restrict UIKit to iOS s.osx.framework = ["Accelerate"] # [macOS] s.dependency "RCT-Folly", folly_version diff --git a/packages/react-native/Libraries/Network/RCTFileRequestHandler.mm b/packages/react-native/Libraries/Network/RCTFileRequestHandler.mm index 5838e167f96d55..ddab504a35ed9d 100644 --- a/packages/react-native/Libraries/Network/RCTFileRequestHandler.mm +++ b/packages/react-native/Libraries/Network/RCTFileRequestHandler.mm @@ -7,11 +7,8 @@ #import -#if !TARGET_OS_OSX // [macOS] -#import -#else // [macOS -#import -#endif // macOS] +#import + #import #import @@ -59,10 +56,13 @@ - (NSOperation *)sendRequest:(NSURLRequest *)request withDelegate:(id "c++20", "HEADER_SEARCH_PATHS" => header_search_paths.join(' ') } - s.ios.frameworks = "MobileCoreServices" # [macOS] Restrict to iOS + s.frameworks = "UniformTypeIdentifiers" # [macOS] s.dependency "RCT-Folly", folly_version s.dependency "React-Codegen", version diff --git a/packages/react-native/Libraries/Text/React-RCTText.podspec b/packages/react-native/Libraries/Text/React-RCTText.podspec index 800b5f726654ac..a05b9abf36d458 100644 --- a/packages/react-native/Libraries/Text/React-RCTText.podspec +++ b/packages/react-native/Libraries/Text/React-RCTText.podspec @@ -30,7 +30,7 @@ Pod::Spec.new do |s| s.ios.exclude_files = "**/macOS/*" # [macOS] s.preserve_paths = "package.json", "LICENSE", "LICENSE-docs" s.header_dir = "RCTText" - s.ios.framework = ["MobileCoreServices"] # [macOS] Restrict to iOS + s.framework = ["UniformTypeIdentifiers"] # [macOS] s.pod_target_xcconfig = { "CLANG_CXX_LANGUAGE_STANDARD" => "c++20" } s.dependency "Yoga" diff --git a/packages/react-native/Libraries/Text/Text/RCTTextView.mm b/packages/react-native/Libraries/Text/Text/RCTTextView.mm index 504720170a2b40..1d57feb89f4410 100644 --- a/packages/react-native/Libraries/Text/Text/RCTTextView.mm +++ b/packages/react-native/Libraries/Text/Text/RCTTextView.mm @@ -7,9 +7,7 @@ #import -#if !TARGET_OS_OSX // [macOS] -#import -#endif // [macOS] +#import #import // [macOS] #import @@ -545,10 +543,10 @@ - (void)copy:(id)sender NSMutableDictionary *item = [NSMutableDictionary new]; // [macOS] if (rtf) { - [item setObject:rtf forKey:(id)kUTTypeFlatRTFD]; + [item setObject:rtf forKey:(id)UTTypeFlatRTFD]; } - [item setObject:attributedText.string forKey:(id)kUTTypeUTF8PlainText]; + [item setObject:attributedText.string forKey:(id)UTTypeUTF8PlainText]; UIPasteboard *pasteboard = [UIPasteboard generalPasteboard]; pasteboard.items = @[ item ]; diff --git a/packages/react-native/React/Fabric/Mounting/ComponentViews/Text/RCTParagraphComponentView.mm b/packages/react-native/React/Fabric/Mounting/ComponentViews/Text/RCTParagraphComponentView.mm index a27960e1575d21..38480b67ed6a1c 100644 --- a/packages/react-native/React/Fabric/Mounting/ComponentViews/Text/RCTParagraphComponentView.mm +++ b/packages/react-native/React/Fabric/Mounting/ComponentViews/Text/RCTParagraphComponentView.mm @@ -8,9 +8,7 @@ #import "RCTParagraphComponentView.h" #import "RCTParagraphComponentAccessibilityProvider.h" -#if !TARGET_OS_OSX // [macOS] -#import -#endif // [macOS] +#import #import #import @@ -309,10 +307,10 @@ - (void)copy:(id)sender error:nil]; if (rtf) { - [item setObject:rtf forKey:(id)kUTTypeFlatRTFD]; + [item setObject:rtf forKey:(id)UTTypeFlatRTFD]; } - [item setObject:attributedText.string forKey:(id)kUTTypeUTF8PlainText]; + [item setObject:attributedText.string forKey:(id)UTTypeUTF8PlainText]; #if !TARGET_OS_OSX // [macOS] UIPasteboard *pasteboard = [UIPasteboard generalPasteboard]; diff --git a/packages/react-native/React/React-RCTFabric.podspec b/packages/react-native/React/React-RCTFabric.podspec index f5b994930003c9..0a964655df70c6 100644 --- a/packages/react-native/React/React-RCTFabric.podspec +++ b/packages/react-native/React/React-RCTFabric.podspec @@ -66,8 +66,7 @@ Pod::Spec.new do |s| s.compiler_flags = folly_compiler_flags + ' ' + boost_compiler_flags s.header_dir = "React" s.module_name = "RCTFabric" - s.ios.framework = ["JavaScriptCore", "MobileCoreServices"] # [macOS] Restrict MobileCoreServices to iOS - s.osx.framework = ["JavaScriptCore"] # [macOS] Restrict MobileCoreServices to iOS + s.framework = ["JavaScriptCore", "UniformTypeIdentifiers"] s.pod_target_xcconfig = { "HEADER_SEARCH_PATHS" => header_search_paths, "OTHER_CFLAGS" => "$(inherited) -DRN_FABRIC_ENABLED" + " " + folly_flags, diff --git a/packages/react-native/React/Views/RCTView.m b/packages/react-native/React/Views/RCTView.m index 1c9e45862ad73b..a3a636db1e8c75 100644 --- a/packages/react-native/React/Views/RCTView.m +++ b/packages/react-native/React/Views/RCTView.m @@ -1604,9 +1604,9 @@ - (NSDictionary*)dataTransferInfoFromPasteboard:(NSPasteboard*)pasteboard NSString *MIMETypeString = nil; if (fileURL.pathExtension) { CFStringRef fileExtension = (__bridge CFStringRef)fileURL.pathExtension; - CFStringRef UTI = UTTypeCreatePreferredIdentifierForTag(kUTTagClassFilenameExtension, fileExtension, NULL); + CFStringRef UTI = UTTagClassFilenameExtension; if (UTI != NULL) { - CFStringRef MIMEType = UTTypeCopyPreferredTagWithClass(UTI, kUTTagClassMIMEType); + NSString *MIMEType = UTTagClassMIMEType; CFRelease(UTI); MIMETypeString = (__bridge_transfer NSString *)MIMEType; }