Skip to content

Commit

Permalink
Fix remainig macOS compile errors
Browse files Browse the repository at this point in the history
  • Loading branch information
Saadnajmi committed Sep 24, 2023
1 parent 27d2c0c commit e23764c
Show file tree
Hide file tree
Showing 36 changed files with 197 additions and 97 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@
*
* @return: void
*/
- (void)setRootView:(UIView *)rootView toRootViewController:(UIViewController *)rootViewController;
- (void)setRootView:(RCTPlatformView *)rootView toRootViewController:(UIViewController *)rootViewController; // [macOS]

/// This method controls whether the App will use RuntimeScheduler. Only applicable in the legacy architecture.
///
Expand Down
8 changes: 5 additions & 3 deletions packages/react-native/Libraries/AppDelegate/RCTAppDelegate.mm
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,8 @@ - (void)applicationDidFinishLaunching:(NSNotification *)notification
self.window.rootViewController = rootViewController;
self.window.windowScene.delegate = self;
[self.window makeKeyAndVisible];

return YES;
#else // [macOS
NSRect frame = NSMakeRect(0,0,1024,768);
self.window = [[NSWindow alloc] initWithContentRect:NSZeroRect
Expand All @@ -143,8 +145,6 @@ - (void)applicationDidFinishLaunching:(NSNotification *)notification
[self.window makeKeyAndOrderFront:self];
[self.window center];
#endif // macOS]

return YES;
}

- (NSURL *)sourceURLForBridge:(RCTBridge *)bridge
Expand Down Expand Up @@ -203,7 +203,7 @@ - (NSViewController *)createRootViewController
}
#endif // macOS]

- (void)setRootView:(UIView *)rootView toRootViewController:(UIViewController *)rootViewController
- (void)setRootView:(RCTPlatformView *)rootView toRootViewController:(UIViewController *)rootViewController // [macOS]
{
rootViewController.view = rootView;
}
Expand All @@ -214,13 +214,15 @@ - (BOOL)runtimeSchedulerEnabled
}

#pragma mark - UISceneDelegate
#if !TARGET_OS_OSX // [macOS]
- (void)windowScene:(UIWindowScene *)windowScene
didUpdateCoordinateSpace:(id<UICoordinateSpace>)previousCoordinateSpace
interfaceOrientation:(UIInterfaceOrientation)previousInterfaceOrientation
traitCollection:(UITraitCollection *)previousTraitCollection API_AVAILABLE(ios(13.0))
{
[[NSNotificationCenter defaultCenter] postNotificationName:RCTRootViewFrameDidChangeNotification object:self];
}
#endif // [macOS]

#pragma mark - RCTCxxBridgeDelegate
- (std::unique_ptr<facebook::react::JSExecutorFactory>)jsExecutorFactoryForBridge:(RCTBridge *)bridge
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,11 @@ void RCTAppSetupPrepareApp(UIApplication *application, BOOL turboModuleEnabled)
#endif

#if DEBUG
#if !TARGET_OS_OSX // [macOS]
// Disable idle timer in dev builds to avoid putting application in background and complicating
// Metro reconnection logic. Users only need this when running the application using our CLI tooling.
application.idleTimerDisabled = YES;
#endif // macOS]
#endif
}

Expand Down
3 changes: 2 additions & 1 deletion packages/react-native/Libraries/Image/React-RCTImage.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@ Pod::Spec.new do |s|
"CLANG_CXX_LANGUAGE_STANDARD" => "c++20",
"HEADER_SEARCH_PATHS" => header_search_paths.join(' ')
}
s.framework = ["Accelerate", "UIKit"]
s.ios.framework = ["Accelerate", "UIKit"] # [macOS] Restrict UIKit to iOS
s.osx.framework = ["Accelerate"] # [macOS]

