Skip to content

Commit

Permalink
Refactor to use UniformTypeIdentifiers framework
Browse files Browse the repository at this point in the history
  • Loading branch information
Saadnajmi committed Jan 20, 2024
1 parent 32234e3 commit 89f73ed
Show file tree
Hide file tree
Showing 10 changed files with 27 additions and 33 deletions.
8 changes: 4 additions & 4 deletions packages/react-native/Libraries/Image/RCTImageStoreManager.mm
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,8 @@

#import <FBReactNativeSpec/FBReactNativeSpec.h>
#import <ImageIO/ImageIO.h>
#if !TARGET_OS_OSX // [macOS]
#import <MobileCoreServices/UTType.h>
#endif // [macOS]
#import <UniformTypeIdentifiers/UniformTypeIdentifiers.h>

#import <React/RCTAssert.h>
#import <React/RCTImageUtils.h>
#import <React/RCTLog.h>
Expand Down Expand Up @@ -177,7 +176,8 @@ - (id)sendRequest:(NSURLRequest *)request withDelegate:(id<RCTURLRequestDelegate
CFStringRef UTI = CGImageSourceGetType(sourceRef);
CFRelease(sourceRef);

NSString *MIMEType = (__bridge_transfer NSString *)UTTypeCopyPreferredTagWithClass(UTI, kUTTagClassMIMEType);
// NSString *MIMEType = (__bridge_transfer NSString *)UTTypeCopyPreferredTagWithClass(UTI, kUTTagClassMIMEType);
NSString *MIMEType = UTTagClassMIMEType;
NSURLResponse *response = [[NSURLResponse alloc] initWithURL:request.URL
MIMEType:MIMEType
expectedContentLength:imageData.length
Expand Down
8 changes: 3 additions & 5 deletions packages/react-native/Libraries/Image/RCTImageUtils.mm
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,7 @@
#import <tgmath.h>

#import <ImageIO/ImageIO.h>
#if !TARGET_OS_OSX // [macOS]
#import <MobileCoreServices/UTCoreTypes.h>
#endif // [macOS]
#import <UniformTypeIdentifiers/UniformTypeIdentifiers.h>

#import <React/RCTLog.h>
#import <React/RCTUtils.h>
Expand Down Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
16 changes: 8 additions & 8 deletions packages/react-native/Libraries/Network/RCTFileRequestHandler.mm
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,8 @@

#import <React/RCTFileRequestHandler.h>

#if !TARGET_OS_OSX // [macOS]
#import <MobileCoreServices/MobileCoreServices.h>
#else // [macOS
#import <CoreServices/CoreServices.h>
#endif // macOS]
#import <UniformTypeIdentifiers/UniformTypeIdentifiers.h>


#import <React/RCTUtils.h>
#import <ReactCommon/RCTTurboModule.h>
Expand Down Expand Up @@ -59,10 +56,13 @@ - (NSOperation *)sendRequest:(NSURLRequest *)request withDelegate:(id<RCTURLRequ

// Get mime type
NSString *fileExtension = [request.URL pathExtension];
NSString *UTI = (__bridge_transfer NSString *)UTTypeCreatePreferredIdentifierForTag(
kUTTagClassFilenameExtension, (__bridge CFStringRef)fileExtension, NULL);
// NSString *UTI = (__bridge_transfer NSString *)UTTypeCreatePreferredIdentifierForTag(
// kUTTagClassFilenameExtension, (__bridge CFStringRef)fileExtension, NULL);
NSString *UTI = UTTagClassFilenameExtension;
NSString *contentType =
(__bridge_transfer NSString *)UTTypeCopyPreferredTagWithClass((__bridge CFStringRef)UTI, kUTTagClassMIMEType);
// (__bridge_transfer NSString *)UTTypeCopyPreferredTagWithClass((__bridge CFStringRef)UTI, kUTTagClassMIMEType);
UTTagClassMIMEType;


// Send response
NSURLResponse *response = [[NSURLResponse alloc] initWithURL:request.URL
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ Pod::Spec.new do |s|
"CLANG_CXX_LANGUAGE_STANDARD" => "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
Expand Down
2 changes: 1 addition & 1 deletion packages/react-native/Libraries/Text/React-RCTText.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
8 changes: 3 additions & 5 deletions packages/react-native/Libraries/Text/Text/RCTTextView.mm
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,7 @@

#import <React/RCTTextView.h>

#if !TARGET_OS_OSX // [macOS]
#import <MobileCoreServices/UTCoreTypes.h>
#endif // [macOS]
#import <UniformTypeIdentifiers/UniformTypeIdentifiers.h>

#import <React/RCTAssert.h> // [macOS]
#import <React/RCTUtils.h>
Expand Down Expand Up @@ -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 ];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,7 @@
#import "RCTParagraphComponentView.h"
#import "RCTParagraphComponentAccessibilityProvider.h"

#if !TARGET_OS_OSX // [macOS]
#import <MobileCoreServices/UTCoreTypes.h>
#endif // [macOS]
#import <UniformTypeIdentifiers/UniformTypeIdentifiers.h>

#import <react/renderer/components/text/ParagraphComponentDescriptor.h>
#import <react/renderer/components/text/ParagraphProps.h>
Expand Down Expand Up @@ -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];
Expand Down
3 changes: 1 addition & 2 deletions packages/react-native/React/React-RCTFabric.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions packages/react-native/React/Views/RCTView.m
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down

0 comments on commit 89f73ed

Please sign in to comment.