Skip to content

Commit 7ad7df4

Browse files
committed
Remove TARGET_OS_UIKITFORMAC macros (facebook#42278)
Summary: There seems to be a lot of `TARGET_OS_UIKITFORMAC` macro in React Native that don't need to be there. Let's remove them. First off, what is `TARGET_OS_UIKITFORMAC` targeting? You might think it's [Mac Catalyst](https://developer.apple.com/mac-catalyst/), if you look at the [commit](facebook@3724810) introducing the ifdefs. However.. that doesn't seem right because `TARGET_OS_MACCATALYST` exists, and is used elsewhere in the codebase. In fact, if you look at this handy comment inside `TargetConditionals.h` (the file that defines all these conditionals), `TARGET_OS_UIKITFORMAC` is not even on there! ``` /* * TARGET_OS_* * * These conditionals specify in which Operating System the generated code will * run. Indention is used to show which conditionals are evolutionary subclasses. * * The MAC/WIN32/UNIX conditionals are mutually exclusive. * The IOS/TV/WATCH/VISION conditionals are mutually exclusive. * * TARGET_OS_WIN32 - Generated code will run on WIN32 API * TARGET_OS_WINDOWS - Generated code will run on Windows * TARGET_OS_UNIX - Generated code will run on some Unix (not macOS) * TARGET_OS_LINUX - Generated code will run on Linux * TARGET_OS_MAC - Generated code will run on a variant of macOS * TARGET_OS_OSX - Generated code will run on macOS * TARGET_OS_IPHONE - Generated code will run on a variant of iOS (firmware, devices, simulator) * TARGET_OS_IOS - Generated code will run on iOS * TARGET_OS_MACCATALYST - Generated code will run on macOS * TARGET_OS_TV - Generated code will run on tvOS * TARGET_OS_WATCH - Generated code will run on watchOS * TARGET_OS_VISION - Generated code will run on visionOS * TARGET_OS_BRIDGE - Generated code will run on bridge devices * TARGET_OS_SIMULATOR - Generated code will run on an iOS, tvOS, watchOS, or visionOS simulator * TARGET_OS_DRIVERKIT - Generated code will run on macOS, iOS, tvOS, watchOS, or visionOS * * TARGET_OS_EMBEDDED - DEPRECATED: Use TARGET_OS_IPHONE and/or TARGET_OS_SIMULATOR instead * TARGET_IPHONE_SIMULATOR - DEPRECATED: Same as TARGET_OS_SIMULATOR * TARGET_OS_NANO - DEPRECATED: Same as TARGET_OS_WATCH * * +--------------------------------------------------------------------------------------+ * | TARGET_OS_MAC | * | +-----+ +------------------------------------------------------------+ +-----------+ | * | | | | TARGET_OS_IPHONE | | | | * | | | | +-----------------+ +----+ +-------+ +--------+ +--------+ | | | | * | | | | | IOS | | | | | | | | | | | | | * | | OSX | | | +-------------+ | | TV | | WATCH | | BRIDGE | | VISION | | | DRIVERKIT | | * | | | | | | MACCATALYST | | | | | | | | | | | | | | * | | | | | +-------------+ | | | | | | | | | | | | | * | | | | +-----------------+ +----+ +-------+ +--------+ +--------+ | | | | * | +-----+ +------------------------------------------------------------+ +-----------+ | * +--------------------------------------------------------------------------------------+ */ ``` Going even deeper into `TargetConditionals.h`, you will see `TARGET_OS_UIKITFORMAC` defined... and it's always 1 when `TARGET_OS_MACCATALYST` is 1, making it feel even more redundant. My current conclusion is it's either another variant of Mac Catalyst (the one where they just run unmodified UIKit maybe..), or it's an older macro back from when Catalyst was still experimental. Either way, it's pretty obvious nobody is running or testing this codepath, and it adds bloat, especially to React Native macOS where we have extra ifdef blocks for macOS support (and eventually visionOS support). Let's remove it. Another change I made while we're here: I've seen this lingering TODO to replace setTargetRect:InView: / setMenuVisible:animated: (deprecated as of iOS 13, below our minimum OS requirement) with showMenuFromView (deprecated as of iOS 16, in line with the availability check). Let's just.... do that? [IOS] [REMOVED] - Remove TARGET_OS_UIKITFORMAC macros Pull Request resolved: facebook#42278 Test Plan: RNTester with Mac Catalyst still compiles: ![Screenshot 2024-01-15 at 12 26 03 AM](https://github.com/facebook/react-native/assets/6722175/015bd37d-f536-43c7-9586-96187cdbd013) Reviewed By: cipolleschi Differential Revision: D52780690 Pulled By: sammy-SC fbshipit-source-id: df6a333e8e15f79de0ce6f538ebd73b92698dcb6
1 parent 229402c commit 7ad7df4

File tree

6 files changed

+12
-137
lines changed

6 files changed

+12
-137
lines changed

packages/react-native/Libraries/Image/RCTUIImageViewAnimated.m

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -193,15 +193,10 @@ - (BOOL)paused
193193

194194
- (void)displayDidRefresh:(CADisplayLink *)displayLink
195195
{
196-
#if TARGET_OS_UIKITFORMAC
197-
// TODO: `displayLink.frameInterval` is not available on UIKitForMac
198-
NSTimeInterval durationToNextRefresh = displayLink.duration;
199-
#else
200196
// displaylink.duration -- time interval between frames, assuming maximumFramesPerSecond
201197
// displayLink.preferredFramesPerSecond (>= iOS 10) -- Set to 30 for displayDidRefresh to be called at 30 fps
202198
// durationToNextRefresh -- Time interval to the next time displayDidRefresh is called
203199
NSTimeInterval durationToNextRefresh = displayLink.targetTimestamp - displayLink.timestamp;
204-
#endif
205200
NSUInteger totalFrameCount = self.totalFrameCount;
206201
NSUInteger currentFrameIndex = self.currentFrameIndex;
207202
NSUInteger nextFrameIndex = (currentFrameIndex + 1) % totalFrameCount;

packages/react-native/Libraries/PushNotificationIOS/RCTPushNotificationManager.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ extern NSString *const RCTRemoteNotificationReceived;
1515
typedef void (^RCTRemoteNotificationCallback)(UIBackgroundFetchResult result);
1616
#endif // [macOS]
1717

18-
#if !TARGET_OS_UIKITFORMAC
1918
+ (void)didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken;
2019
+ (void)didReceiveRemoteNotification:(NSDictionary *)notification;
2120
#if !TARGET_OS_OSX // [macOS]
@@ -27,6 +26,5 @@ typedef void (^RCTRemoteNotificationCallback)(UIBackgroundFetchResult result);
2726
+ (void)didReceiveUserNotification:(NSUserNotification *)notification;
2827
#endif // macOS]
2928
+ (void)didFailToRegisterForRemoteNotificationsWithError:(NSError *)error;
30-
#endif
3129

3230
@end

packages/react-native/Libraries/PushNotificationIOS/RCTPushNotificationManager.mm

Lines changed: 1 addition & 106 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,6 @@
2424

2525
static NSString *const kErrorUnableToRequestPermissions = @"E_UNABLE_TO_REQUEST_PERMISSIONS";
2626

27-
#if !TARGET_OS_UIKITFORMAC
28-
2927
@interface RCTPushNotificationManager () <NativePushNotificationManagerIOSSpec>
3028
@property (nonatomic, strong) NSMutableDictionary *remoteNotificationCallbacks;
3129
@end
@@ -97,16 +95,10 @@ @implementation RCTConvert (UIBackgroundFetchResult)
9795

9896
@end
9997
#endif // [macOS]
100-
#else
101-
@interface RCTPushNotificationManager () <NativePushNotificationManagerIOSSpec>
102-
@end
103-
#endif // TARGET_OS_UIKITFORMAC
10498

10599
@implementation RCTPushNotificationManager
106100

107-
#if !TARGET_OS_UIKITFORMAC
108-
109-
#if !TARGET_OS_OSX // [macOS]
101+
#if TARGET_OS_IOS // [macOS] [visionOS]
110102
/** DEPRECATED. UILocalNotification was deprecated in iOS 10. Please don't add new callsites. */
111103
static NSDictionary *RCTFormatLocalNotification(UILocalNotification *notification)
112104
{
@@ -198,16 +190,13 @@ @implementation RCTPushNotificationManager
198190
return [formatter stringFromDate:date];
199191
}
200192

201-
#endif // TARGET_OS_UIKITFORMAC
202-
203193
RCT_EXPORT_MODULE()
204194

205195
- (dispatch_queue_t)methodQueue
206196
{
207197
return dispatch_get_main_queue();
208198
}
209199

210-
#if !TARGET_OS_UIKITFORMAC
211200
- (void)startObserving
212201
{
213202
[[NSNotificationCenter defaultCenter] addObserver:self
@@ -638,100 +627,6 @@ - (void)handleRemoteNotificationRegistrationError:(NSNotification *)notification
638627
}];
639628
}
640629

641-
#else // TARGET_OS_UIKITFORMAC
642-
643-
RCT_EXPORT_METHOD(onFinishRemoteNotification : (NSString *)notificationId fetchResult : (NSString *)fetchResult)
644-
{
645-
RCTLogError(@"Not implemented: %@", NSStringFromSelector(_cmd));
646-
}
647-
648-
RCT_EXPORT_METHOD(setApplicationIconBadgeNumber : (double)number)
649-
{
650-
RCTLogError(@"Not implemented: %@", NSStringFromSelector(_cmd));
651-
}
652-
653-
RCT_EXPORT_METHOD(getApplicationIconBadgeNumber : (RCTResponseSenderBlock)callback)
654-
{
655-
RCTLogError(@"Not implemented: %@", NSStringFromSelector(_cmd));
656-
}
657-
658-
RCT_EXPORT_METHOD(requestPermissions
659-
: (JS::NativePushNotificationManagerIOS::SpecRequestPermissionsPermission &)permissions resolve
660-
: (RCTPromiseResolveBlock)resolve reject
661-
: (RCTPromiseRejectBlock)reject)
662-
{
663-
RCTLogError(@"Not implemented: %@", NSStringFromSelector(_cmd));
664-
}
665-
666-
RCT_EXPORT_METHOD(abandonPermissions)
667-
{
668-
RCTLogError(@"Not implemented: %@", NSStringFromSelector(_cmd));
669-
}
670-
671-
RCT_EXPORT_METHOD(checkPermissions : (RCTResponseSenderBlock)callback)
672-
{
673-
RCTLogError(@"Not implemented: %@", NSStringFromSelector(_cmd));
674-
}
675-
676-
RCT_EXPORT_METHOD(presentLocalNotification : (JS::NativePushNotificationManagerIOS::Notification &)notification)
677-
{
678-
RCTLogError(@"Not implemented: %@", NSStringFromSelector(_cmd));
679-
}
680-
681-
RCT_EXPORT_METHOD(scheduleLocalNotification : (JS::NativePushNotificationManagerIOS::Notification &)notification)
682-
{
683-
RCTLogError(@"Not implemented: %@", NSStringFromSelector(_cmd));
684-
}
685-
686-
RCT_EXPORT_METHOD(cancelAllLocalNotifications)
687-
{
688-
RCTLogError(@"Not implemented: %@", NSStringFromSelector(_cmd));
689-
}
690-
691-
RCT_EXPORT_METHOD(cancelLocalNotifications : (NSDictionary<NSString *, id> *)userInfo)
692-
{
693-
RCTLogError(@"Not implemented: %@", NSStringFromSelector(_cmd));
694-
}
695-
696-
RCT_EXPORT_METHOD(getInitialNotification
697-
: (RCTPromiseResolveBlock)resolve reject
698-
: (__unused RCTPromiseRejectBlock)reject)
699-
{
700-
RCTLogError(@"Not implemented: %@", NSStringFromSelector(_cmd));
701-
}
702-
703-
RCT_EXPORT_METHOD(getScheduledLocalNotifications : (RCTResponseSenderBlock)callback)
704-
{
705-
RCTLogError(@"Not implemented: %@", NSStringFromSelector(_cmd));
706-
}
707-
708-
RCT_EXPORT_METHOD(removeAllDeliveredNotifications)
709-
{
710-
RCTLogError(@"Not implemented: %@", NSStringFromSelector(_cmd));
711-
}
712-
713-
RCT_EXPORT_METHOD(removeDeliveredNotifications : (NSArray<NSString *> *)identifiers)
714-
{
715-
RCTLogError(@"Not implemented: %@", NSStringFromSelector(_cmd));
716-
}
717-
718-
RCT_EXPORT_METHOD(getDeliveredNotifications : (RCTResponseSenderBlock)callback)
719-
{
720-
RCTLogError(@"Not implemented: %@", NSStringFromSelector(_cmd));
721-
}
722-
723-
RCT_EXPORT_METHOD(getAuthorizationStatus : (RCTResponseSenderBlock)callback)
724-
{
725-
RCTLogError(@"Not implemented: %@", NSStringFromSelector(_cmd));
726-
}
727-
728-
- (NSArray<NSString *> *)supportedEvents
729-
{
730-
return @[];
731-
}
732-
733-
#endif // TARGET_OS_UIKITFORMAC
734-
735630
- (std::shared_ptr<facebook::react::TurboModule>)getTurboModule:
736631
(const facebook::react::ObjCTurboModule::InitParams &)params
737632
{

packages/react-native/Libraries/Text/Text/RCTTextView.m

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -380,29 +380,25 @@ - (void)disableContextMenu
380380

381381
- (void)handleLongPress:(UILongPressGestureRecognizer *)gesture
382382
{
383-
#if !TARGET_OS_UIKITFORMAC
384-
if (@available(iOS 16.0, *)) {
383+
if (@available(iOS 16.0, macCatalyst 16.0, *)) {
385384
CGPoint location = [gesture locationInView:self];
386385
UIEditMenuConfiguration *config = [UIEditMenuConfiguration configurationWithIdentifier:nil sourcePoint:location];
387386
if (_editMenuInteraction) {
388387
[_editMenuInteraction presentEditMenuWithConfiguration:config];
389388
}
390389
return;
391390
}
392-
// TODO: Adopt showMenuFromRect (necessary for UIKitForMac)
393391
UIMenuController *menuController = [UIMenuController sharedMenuController];
394392

395-
if (menuController.isMenuVisible) {
396-
return;
397-
}
393+
if (menuController.isMenuVisible) {
394+
return;
395+
}
398396

399-
if (!self.isFirstResponder) {
400-
[self becomeFirstResponder];
401-
}
397+
if (!self.isFirstResponder) {
398+
[self becomeFirstResponder];
399+
}
402400

403-
[menuController setTargetRect:self.bounds inView:self];
404-
[menuController setMenuVisible:YES animated:YES];
405-
#endif
401+
[menuController showMenuFromView:self rect:self.bounds];
406402
}
407403
#else // [macOS
408404

packages/react-native/React/Fabric/Mounting/ComponentViews/Text/RCTParagraphComponentView.mm

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,6 @@ - (void)disableContextMenu
251251

252252
- (void)handleLongPress:(UILongPressGestureRecognizer *)gesture
253253
{
254-
#if !TARGET_OS_UIKITFORMAC
255254
if (@available(iOS 16.0, *)) {
256255
CGPoint location = [gesture locationInView:self];
257256
UIEditMenuConfiguration *config = [UIEditMenuConfiguration configurationWithIdentifier:nil sourcePoint:location];
@@ -260,20 +259,17 @@ - (void)handleLongPress:(UILongPressGestureRecognizer *)gesture
260259
}
261260
return;
262261
}
263-
// TODO: Adopt showMenuFromRect (necessary for UIKitForMac)
264262
UIMenuController *menuController = [UIMenuController sharedMenuController];
265263

266264
if (menuController.isMenuVisible) {
267-
return;
265+
return;
268266
}
269267

270268
if (!self.isFirstResponder) {
271-
[self becomeFirstResponder];
269+
[self becomeFirstResponder];
272270
}
273271

274-
[menuController setTargetRect:self.bounds inView:self];
275-
[menuController setMenuVisible:YES animated:YES];
276-
#endif
272+
[menuController showMenuFromView:self rect:self.bounds];
277273
}
278274
#endif // [macOS]
279275

packages/rn-tester/RNTester/AppDelegate.mm

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,7 @@
4848

4949
#import <cxxreact/JSExecutor.h>
5050

51-
#if !TARGET_OS_TV && !TARGET_OS_UIKITFORMAC
5251
#import <React/RCTPushNotificationManager.h>
53-
#endif
5452

5553
#ifdef RN_FABRIC_ENABLED
5654
#import <React/RCTFabricSurfaceHostingProxyRootView.h>
@@ -336,8 +334,6 @@ - (void)registerPaperComponents:(NSArray<NSString *> *)components
336334

337335
#pragma mark - Push Notifications
338336

339-
#if !TARGET_OS_TV && !TARGET_OS_UIKITFORMAC
340-
341337
// Required for the remoteNotificationsRegistered event.
342338
- (void)application:(__unused RCTUIApplication *)application
343339
didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken
@@ -384,6 +380,5 @@ - (BOOL)userNotificationCenter:(NSUserNotificationCenter *)center
384380
return YES;
385381
}
386382
#endif // macOS]
387-
#endif
388383

389384
@end

0 commit comments

Comments
 (0)