s.dependency "RCT-Folly", folly_version
s.dependency "React-Codegen", version
Expand Down
2 changes: 2 additions & 0 deletions packages/react-native/Libraries/Text/RCTConvert+Text.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,9 @@ typedef enum UITextSpellCheckingType : NSInteger {
+ (UITextAutocorrectionType)UITextAutocorrectionType:(nullable id)json;
+ (UITextSpellCheckingType)UITextSpellCheckingType:(nullable id)json;
+ (RCTTextTransform)RCTTextTransform:(nullable id)json;
#if !TARGET_OS_OSX // [macOS]
+ (UITextSmartInsertDeleteType)UITextSmartInsertDeleteType:(nullable id)json;
#endif // [macOS]

@end

Expand Down
2 changes: 2 additions & 0 deletions packages/react-native/Libraries/Text/RCTConvert+Text.mm
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,13 @@ + (UITextSpellCheckingType)UITextSpellCheckingType:(id)json
RCTTextTransformUndefined,
integerValue)

#if !TARGET_OS_OSX // [macOS]
+ (UITextSmartInsertDeleteType)UITextSmartInsertDeleteType:(id)json
{
return json == nil ? UITextSmartInsertDeleteTypeDefault
: [RCTConvert BOOL:json] ? UITextSmartInsertDeleteTypeYes
: UITextSmartInsertDeleteTypeNo;
}
#endif// macOS]

@end
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.framework = ["MobileCoreServices"]
s.ios.framework = ["MobileCoreServices"] # [macOS] Restrict to iOS
s.pod_target_xcconfig = { "CLANG_CXX_LANGUAGE_STANDARD" => "c++20" }

s.dependency "Yoga"
Expand Down
2 changes: 1 addition & 1 deletion packages/react-native/Libraries/Text/Text/RCTTextView.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ NS_ASSUME_NONNULL_BEGIN

- (void)setTextStorage:(NSTextStorage *)textStorage
contentFrame:(CGRect)contentFrame
descendantViews:(NSArray<RCTUIView *> *)descendantViews; // [macOS]
descendantViews:(NSArray<RCTPlatformView *> *)descendantViews; // [macOS]

