Skip to content

Commit

Permalink
Initial UIKitForMac support (#25427)
Browse files Browse the repository at this point in the history
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
  • Loading branch information
Radosław Pietruszewski authored and facebook-github-bot committed Jul 4, 2019
1 parent 5dade01 commit 3724810
Show file tree
Hide file tree
Showing 22 changed files with 133 additions and 94 deletions.
5 changes: 5 additions & 0 deletions Libraries/Image/RCTUIImageViewAnimated.m
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,12 @@ - (BOOL)paused

- (void)displayDidRefresh:(CADisplayLink *)displayLink
{
#if TARGET_OS_UIKITFORMAC
// TODO: `displayLink.frameInterval` is not available on UIKitForMac
NSTimeInterval duration = displayLink.duration;
#else
NSTimeInterval duration = displayLink.duration * displayLink.frameInterval;
#endif
NSUInteger totalFrameCount = self.totalFrameCount;
NSUInteger currentFrameIndex = self.currentFrameIndex;
NSUInteger nextFrameIndex = (currentFrameIndex + 1) % totalFrameCount;
Expand Down
6 changes: 6 additions & 0 deletions Libraries/LinkingIOS/RCTLinkingManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -101,12 +101,15 @@ - (void)handleOpenURLNotification:(NSNotification *)notification
}
}];
} else {
#if !TARGET_OS_UIKITFORMAC
// Note: this branch will never be taken on UIKitForMac
BOOL opened = [RCTSharedApplication() openURL:URL];
if (opened) {
resolve(@YES);
} else {
reject(RCTErrorUnspecified, [NSString stringWithFormat:@"Unable to open URL: %@", URL], nil);
}
#endif
}

}
Expand Down Expand Up @@ -170,12 +173,15 @@ - (void)handleOpenURLNotification:(NSNotification *)notification
}
}];
} else {
#if !TARGET_OS_UIKITFORMAC
// Note: This branch will never be taken on UIKitForMac
BOOL opened = [RCTSharedApplication() openURL:url];
if (opened) {
resolve(nil);
} else {
reject(RCTErrorUnspecified, @"Unable to open app settings", nil);
}
#endif
}
}

Expand Down
4 changes: 2 additions & 2 deletions Libraries/Network/RCTNetInfo.m
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

#import "RCTNetInfo.h"

#if !TARGET_OS_TV
#if !TARGET_OS_TV && !TARGET_OS_UIKITFORMAC
#import <CoreTelephony/CTTelephonyNetworkInfo.h>
#endif
#import <React/RCTAssert.h>
Expand Down Expand Up @@ -148,7 +148,7 @@ - (BOOL)setReachabilityStatus:(SCNetworkReachabilityFlags)flags
status = RCTReachabilityStateNone;
}

#if !TARGET_OS_TV
#if !TARGET_OS_TV && !TARGET_OS_UIKITFORMAC

else if ((flags & kSCNetworkReachabilityFlagsIsWWAN) != 0) {
connectionType = RCTConnectionTypeCellular;
Expand Down
2 changes: 1 addition & 1 deletion Libraries/PushNotificationIOS/RCTPushNotificationManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ extern NSString *const RCTRemoteNotificationReceived;

typedef void (^RCTRemoteNotificationCallback)(UIBackgroundFetchResult result);

#if !TARGET_OS_TV
#if !TARGET_OS_TV && !TARGET_OS_UIKITFORMAC
+ (void)didRegisterUserNotificationSettings:(UIUserNotificationSettings *)notificationSettings;
+ (void)didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken;
+ (void)didReceiveRemoteNotification:(NSDictionary *)notification;
Expand Down
14 changes: 7 additions & 7 deletions Libraries/PushNotificationIOS/RCTPushNotificationManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@

static NSString *const kErrorUnableToRequestPermissions = @"E_UNABLE_TO_REQUEST_PERMISSIONS";

#if !TARGET_OS_TV
#if !TARGET_OS_TV && !TARGET_OS_UIKITFORMAC
@implementation RCTConvert (NSCalendarUnit)

RCT_ENUM_CONVERTER(NSCalendarUnit,
Expand Down Expand Up @@ -74,14 +74,14 @@ + (UILocalNotification *)UILocalNotification:(id)json
}), UIBackgroundFetchResultNoData, integerValue)

@end
#endif //TARGET_OS_TV
#endif //TARGET_OS_TV / TARGET_OS_UIKITFORMAC

@implementation RCTPushNotificationManager
{
RCTPromiseResolveBlock _requestPermissionsResolveBlock;
}

#if !TARGET_OS_TV
#if !TARGET_OS_TV && !TARGET_OS_UIKITFORMAC

static NSDictionary *RCTFormatLocalNotification(UILocalNotification *notification)
{
Expand Down Expand Up @@ -125,7 +125,7 @@ @implementation RCTPushNotificationManager
return formattedNotification;
}

#endif //TARGET_OS_TV
#endif //TARGET_OS_TV / TARGET_OS_UIKITFORMAC

RCT_EXPORT_MODULE()

Expand All @@ -134,7 +134,7 @@ - (dispatch_queue_t)methodQueue
return dispatch_get_main_queue();
}

#if !TARGET_OS_TV
#if !TARGET_OS_TV && !TARGET_OS_UIKITFORMAC
- (void)startObserving
{
[[NSNotificationCenter defaultCenter] addObserver:self
Expand Down Expand Up @@ -464,13 +464,13 @@ - (void)handleRegisterUserNotificationSettings:(NSNotification *)notification
}
}

