Skip to content

Commit 3724810

Browse files
Radosław Pietruszewskifacebook-github-bot
authored andcommitted
Initial UIKitForMac support (#25427)
Summary: This PR adds initial support for Project Catalyst a.k.a. UIKitForMac. This is not yet meant for production, but this is enough for RNTester to successfully compile and mostly work :) Some APIs are not supported on the Mac -- e.g. telephony, and deprecated APIs are removed on Mac ���-- those had to be ifdef'd out via platform checks. The biggest limitation right now is that I couldn't get Web Socket code to successfully compile, and so there are a lot of temporary platform checks for that , and the RCTWebSocket.xcodeproj is marked as not supporting UIKitForMac. Again -- temporary, until someone with more knowledge knows how to fix this. react-native-community/discussions-and-proposals#131 ## Changelog [iOS] [Added] - Fixed compilation for macOS (Project Catalyst) -- not meant for production use yet Pull Request resolved: #25427 Test Plan: - Open RNTester/RNTester.xcodeproj with Xcode 10.2, run it like a normal iOS app -- make sure it compiles and runs correctly (no regression) - Open the same project with Xcode 11 beta 2 (or higher) on macOS Catalina beta, select "My Mac" as device target, and run -- see that it actually compiles and runs. **Note** there are unfortunately some required steps: - change build configuration to Release (because packager doesn't work correctly yet) - change development team to yours if Xcode tells you to - go to RNTester project → Build phases → Link binary with libraries, and change `platforms` for `libRCTWebSocket.a` to `iOS` (without Mac compatibility). I can't commit that change because it breaks compatibility with earlier Xcode versions The two extra steps for successful compile will disappear once web socket compilation for Catalyst is fixed Reviewed By: mmmulani Differential Revision: D16088263 Pulled By: sammy-SC fbshipit-source-id: 9c0b932b048e50a8e0f336eaa0612851b1909cae
1 parent 5dade01 commit 3724810

22 files changed

+133
-94
lines changed

Libraries/Image/RCTUIImageViewAnimated.m

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,12 @@ - (BOOL)paused
173173

174174
- (void)displayDidRefresh:(CADisplayLink *)displayLink
175175
{
176+
#if TARGET_OS_UIKITFORMAC
177+
// TODO: `displayLink.frameInterval` is not available on UIKitForMac
178+
NSTimeInterval duration = displayLink.duration;
179+
#else
176180
NSTimeInterval duration = displayLink.duration * displayLink.frameInterval;
181+
#endif
177182
NSUInteger totalFrameCount = self.totalFrameCount;
178183
NSUInteger currentFrameIndex = self.currentFrameIndex;
179184
NSUInteger nextFrameIndex = (currentFrameIndex + 1) % totalFrameCount;

Libraries/LinkingIOS/RCTLinkingManager.m

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,12 +101,15 @@ - (void)handleOpenURLNotification:(NSNotification *)notification
101101
}
102102
}];
103103
} else {
104+
#if !TARGET_OS_UIKITFORMAC
105+
// Note: this branch will never be taken on UIKitForMac
104106
BOOL opened = [RCTSharedApplication() openURL:URL];
105107
if (opened) {
106108
resolve(@YES);
107109
} else {
108110
reject(RCTErrorUnspecified, [NSString stringWithFormat:@"Unable to open URL: %@", URL], nil);
109111
}
112+
#endif
110113
}
111114

112115
}
@@ -170,12 +173,15 @@ - (void)handleOpenURLNotification:(NSNotification *)notification
170173
}
171174
}];
172175
} else {
176+
#if !TARGET_OS_UIKITFORMAC
177+
// Note: This branch will never be taken on UIKitForMac
173178
BOOL opened = [RCTSharedApplication() openURL:url];
174179
if (opened) {
175180
resolve(nil);
176181
} else {
177182
reject(RCTErrorUnspecified, @"Unable to open app settings", nil);
178183
}
184+
#endif
179185
}
180186
}
181187

Libraries/Network/RCTNetInfo.m

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
#import "RCTNetInfo.h"
99

10-
#if !TARGET_OS_TV
10+
#if !TARGET_OS_TV && !TARGET_OS_UIKITFORMAC
1111
#import <CoreTelephony/CTTelephonyNetworkInfo.h>
1212
#endif
1313
#import <React/RCTAssert.h>
@@ -148,7 +148,7 @@ - (BOOL)setReachabilityStatus:(SCNetworkReachabilityFlags)flags
148148
status = RCTReachabilityStateNone;
149149
}
150150

151-
#if !TARGET_OS_TV
151+
#if !TARGET_OS_TV && !TARGET_OS_UIKITFORMAC
152152