/**
* (Experimental and unused for Paper) Pointer event handlers.
Expand Down
2 changes: 1 addition & 1 deletion packages/react-native/Libraries/Text/Text/RCTTextView.mm
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ - (void)didUpdateReactSubviews

- (void)setTextStorage:(NSTextStorage *)textStorage
contentFrame:(CGRect)contentFrame
descendantViews:(NSArray<RCTUIView *> *)descendantViews // [macOS]
descendantViews:(NSArray<RCTPlatformView *> *)descendantViews // [macOS]
{
// This lets the textView own its text storage on macOS
// We update and replace the text container `_textView.textStorage.attributedString` when text/layout changes
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ @implementation RCTBaseTextInputView {
BOOL _didMoveToWindow;
}

#if !TARGET_OS_OSX // [macOS]
- (void)reactUpdateResponderOffsetForScrollView:(RCTScrollView *)scrollView
{
if (![self isDescendantOfView:scrollView]) {
Expand All @@ -61,6 +62,7 @@ - (void)reactUpdateResponderOffsetForScrollView:(RCTScrollView *)scrollView
}
scrollView.firstResponderFocus = [self convertRect:focusRect toView:nil];
}
#endif // [macOS]

- (instancetype)initWithBridge:(RCTBridge *)bridge
{
Expand Down Expand Up @@ -170,6 +172,7 @@ - (BOOL)textOf:(NSAttributedString *)newText equals:(NSAttributedString *)oldTex
[self.backedTextInputView.textInputMode.primaryLanguage isEqualToString:@"ko-KR"] ||
self.backedTextInputView.markedTextRange || self.backedTextInputView.isSecureTextEntry ||
#else // [macOS
BOOL shouldFallbackToBareTextComparison =
// There are multiple Korean input sources (2-Set, 3-Set, etc). Check substring instead instead
[[[self.backedTextInputView inputContext] selectedKeyboardInputSource] containsString:@"com.apple.inputmethod.Korean"] ||
[self.backedTextInputView hasMarkedText] || [self.backedTextInputView isKindOfClass:[NSSecureTextField class]] ||
Expand Down Expand Up @@ -319,6 +322,7 @@ - (void)setSelectionStart:(NSInteger)start selectionEnd:(NSInteger)end

- (void)setTextContentType:(NSString *)type
{
#if !TARGET_OS_OSX // [macOS]
static dispatch_once_t onceToken;
static NSDictionary<NSString *, NSString *> *contentTypeMap;

Expand Down Expand Up @@ -381,6 +385,7 @@ - (void)setTextContentType:(NSString *)type
// Setting textContentType to an empty string will disable any
// default behaviour, like the autofill bar for password inputs
self.backedTextInputView.textContentType = contentTypeMap[type] ?: type;
#endif // [macOS]
}

#if !TARGET_OS_OSX // [macOS]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ - (void)setUseSecureTextField:(BOOL)useSecureTextField {
_useSecureTextField = useSecureTextField;
RCTUITextField *previousTextField = _backedTextInputView;
if (useSecureTextField) {
_backedTextInputView = [[RCTUISecureTextField alloc] initWithFrame:self.bounds];
_backedTextInputView = (RCTUITextField *)[[RCTUISecureTextField alloc] initWithFrame:self.bounds];
} else {
_backedTextInputView = [[RCTUITextField alloc] initWithFrame:self.bounds];
}
Expand Down
9 changes: 9 additions & 0 deletions packages/react-native/React/Base/RCTUIKit.h
Original file line number Diff line number Diff line change
Expand Up @@ -261,11 +261,20 @@ NS_INLINE NSString *NSStringFromCGRect(CGRect rect)
return NSStringFromRect(NSRectFromCGRect(rect));
}

#ifdef __cplusplus
extern "C" {
#endif

// UIGraphics.h
CGContextRef UIGraphicsGetCurrentContext(void);
void UIGraphicsBeginImageContextWithOptions(CGSize size, BOOL opaque, CGFloat scale);
NSImage *UIGraphicsGetImageFromCurrentImageContext(void);
void UIGraphicsEndImageContext(void);
CGImageRef UIImageGetCGImageRef(NSImage *image);

#ifdef __cplusplus
}
#endif // __cpusplus

//
// semantically equivalent types
Expand Down
8 changes: 6 additions & 2 deletions packages/react-native/React/Base/RCTUtils.m
Original file line number Diff line number Diff line change
Expand Up @@ -593,9 +593,9 @@ BOOL RCTRunningInAppExtension(void)
#endif // macOS]
}

#if !TARGET_OS_OSX // [macOS]
UIWindow *__nullable RCTKeyWindow(void)
RCTPlatformWindow *__nullable RCTKeyWindow(void) // [macOS]
{
#if !TARGET_OS_OSX // [macOS]
if (RCTRunningInAppExtension()) {
return nil;
}
Expand All @@ -607,8 +607,12 @@ BOOL RCTRunningInAppExtension(void)
}
}
return nil;
#else // [macOS
return [NSApp keyWindow];
#endif // macOS]
}

#if !TARGET_OS_OSX // [macOS]
UIViewController *__nullable RCTPresentedViewController(void)
{
if ([RCTUtilsUIOverride hasPresentedViewController]) {
Expand Down
6 changes: 3 additions & 3 deletions packages/react-native/React/CoreModules/RCTDevLoadingView.mm
Original file line number Diff line number Diff line change
Expand Up @@ -164,15 +164,15 @@ - (void)showMessage:(NSString *)message color:(RCTUIColor *)color backgroundColo

self->_window.backgroundColor = backgroundColor;
self->_window.hidden = NO;

UIWindowScene *scene = (UIWindowScene *)RCTSharedApplication().connectedScenes.anyObject;
self->_window.windowScene = scene;
#else // [macOS
self->_label.stringValue = message;
self->_label.textColor = color;
self->_label.backgroundColor = backgroundColor;
[self->_window orderFront:nil];
#endif // macOS]

UIWindowScene *scene = (UIWindowScene *)RCTSharedApplication().connectedScenes.anyObject;
self->_window.windowScene = scene;
});

[self hideBannerAfter:15.0];
Expand Down
4 changes: 4 additions & 0 deletions packages/react-native/React/CoreModules/RCTTiming.mm
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,11 @@ - (void)setup
_timers = [NSMutableDictionary new];
_inBackground = NO;
RCTExecuteOnMainQueue(^{
#if !TARGET_OS_OSX // [macOS]
if (!self->_inBackground && [RCTSharedApplication() applicationState] == UIApplicationStateBackground) {
#else // [macOS
if (!self->_inBackground && ![RCTSharedApplication() isHidden]) {
#endif
[self appDidMoveToBackground];
}
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ Pod::Spec.new do |s|
"CLANG_CXX_LANGUAGE_STANDARD" => "c++20",
"HEADER_SEARCH_PATHS" => header_search_paths.join(" ")
}
s.framework = "UIKit"
s.ios.framework = "UIKit" # [macOS] Restrict to iOS
s.dependency "React-Codegen", version
s.dependency "RCT-Folly", folly_version
s.dependency "RCTTypeSafety", version
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ NS_ASSUME_NONNULL_BEGIN

- (instancetype)initWithCoordinator:(RCTLegacyViewManagerInteropCoordinator *)coordinator reactTag:(NSInteger)tag;

@property (strong, nonatomic) RCTUIView *paperView; // [macOS]
@property (strong, nonatomic) RCTPlatformView *paperView; // [macOS]

@property (nonatomic, copy, nullable) void (^eventInterceptor)(std::string eventName, folly::dynamic event);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ - (void)dealloc
[_coordinator removeObserveForTag:_tag];
}

- (RCTUIView *)paperView // [macOS]
- (RCTPlatformView *)paperView // [macOS]
{
if (!_paperView) {
_paperView = [_coordinator createPaperViewWithTag:_tag];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ @implementation RCTFabricModalHostViewController {
RCTSurfaceTouchHandler *_touchHandler;
}

#if !TARGET_OS_OSX // [macOS]
- (instancetype)init
{
if (!(self = [super init])) {
Expand All @@ -27,7 +28,6 @@ - (instancetype)init
return self;
}

#if !TARGET_OS_OSX // [macOS]
- (void)viewDidLayoutSubviews
{
[super viewDidLayoutSubviews];
Expand Down
18 changes: 12 additions & 6 deletions packages/react-native/React/Fabric/RCTSurfacePointerHandler.mm
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ typedef NS_ENUM(NSInteger, RCTPointerEventType) {
RCTPointerEventTypeCancel,
};

#if !TARGET_OS_OSX // [macOS]
static BOOL AllTouchesAreCancelledOrEnded(NSSet<UITouch *> *touches)
{
for (UITouch *touch in touches) {
Expand All @@ -43,6 +44,7 @@ static BOOL AnyTouchesChanged(NSSet<UITouch *> *touches)
}
return NO;
}
#endif // [macOS]

struct ActivePointer {
/*
Expand All @@ -53,12 +55,12 @@ static BOOL AnyTouchesChanged(NSSet<UITouch *> *touches)
/*
* The component view on which the touch started.
*/
RCTUIView<RCTComponentViewProtocol> *initialComponentView = nil; // [macOS]
RCTPlatformView<RCTComponentViewProtocol> *initialComponentView = nil; // [macOS]