#else //TARGET_OS_TV
#else //TARGET_OS_TV / TARGET_OS_UIKITFORMAC

- (NSArray<NSString *> *)supportedEvents
{
return @[];
}

#endif //TARGET_OS_TV
#endif //TARGET_OS_TV / TARGET_OS_UIKITFORMAC

@end
3 changes: 2 additions & 1 deletion Libraries/Text/Text/RCTTextView.m
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,8 @@ - (void)disableContextMenu

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

if (menuController.isMenuVisible) {
Expand Down
4 changes: 4 additions & 0 deletions Libraries/WebSocket/RCTSRWebSocket.m
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
// limitations under the License.
//

#if !TARGET_OS_UIKITFORMAC

#import "RCTSRWebSocket.h"

#import <Availability.h>
Expand Down Expand Up @@ -1635,3 +1637,5 @@ - (NSRunLoop *)runLoop;
}

@end

#endif
58 changes: 3 additions & 55 deletions Libraries/WebSocket/RCTWebSocket.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@
3C86DF7A1ADF695F0047B81A /* RCTWebSocketModule.h */,
3C86DF7B1ADF695F0047B81A /* RCTWebSocketModule.m */,
3C86DF471ADF2C930047B81A /* Products */,
13526A501F362F7F0008EF00 /* Frameworks */,
);
indentWidth = 2;
sourceTree = "<group>";
Expand All @@ -67,12 +66,10 @@
buildConfigurationList = 2D2A28901D9B049200D4039D /* Build configuration list for PBXNativeTarget "RCTWebSocket-tvOS" */;
buildPhases = (
2D2A28841D9B049200D4039D /* Sources */,
2DC5E5151F3A6C39000EE84B /* Frameworks */,
);
buildRules = (
);
dependencies = (
3DBE0D111F3B184D0099AA32 /* PBXTargetDependency */,
);
name = "RCTWebSocket-tvOS";
productName = "RCTWebSocket-tvOS";
Expand All @@ -84,12 +81,10 @@
buildConfigurationList = 3C86DF5A1ADF2C930047B81A /* Build configuration list for PBXNativeTarget "RCTWebSocket" */;
buildPhases = (
3C86DF421ADF2C930047B81A /* Sources */,
13526A4F1F362F770008EF00 /* Frameworks */,
);
buildRules = (
);
dependencies = (
3DBE0D0F1F3B18490099AA32 /* PBXTargetDependency */,
);
name = RCTWebSocket;
productName = WebSocket;
Expand Down Expand Up @@ -119,6 +114,7 @@
developmentRegion = English;
hasScannedForEncodings = 0;
knownRegions = (
English,
en,
);
mainGroup = 3C86DF3D1ADF2C930047B81A;
Expand Down Expand Up @@ -313,6 +309,7 @@
GCC_TREAT_WARNINGS_AS_ERRORS = NO;
OTHER_LDFLAGS = "-ObjC";
PRODUCT_NAME = "$(TARGET_NAME)";
SUPPORTS_UIKITFORMAC = NO;
};
name = Debug;
};
Expand All @@ -324,56 +321,7 @@
GCC_TREAT_WARNINGS_AS_ERRORS = NO;
OTHER_LDFLAGS = "-ObjC";
PRODUCT_NAME = "$(TARGET_NAME)";
};
name = Release;
};
3DBE0CFE1F3B181A0099AA32 /* Debug */ = {
isa = XCBuildConfiguration;
buildSettings = {
EXECUTABLE_PREFIX = lib;
GCC_TREAT_WARNINGS_AS_ERRORS = NO;
OTHER_LDFLAGS = "-ObjC";
PRODUCT_NAME = "$(TARGET_NAME)";
};
name = Debug;
};
3DBE0CFF1F3B181A0099AA32 /* Release */ = {
isa = XCBuildConfiguration;
buildSettings = {
EXECUTABLE_PREFIX = lib;
GCC_TREAT_WARNINGS_AS_ERRORS = NO;
OTHER_LDFLAGS = "-ObjC";
PRODUCT_NAME = "$(TARGET_NAME)";
};
name = Release;
};
3DBE0D0B1F3B181C0099AA32 /* Debug */ = {
isa = XCBuildConfiguration;
buildSettings = {
CLANG_ANALYZER_NONNULL = YES;
CLANG_WARN_DOCUMENTATION_COMMENTS = YES;
CLANG_WARN_INFINITE_RECURSION = YES;
CLANG_WARN_SUSPICIOUS_MOVES = YES;
DEBUG_INFORMATION_FORMAT = dwarf;
ENABLE_TESTABILITY = YES;
OTHER_LDFLAGS = "-ObjC";
PRODUCT_NAME = "$(TARGET_NAME)";
SDKROOT = appletvos;
TVOS_DEPLOYMENT_TARGET = 9.2;
};
name = Debug;
};
3DBE0D0C1F3B181C0099AA32 /* Release */ = {
isa = XCBuildConfiguration;
buildSettings = {
CLANG_ANALYZER_NONNULL = YES;
CLANG_WARN_DOCUMENTATION_COMMENTS = YES;
CLANG_WARN_INFINITE_RECURSION = YES;
CLANG_WARN_SUSPICIOUS_MOVES = YES;
OTHER_LDFLAGS = "-ObjC";
PRODUCT_NAME = "$(TARGET_NAME)";
SDKROOT = appletvos;
TVOS_DEPLOYMENT_TARGET = 9.2;
SUPPORTS_UIKITFORMAC = NO;
};
name = Release;
};
Expand Down
Loading

0 comments on commit 3724810

Please sign in to comment.