153153
else if ((flags & kSCNetworkReachabilityFlagsIsWWAN) != 0) {
154154
connectionType = RCTConnectionTypeCellular;

Libraries/PushNotificationIOS/RCTPushNotificationManager.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ extern NSString *const RCTRemoteNotificationReceived;
1313

1414
typedef void (^RCTRemoteNotificationCallback)(UIBackgroundFetchResult result);
1515

16-
#if !TARGET_OS_TV
16+
#if !TARGET_OS_TV && !TARGET_OS_UIKITFORMAC
1717
+ (void)didRegisterUserNotificationSettings:(UIUserNotificationSettings *)notificationSettings;
1818
+ (void)didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken;
1919
+ (void)didReceiveRemoteNotification:(NSDictionary *)notification;

Libraries/PushNotificationIOS/RCTPushNotificationManager.m

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323

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

26-
#if !TARGET_OS_TV
26+
#if !TARGET_OS_TV && !TARGET_OS_UIKITFORMAC
2727
@implementation RCTConvert (NSCalendarUnit)
2828

2929
RCT_ENUM_CONVERTER(NSCalendarUnit,
@@ -74,14 +74,14 @@ + (UILocalNotification *)UILocalNotification:(id)json
7474
}), UIBackgroundFetchResultNoData, integerValue)
7575

7676
@end
77-
#endif //TARGET_OS_TV
77+
#endif //TARGET_OS_TV / TARGET_OS_UIKITFORMAC
7878

7979
@implementation RCTPushNotificationManager
8080
{
8181
RCTPromiseResolveBlock _requestPermissionsResolveBlock;
8282
}
8383

84-
#if !TARGET_OS_TV
84+
#if !TARGET_OS_TV && !TARGET_OS_UIKITFORMAC
8585

8686
static NSDictionary *RCTFormatLocalNotification(UILocalNotification *notification)
8787
{
@@ -125,7 +125,7 @@ @implementation RCTPushNotificationManager
125125
return formattedNotification;
126126
}
127127

128-
#endif //TARGET_OS_TV
128+
#endif //TARGET_OS_TV / TARGET_OS_UIKITFORMAC
129129

130130
RCT_EXPORT_MODULE()
131131

@@ -134,7 +134,7 @@ - (dispatch_queue_t)methodQueue
134134
return dispatch_get_main_queue();
135135
}
136136

137-
#if !TARGET_OS_TV
137+
#if !TARGET_OS_TV && !TARGET_OS_UIKITFORMAC
138138
- (void)startObserving
139139
{
140140
[[NSNotificationCenter defaultCenter] addObserver:self
@@ -464,13 +464,13 @@ - (void)handleRegisterUserNotificationSettings:(NSNotification *)notification
464464
}
465465
}
466466

467-
#else //TARGET_OS_TV
467+
#else //TARGET_OS_TV / TARGET_OS_UIKITFORMAC
468468

469469
- (NSArray<NSString *> *)supportedEvents
470470
{
471471
return @[];
472472
}
473473

474-
#endif //TARGET_OS_TV
474+
#endif //TARGET_OS_TV / TARGET_OS_UIKITFORMAC
475475

476476
@end

Libraries/Text/Text/RCTTextView.m

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -294,7 +294,8 @@ - (void)disableContextMenu
294294