/*
* The current target component view of the pointer
*/
RCTUIView<RCTComponentViewProtocol> *componentView = nil; // [macOS]
RCTPlatformView<RCTComponentViewProtocol> *componentView = nil; // [macOS]

/*
* The location of the pointer relative to the root component view
Expand Down Expand Up @@ -155,13 +157,12 @@ bool operator()(const ActivePointer &lhs, const ActivePointer &rhs) const
// do not conflict
static NSInteger constexpr kTouchIdentifierPoolOffset = 2;

#if !TARGET_OS_OSX // [macOS]
static SharedTouchEventEmitter GetTouchEmitterFromView(RCTUIView *componentView, CGPoint point) // [macOS]
{
return [(id<RCTTouchableComponentViewProtocol>)componentView touchEventEmitterAtPoint:point];
}

static NSOrderedSet<RCTReactTaggedView *> *GetTouchableViewsInPathToRoot(RCTUIView *componentView) // [macOS]
static NSOrderedSet<RCTReactTaggedView *> *GetTouchableViewsInPathToRoot(RCTPlatformView *componentView) // [macOS]
{
NSMutableOrderedSet *results = [NSMutableOrderedSet orderedSet];
do {
Expand All @@ -173,7 +174,7 @@ static SharedTouchEventEmitter GetTouchEmitterFromView(RCTUIView *componentView,
return results;
}

static UIView *FindClosestFabricManagedTouchableView(RCTUIView *componentView) // [macOS]
static RCTPlatformView *FindClosestFabricManagedTouchableView(RCTPlatformView *componentView) // [macOS]
{
while (componentView) {
if ([componentView respondsToSelector:@selector(touchEventEmitterAtPoint:)]) {
Expand All @@ -183,7 +184,6 @@ static SharedTouchEventEmitter GetTouchEmitterFromView(RCTUIView *componentView,
}
return nil;
}
#endif // [macOS]

static NSInteger ButtonMaskDiffToButton(UIEventButtonMask prevButtonMask, UIEventButtonMask curButtonMask)
{
Expand Down Expand Up @@ -585,7 +585,13 @@ - (void)_registerTouches:(NSSet<RCTUITouch *> *)touches withEvent:(UIEvent *)eve
activePointer.shouldLeaveWhenReleased = YES;
}

#if !TARGET_OS_OSX // [macOS]
activePointer.initialComponentView = FindClosestFabricManagedTouchableView(touch.view);
#else // [macOS
CGPoint touchLocation = [_rootComponentView.superview convertPoint:touch.locationInWindow fromView:nil];
RCTPlatformView *componentView = (RCTPlatformView *) [_rootComponentView hitTest:touchLocation];
activePointer.initialComponentView = FindClosestFabricManagedTouchableView(componentView);
#endif // macOS]

UpdateActivePointerWithUITouch(activePointer, touch, event, _rootComponentView);

Expand Down
3 changes: 2 additions & 1 deletion packages/react-native/React/React-RCTFabric.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,8 @@ Pod::Spec.new do |s|
s.compiler_flags = folly_compiler_flags + ' ' + boost_compiler_flags
s.header_dir = "React"
s.module_name = "RCTFabric"
s.framework = ["JavaScriptCore", "MobileCoreServices"]
s.ios.framework = ["JavaScriptCore", "MobileCoreServices"] # [macOS] Restrict MobileCoreServices to iOS
s.osx.framework = ["JavaScriptCore"] # [macOS] Restrict MobileCoreServices to iOS
s.pod_target_xcconfig = {
"HEADER_SEARCH_PATHS" => header_search_paths,
"OTHER_CFLAGS" => "$(inherited) -DRN_FABRIC_ENABLED" + " " + folly_flags,
Expand Down
2 changes: 1 addition & 1 deletion packages/react-native/React/Views/RCTSegmentedControl.m
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ - (void)setSelectedIndex:(NSInteger)selectedIndex
self.selectedSegmentIndex = selectedIndex; // [macOS]
}

#if !TARGET_OS_OSX // [macOS]
- (void)setBackgroundColor:(RCTUIColor *)backgroundColor // [macOS]
{
[super setBackgroundColor:backgroundColor];
Expand All @@ -61,7 +62,6 @@ - (void)setTextColor:(RCTUIColor *)textColor // [macOS]
[self setTitleTextAttributes:@{NSForegroundColorAttributeName : textColor} forState:UIControlStateNormal];
}

#if !TARGET_OS_OSX // [macOS] no concept of tintColor on macOS
- (void)setTintColor:(UIColor *)tintColor // [macOS]
{
[super setTintColor:tintColor];
Expand Down
Loading

0 comments on commit e23764c

Please sign in to comment.