295295
- (void)handleLongPress:(UILongPressGestureRecognizer *)gesture
296296
{
297-
#if !TARGET_OS_TV
297+
// TODO: Adopt showMenuFromRect (necessary for UIKitForMac)
298+
#if !TARGET_OS_TV && !TARGET_OS_UIKITFORMAC
298299
UIMenuController *menuController = [UIMenuController sharedMenuController];
299300

300301
if (menuController.isMenuVisible) {

Libraries/WebSocket/RCTSRWebSocket.m

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
// limitations under the License.
1515
//
1616

17+
#if !TARGET_OS_UIKITFORMAC
18+
1719
#import "RCTSRWebSocket.h"
1820

1921
#import <Availability.h>
@@ -1635,3 +1637,5 @@ - (NSRunLoop *)runLoop;
16351637
}
16361638

16371639
@end
1640+
1641+
#endif

Libraries/WebSocket/RCTWebSocket.xcodeproj/project.pbxproj

Lines changed: 3 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@
4343
3C86DF7A1ADF695F0047B81A /* RCTWebSocketModule.h */,
4444
3C86DF7B1ADF695F0047B81A /* RCTWebSocketModule.m */,
4545
3C86DF471ADF2C930047B81A /* Products */,
46-
13526A501F362F7F0008EF00 /* Frameworks */,
4746
);
4847
indentWidth = 2;
4948
sourceTree = "<group>";
@@ -67,12 +66,10 @@
6766
buildConfigurationList = 2D2A28901D9B049200D4039D /* Build configuration list for PBXNativeTarget "RCTWebSocket-tvOS" */;
6867
buildPhases = (
6968
2D2A28841D9B049200D4039D /* Sources */,
70-
2DC5E5151F3A6C39000EE84B /* Frameworks */,
7169
);
7270
buildRules = (
7371
);
7472
dependencies = (
75-
3DBE0D111F3B184D0099AA32 /* PBXTargetDependency */,
7673
);
7774
name = "RCTWebSocket-tvOS";
7875
productName = "RCTWebSocket-tvOS";
@@ -84,12 +81,10 @@
8481
buildConfigurationList = 3C86DF5A1ADF2C930047B81A /* Build configuration list for PBXNativeTarget "RCTWebSocket" */;
8582
buildPhases = (
8683
3C86DF421ADF2C930047B81A /* Sources */,
87-
13526A4F1F362F770008EF00 /* Frameworks */,
8884
);
8985
buildRules = (
9086
);
9187
dependencies = (
92-
3DBE0D0F1F3B18490099AA32 /* PBXTargetDependency */,
9388
);
9489
name = RCTWebSocket;
9590
productName = WebSocket;
@@ -119,6 +114,7 @@
119114
developmentRegion = English;
120115
hasScannedForEncodings = 0;
121116
knownRegions = (
117+
English,
122118
en,
123119
);
124120
mainGroup = 3C86DF3D1ADF2C930047B81A;
@@ -313,6 +309,7 @@
313309
GCC_TREAT_WARNINGS_AS_ERRORS = NO;
314310
OTHER_LDFLAGS = "-ObjC";
315311
PRODUCT_NAME = "$(TARGET_NAME)";
312+
SUPPORTS_UIKITFORMAC = NO;
316313
};
317314
name = Debug;
318315
};
@@ -324,56 +321,7 @@
324321
GCC_TREAT_WARNINGS_AS_ERRORS = NO;
325322
OTHER_LDFLAGS = "-ObjC";
326323
PRODUCT_NAME = "$(TARGET_NAME)";
327-
};
328-
name = Release;
329-
};
330-
3DBE0CFE1F3B181A0099AA32 /* Debug */ = {
331-
isa = XCBuildConfiguration;
332-
buildSettings = {
333-
EXECUTABLE_PREFIX = lib;
334-
GCC_TREAT_WARNINGS_AS_ERRORS = NO;
335-
OTHER_LDFLAGS = "-ObjC";
336-
PRODUCT_NAME = "$(TARGET_NAME)";
337-
};
338-
name = Debug;
339-
};
340-
3DBE0CFF1F3B181A0099AA32 /* Release */ = {
341-
isa = XCBuildConfiguration;
342-
buildSettings = {
343-
EXECUTABLE_PREFIX = lib;
344-
GCC_TREAT_WARNINGS_AS_ERRORS = NO;
345-
OTHER_LDFLAGS = "-ObjC";
346-
PRODUCT_NAME = "$(TARGET_NAME)";
347-
};
348-
name = Release;
349-
};
350-
3DBE0D0B1F3B181C0099AA32 /* Debug */ = {
351-
isa = XCBuildConfiguration;
352-
buildSettings = {
353-
CLANG_ANALYZER_NONNULL = YES;
354-
CLANG_WARN_DOCUMENTATION_COMMENTS = YES;
355-
CLANG_WARN_INFINITE_RECURSION = YES;
356-
CLANG_WARN_SUSPICIOUS_MOVES = YES;
357-
DEBUG_INFORMATION_FORMAT = dwarf;
358-
ENABLE_TESTABILITY = YES;
359-
OTHER_LDFLAGS = "-ObjC";
360-
PRODUCT_NAME = "$(TARGET_NAME)";
361-
SDKROOT = appletvos;
362-
TVOS_DEPLOYMENT_TARGET = 9.2;
363-
};
364-
name = Debug;
365-
};
366-
3DBE0D0C1F3B181C0099AA32 /* Release */ = {
367-
isa = XCBuildConfiguration;
368-
buildSettings = {
369-
CLANG_ANALYZER_NONNULL = YES;
370-
CLANG_WARN_DOCUMENTATION_COMMENTS = YES;
371-
CLANG_WARN_INFINITE_RECURSION = YES;
372-
CLANG_WARN_SUSPICIOUS_MOVES = YES;
373-
OTHER_LDFLAGS = "-ObjC";
374-
PRODUCT_NAME = "$(TARGET_NAME)";
375-
SDKROOT = appletvos;
376-
TVOS_DEPLOYMENT_TARGET = 9.2;
324+
SUPPORTS_UIKITFORMAC = NO;
377325
};
378326
name = Release;
379327
};

0 commit comments

Comments
 (0)