From 9b28ff66f2eb44469b0f57edfeb4ce765735dfc2 Mon Sep 17 00:00:00 2001 From: Saad Najmi Date: Mon, 9 Mar 2026 11:28:04 -0700 Subject: [PATCH 1/6] refactor: extract RCTUIKit into its own pod --- packages/react-native/React-Core.podspec | 2 + packages/react-native/React-RCTUIKit.podspec | 43 + .../react-native/React/Base/RCTDisplayLink.m | 2 +- .../react-native/React/Base/RCTFrameUpdate.h | 2 +- .../react-native/React/Base/RCTFrameUpdate.m | 2 +- packages/react-native/React/Base/RCTUIKit.h | 769 --------------- .../react-native/React/Base/macOS/RCTUIKit.m | 908 ------------------ .../RCTPlatformDisplayLink.h | 0 .../RCTPlatformDisplayLink.m | 5 +- .../React/RCTUIKit/RCTUIAccessibilityTraits.h | 126 +++ .../React/RCTUIKit/RCTUIControls.h | 115 +++ .../React/RCTUIKit/RCTUIControls.m | 263 +++++ .../React/RCTUIKit/RCTUIGeometry.h | 87 ++ .../React/RCTUIKit/RCTUIGraphics.h | 58 ++ .../React/RCTUIKit/RCTUIGraphics.m | 56 ++ .../RCTUIKit/RCTUIGraphicsImageRenderer.h | 51 + .../RCTUIKit/RCTUIGraphicsImageRenderer.m | 68 ++ .../react-native/React/RCTUIKit/RCTUIImage.h | 100 ++ .../react-native/React/RCTUIKit/RCTUIImage.m | 98 ++ .../react-native/React/RCTUIKit/RCTUIKit.h | 19 + .../React/RCTUIKit/RCTUIKitCompat.h | 225 +++++ .../react-native/React/RCTUIKit/RCTUIView.h | 163 ++++ .../react-native/React/RCTUIKit/RCTUIView.m | 465 +++++++++ .../react-native/scripts/react_native_pods.rb | 1 + packages/rn-tester/Podfile.lock | 150 +-- 25 files changed, 2029 insertions(+), 1749 deletions(-) create mode 100644 packages/react-native/React-RCTUIKit.podspec delete mode 100644 packages/react-native/React/Base/RCTUIKit.h delete mode 100644 packages/react-native/React/Base/macOS/RCTUIKit.m rename packages/react-native/React/{Base => RCTUIKit}/RCTPlatformDisplayLink.h (100%) rename packages/react-native/React/{Base/macOS => RCTUIKit}/RCTPlatformDisplayLink.m (97%) create mode 100644 packages/react-native/React/RCTUIKit/RCTUIAccessibilityTraits.h create mode 100644 packages/react-native/React/RCTUIKit/RCTUIControls.h create mode 100644 packages/react-native/React/RCTUIKit/RCTUIControls.m create mode 100644 packages/react-native/React/RCTUIKit/RCTUIGeometry.h create mode 100644 packages/react-native/React/RCTUIKit/RCTUIGraphics.h create mode 100644 packages/react-native/React/RCTUIKit/RCTUIGraphics.m create mode 100644 packages/react-native/React/RCTUIKit/RCTUIGraphicsImageRenderer.h create mode 100644 packages/react-native/React/RCTUIKit/RCTUIGraphicsImageRenderer.m create mode 100644 packages/react-native/React/RCTUIKit/RCTUIImage.h create mode 100644 packages/react-native/React/RCTUIKit/RCTUIImage.m create mode 100644 packages/react-native/React/RCTUIKit/RCTUIKit.h create mode 100644 packages/react-native/React/RCTUIKit/RCTUIKitCompat.h create mode 100644 packages/react-native/React/RCTUIKit/RCTUIView.h create mode 100644 packages/react-native/React/RCTUIKit/RCTUIView.m diff --git a/packages/react-native/React-Core.podspec b/packages/react-native/React-Core.podspec index 795801379b91..35d03c3ec67b 100644 --- a/packages/react-native/React-Core.podspec +++ b/packages/react-native/React-Core.podspec @@ -75,6 +75,7 @@ Pod::Spec.new do |s| "React/Tests/**/*", "React/Inspector/**/*", "React/Runtime/**/*", + "React/RCTUIKit/**/*", ] # The default is use hermes, we don't have jsc installed @@ -114,6 +115,7 @@ Pod::Spec.new do |s| end end + s.dependency "React-RCTUIKit" s.dependency "React-cxxreact" s.dependency "React-perflogger" s.dependency "React-jsi" diff --git a/packages/react-native/React-RCTUIKit.podspec b/packages/react-native/React-RCTUIKit.podspec new file mode 100644 index 000000000000..88be7d10bc2f --- /dev/null +++ b/packages/react-native/React-RCTUIKit.podspec @@ -0,0 +1,43 @@ +# Copyright (c) Meta Platforms, Inc. and affiliates. +# +# This source code is licensed under the MIT license found in the +# LICENSE file in the root directory of this source tree. + +require "json" + +package = JSON.parse(File.read(File.join(__dir__, "package.json"))) +version = package['version'] + +source = { :git => 'https://github.com/facebook/react-native.git' } +if version == '1000.0.0' + # This is an unpublished version, use the latest commit hash of the react-native repo, which we're presumably in. + source[:commit] = `git rev-parse HEAD`.strip if system("git rev-parse --git-dir > /dev/null 2>&1") +else + source[:tag] = "v#{version}" +end + +Pod::Spec.new do |s| + s.name = "React-RCTUIKit" + s.version = version + s.summary = "UIKit/AppKit compatibility layer for React Native macOS." + s.homepage = "https://reactnative.dev/" + s.license = package["license"] + s.author = "Meta Platforms, Inc. and its affiliates" + s.platforms = min_supported_versions + s.source = source + s.source_files = podspec_sources( + ["React/RCTUIKit/*.{h,m}"], + "React/RCTUIKit/*.h") + s.public_header_files = "React/RCTUIKit/*.h" + s.header_dir = "React" + s.module_name = "React_RCTUIKit" + s.pod_target_xcconfig = { + "DEFINES_MODULE" => "YES", + "CLANG_CXX_LANGUAGE_STANDARD" => rct_cxx_language_standard(), + } + # [macOS Restrict UIKit to iOS and visionOS + s.ios.framework = "UIKit" + s.visionos.framework = "UIKit" + s.osx.framework = "AppKit" + # macOS] +end diff --git a/packages/react-native/React/Base/RCTDisplayLink.m b/packages/react-native/React/Base/RCTDisplayLink.m index b39fb7ef827e..8fd185f7764b 100644 --- a/packages/react-native/React/Base/RCTDisplayLink.m +++ b/packages/react-native/React/Base/RCTDisplayLink.m @@ -9,7 +9,7 @@ #import -#import "RCTPlatformDisplayLink.h" // [macOS] +#import // [macOS] #import "RCTAssert.h" #import "RCTBridgeModule.h" #import "RCTFrameUpdate.h" diff --git a/packages/react-native/React/Base/RCTFrameUpdate.h b/packages/react-native/React/Base/RCTFrameUpdate.h index f10251bda70d..9c6722b32d7b 100644 --- a/packages/react-native/React/Base/RCTFrameUpdate.h +++ b/packages/react-native/React/Base/RCTFrameUpdate.h @@ -6,7 +6,7 @@ */ #import -#import "RCTPlatformDisplayLink.h" // [macOS] +#import // [macOS] /** * Interface containing the information about the last screen refresh. diff --git a/packages/react-native/React/Base/RCTFrameUpdate.m b/packages/react-native/React/Base/RCTFrameUpdate.m index 232fbefed7ce..f8e06ca15753 100644 --- a/packages/react-native/React/Base/RCTFrameUpdate.m +++ b/packages/react-native/React/Base/RCTFrameUpdate.m @@ -5,7 +5,7 @@ * LICENSE file in the root directory of this source tree. */ -#import "RCTPlatformDisplayLink.h" // [macOS] +#import // [macOS] #import "RCTFrameUpdate.h" diff --git a/packages/react-native/React/Base/RCTUIKit.h b/packages/react-native/React/Base/RCTUIKit.h deleted file mode 100644 index f129e938bcea..000000000000 --- a/packages/react-native/React/Base/RCTUIKit.h +++ /dev/null @@ -1,769 +0,0 @@ -/* - * Copyright (c) Meta Platforms, Inc. and affiliates. - * - * This source code is licensed under the MIT license found in the - * LICENSE file in the root directory of this source tree. - */ - -// [macOS] - -#include - -#include - -#if !TARGET_OS_OSX - -#import - -NS_ASSUME_NONNULL_BEGIN - -// -// functionally equivalent types -// - -UIKIT_STATIC_INLINE CGFloat UIImageGetScale(UIImage *image) -{ - return image.scale; -} - -UIKIT_STATIC_INLINE CGImageRef UIImageGetCGImageRef(UIImage *image) -{ - return image.CGImage; -} - -UIKIT_STATIC_INLINE UIImage *UIImageWithContentsOfFile(NSString *filePath) -{ - return [UIImage imageWithContentsOfFile:filePath]; -} - -UIKIT_STATIC_INLINE UIImage *UIImageWithData(NSData *imageData) -{ - return [UIImage imageWithData:imageData]; -} - -UIKIT_STATIC_INLINE UIBezierPath *UIBezierPathWithRoundedRect(CGRect rect, CGFloat cornerRadius) -{ - return [UIBezierPath bezierPathWithRoundedRect:rect cornerRadius:cornerRadius]; -} - -UIKIT_STATIC_INLINE void UIBezierPathAppendPath(UIBezierPath *path, UIBezierPath *appendPath) -{ - [path appendPath:appendPath]; -} - -// -// substantially different types -// - -// UIView -#define RCTPlatformView UIView -#define RCTUIView UIView -#define RCTUIScrollView UIScrollView -#define RCTUIScrollViewDelegate UIScrollViewDelegate -#define RCTPlatformImage UIImage -#define RCTUIImage UIImage -#define RCTUIPanGestureRecognizer UIPanGestureRecognizer - -UIKIT_STATIC_INLINE RCTPlatformView *RCTUIViewHitTestWithEvent(RCTPlatformView *view, CGPoint point, __unused UIEvent *__nullable event) -{ - return [view hitTest:point withEvent:event]; -} - -UIKIT_STATIC_INLINE void RCTUIViewSetContentModeRedraw(UIView *view) -{ - view.contentMode = UIViewContentModeRedraw; -} - -UIKIT_STATIC_INLINE BOOL RCTUIViewIsDescendantOfView(RCTPlatformView *view, RCTPlatformView *parent) -{ - return [view isDescendantOfView:parent]; -} - -UIKIT_STATIC_INLINE NSValue *NSValueWithCGRect(CGRect rect) -{ - return [NSValue valueWithCGRect:rect]; -} - -UIKIT_STATIC_INLINE NSValue *NSValueWithCGSize(CGSize size) -{ - return [NSValue valueWithCGSize:size]; -} - -UIKIT_STATIC_INLINE CGRect CGRectValue(NSValue *value) -{ - return [value CGRectValue]; -} - -// -// semantically equivalent types -// - -#define RCTUIColor UIColor - -// [macOS RCTUIAccessibilityTraits - typedef to UIAccessibilityTraits on iOS -static const UIAccessibilityTraits RCTUIAccessibilityTraitSwitch = 0x20000000000001; - -typedef UIAccessibilityTraits RCTUIAccessibilityTraits; -#define RCTUIAccessibilityTraitNone UIAccessibilityTraitNone -#define RCTUIAccessibilityTraitButton UIAccessibilityTraitButton -#define RCTUIAccessibilityTraitLink UIAccessibilityTraitLink -#define RCTUIAccessibilityTraitImage UIAccessibilityTraitImage -#define RCTUIAccessibilityTraitSelected UIAccessibilityTraitSelected -#define RCTUIAccessibilityTraitPlaysSound UIAccessibilityTraitPlaysSound -#define RCTUIAccessibilityTraitKeyboardKey UIAccessibilityTraitKeyboardKey -#define RCTUIAccessibilityTraitStaticText UIAccessibilityTraitStaticText -#define RCTUIAccessibilityTraitSummaryElement UIAccessibilityTraitSummaryElement -#define RCTUIAccessibilityTraitNotEnabled UIAccessibilityTraitNotEnabled -#define RCTUIAccessibilityTraitUpdatesFrequently UIAccessibilityTraitUpdatesFrequently -#define RCTUIAccessibilityTraitSearchField UIAccessibilityTraitSearchField -#define RCTUIAccessibilityTraitStartsMediaSession UIAccessibilityTraitStartsMediaSession -#define RCTUIAccessibilityTraitAdjustable UIAccessibilityTraitAdjustable -#define RCTUIAccessibilityTraitAllowsDirectInteraction UIAccessibilityTraitAllowsDirectInteraction -#define RCTUIAccessibilityTraitCausesPageTurn UIAccessibilityTraitCausesPageTurn -#define RCTUIAccessibilityTraitHeader UIAccessibilityTraitHeader -#define RCTUIAccessibilityTraitTabBar UIAccessibilityTraitTabBar -// macOS] - -UIKIT_STATIC_INLINE UIFont *UIFontWithSize(UIFont *font, CGFloat pointSize) -{ - return [font fontWithSize:pointSize]; -} - -UIKIT_STATIC_INLINE CGFloat UIFontLineHeight(UIFont *font) -{ - return [font lineHeight]; -} - -NS_ASSUME_NONNULL_END - -#else // TARGET_OS_OSX [ - -#import - -NS_ASSUME_NONNULL_BEGIN - -#define RCTPlatformImage NSImage - -// -// semantically equivalent constants -// - -// UIApplication.h/NSApplication.h -#define UIApplicationDidBecomeActiveNotification NSApplicationDidBecomeActiveNotification -#define UIApplicationDidEnterBackgroundNotification NSApplicationDidHideNotification -#define UIApplicationDidFinishLaunchingNotification NSApplicationDidFinishLaunchingNotification -#define UIApplicationWillResignActiveNotification NSApplicationWillResignActiveNotification -#define UIApplicationWillEnterForegroundNotification NSApplicationWillUnhideNotification - -// UIFontDescriptor.h/NSFontDescriptor.h -#define UIFontDescriptorFamilyAttribute NSFontFamilyAttribute; -#define UIFontDescriptorNameAttribute NSFontNameAttribute; -#define UIFontDescriptorFaceAttribute NSFontFaceAttribute; -#define UIFontDescriptorSizeAttribute NSFontSizeAttribute - -#define UIFontDescriptorTraitsAttribute NSFontTraitsAttribute -#define UIFontDescriptorFeatureSettingsAttribute NSFontFeatureSettingsAttribute - -#define UIFontSymbolicTrait NSFontSymbolicTrait -#define UIFontWeightTrait NSFontWeightTrait -#define UIFontFeatureTypeIdentifierKey NSFontFeatureTypeIdentifierKey -#define UIFontFeatureSelectorIdentifierKey NSFontFeatureSelectorIdentifierKey - -#define UIFontWeightUltraLight NSFontWeightUltraLight -#define UIFontWeightThin NSFontWeightThin -#define UIFontWeightLight NSFontWeightLight -#define UIFontWeightRegular NSFontWeightRegular -#define UIFontWeightMedium NSFontWeightMedium -#define UIFontWeightSemibold NSFontWeightSemibold -#define UIFontWeightBold NSFontWeightBold -#define UIFontWeightHeavy NSFontWeightHeavy -#define UIFontWeightBlack NSFontWeightBlack - -#define UIFontDescriptorSystemDesign NSFontDescriptorSystemDesign -#define UIFontDescriptorSystemDesignDefault NSFontDescriptorSystemDesignDefault -#define UIFontDescriptorSystemDesignSerif NSFontDescriptorSystemDesignSerif -#define UIFontDescriptorSystemDesignRounded NSFontDescriptorSystemDesignRounded -#define UIFontDescriptorSystemDesignMonospaced NSFontDescriptorSystemDesignMonospaced - - -// RCTActivityIndicatorView.h -#define UIActivityIndicatorView NSProgressIndicator - - -// UIGeometry.h/NSGeometry.h -#define UIEdgeInsetsZero NSEdgeInsetsZero - -// UIView.h/NSLayoutConstraint.h -#define UIViewNoIntrinsicMetric -1 -// NSViewNoIntrinsicMetric is defined to -1 but is only available on macOS 10.11 and higher. On previous versions it was NSViewNoInstrinsicMetric (misspelled) and also defined to -1. - -// UIInterface.h/NSUserInterfaceLayout.h -#define UIUserInterfaceLayoutDirection NSUserInterfaceLayoutDirection - -// -// semantically equivalent enums -// - -// UIGestureRecognizer.h/NSGestureRecognizer.h -enum -{ - UIGestureRecognizerStatePossible = NSGestureRecognizerStatePossible, - UIGestureRecognizerStateBegan = NSGestureRecognizerStateBegan, - UIGestureRecognizerStateChanged = NSGestureRecognizerStateChanged, - UIGestureRecognizerStateEnded = NSGestureRecognizerStateEnded, - UIGestureRecognizerStateCancelled = NSGestureRecognizerStateCancelled, - UIGestureRecognizerStateFailed = NSGestureRecognizerStateFailed, - UIGestureRecognizerStateRecognized = NSGestureRecognizerStateRecognized, -}; - -// UIFontDescriptor.h/NSFontDescriptor.h -enum -{ - UIFontDescriptorTraitItalic = NSFontItalicTrait, - UIFontDescriptorTraitBold = NSFontBoldTrait, - UIFontDescriptorTraitCondensed = NSFontCondensedTrait, -}; - -// UIView.h/NSView.h -enum : NSUInteger -{ - UIViewAutoresizingNone = NSViewNotSizable, - UIViewAutoresizingFlexibleLeftMargin = NSViewMinXMargin, - UIViewAutoresizingFlexibleWidth = NSViewWidthSizable, - UIViewAutoresizingFlexibleRightMargin = NSViewMaxXMargin, - UIViewAutoresizingFlexibleTopMargin = NSViewMinYMargin, - UIViewAutoresizingFlexibleHeight = NSViewHeightSizable, - UIViewAutoresizingFlexibleBottomMargin = NSViewMaxYMargin, -}; - -// UIView/NSView.h -typedef NS_ENUM(NSInteger, UIViewContentMode) { - UIViewContentModeScaleAspectFill = NSViewLayerContentsPlacementScaleProportionallyToFill, - UIViewContentModeScaleAspectFit = NSViewLayerContentsPlacementScaleProportionallyToFit, - UIViewContentModeScaleToFill = NSViewLayerContentsPlacementScaleAxesIndependently, - UIViewContentModeCenter = NSViewLayerContentsPlacementCenter, - UIViewContentModeTopLeft = NSViewLayerContentsPlacementTopLeft, -}; - -// UIInterface.h/NSUserInterfaceLayout.h -enum : NSInteger -{ - UIUserInterfaceLayoutDirectionLeftToRight = NSUserInterfaceLayoutDirectionLeftToRight, - UIUserInterfaceLayoutDirectionRightToLeft = NSUserInterfaceLayoutDirectionRightToLeft, -}; - -// RCTActivityIndicatorView.h -typedef NS_ENUM(NSInteger, UIActivityIndicatorViewStyle) { - UIActivityIndicatorViewStyleLarge, - UIActivityIndicatorViewStyleMedium, -}; - - -// -// semantically equivalent functions -// - -// UIGeometry.h/NSGeometry.h -NS_INLINE CGRect UIEdgeInsetsInsetRect(CGRect rect, NSEdgeInsets insets) -{ - rect.origin.x += insets.left; - rect.origin.y += insets.top; - rect.size.width -= (insets.left + insets.right); - rect.size.height -= (insets.top + insets.bottom); - return rect; -} - -NS_INLINE BOOL UIEdgeInsetsEqualToEdgeInsets(NSEdgeInsets insets1, NSEdgeInsets insets2) -{ - return NSEdgeInsetsEqual(insets1, insets2); -} - -NS_INLINE NSString *NSStringFromCGSize(CGSize size) -{ - return NSStringFromSize(NSSizeFromCGSize(size)); -} - -NS_INLINE NSString *NSStringFromCGRect(CGRect rect) -{ - return NSStringFromRect(NSRectFromCGRect(rect)); -} - -#ifdef __cplusplus -extern "C" { -#endif - -// UIGraphics.h -CGContextRef UIGraphicsGetCurrentContext(void); - -#ifdef __cplusplus -} -#endif // __cpusplus - -// -// semantically equivalent types -// - -// UIAccessibility.h/NSAccessibility.h -@compatibility_alias UIAccessibilityCustomAction NSAccessibilityCustomAction; - -// [macOS RCTUIAccessibilityTraits - define as bitmask type for macOS -// On macOS these don't directly map to behavior, but allow code to compile -// The actual accessibility role mapping is done in RCTViewAccessibilityElement -typedef uint64_t RCTUIAccessibilityTraits; - -// Trait constants matching iOS UIAccessibilityConstants.h -static const RCTUIAccessibilityTraits RCTUIAccessibilityTraitNone = 0; -static const RCTUIAccessibilityTraits RCTUIAccessibilityTraitButton = (1ULL << 0); -static const RCTUIAccessibilityTraits RCTUIAccessibilityTraitLink = (1ULL << 1); -static const RCTUIAccessibilityTraits RCTUIAccessibilityTraitImage = (1ULL << 2); -static const RCTUIAccessibilityTraits RCTUIAccessibilityTraitSelected = (1ULL << 3); -static const RCTUIAccessibilityTraits RCTUIAccessibilityTraitPlaysSound = (1ULL << 4); -static const RCTUIAccessibilityTraits RCTUIAccessibilityTraitKeyboardKey = (1ULL << 5); -static const RCTUIAccessibilityTraits RCTUIAccessibilityTraitStaticText = (1ULL << 6); -static const RCTUIAccessibilityTraits RCTUIAccessibilityTraitSummaryElement = (1ULL << 7); -static const RCTUIAccessibilityTraits RCTUIAccessibilityTraitNotEnabled = (1ULL << 8); -static const RCTUIAccessibilityTraits RCTUIAccessibilityTraitUpdatesFrequently = (1ULL << 9); -static const RCTUIAccessibilityTraits RCTUIAccessibilityTraitSearchField = (1ULL << 10); -static const RCTUIAccessibilityTraits RCTUIAccessibilityTraitStartsMediaSession = (1ULL << 11); -static const RCTUIAccessibilityTraits RCTUIAccessibilityTraitAdjustable = (1ULL << 12); -static const RCTUIAccessibilityTraits RCTUIAccessibilityTraitAllowsDirectInteraction = (1ULL << 13); -static const RCTUIAccessibilityTraits RCTUIAccessibilityTraitCausesPageTurn = (1ULL << 14); -static const RCTUIAccessibilityTraits RCTUIAccessibilityTraitHeader = (1ULL << 15); -static const RCTUIAccessibilityTraits RCTUIAccessibilityTraitTabBar = (1ULL << 16); -static const RCTUIAccessibilityTraits RCTUIAccessibilityTraitSwitch = (1ULL << 17); - -// Convert RCTUIAccessibilityTraits to NSAccessibilityRole for macOS -NS_INLINE NSAccessibilityRole RCTAccessibilityRoleFromTraits(RCTUIAccessibilityTraits traits) -{ - if (traits & RCTUIAccessibilityTraitSwitch) { - return NSAccessibilityCheckBoxRole; - } - if (traits & RCTUIAccessibilityTraitButton) { - return NSAccessibilityButtonRole; - } - if (traits & RCTUIAccessibilityTraitLink) { - return NSAccessibilityLinkRole; - } - if (traits & RCTUIAccessibilityTraitImage) { - return NSAccessibilityImageRole; - } - if (traits & RCTUIAccessibilityTraitKeyboardKey) { - return NSAccessibilityButtonRole; - } - if (traits & RCTUIAccessibilityTraitHeader) { - return NSAccessibilityStaticTextRole; - } - if (traits & RCTUIAccessibilityTraitStaticText) { - return NSAccessibilityStaticTextRole; - } - if (traits & RCTUIAccessibilityTraitSummaryElement) { - return NSAccessibilityStaticTextRole; - } - if (traits & RCTUIAccessibilityTraitSearchField) { - return NSAccessibilityTextFieldRole; - } - if (traits & RCTUIAccessibilityTraitAdjustable) { - return NSAccessibilitySliderRole; - } - if (traits & RCTUIAccessibilityTraitUpdatesFrequently) { - return NSAccessibilityProgressIndicatorRole; - } - if (traits & RCTUIAccessibilityTraitTabBar) { - return NSAccessibilityTabGroupRole; - } - return NSAccessibilityUnknownRole; -} -// macOS] - -// UIColor.h/NSColor.h -#define RCTUIColor NSColor - -// UIFont.h/NSFont.h -// Both NSFont and UIFont are toll-free bridged to CTFontRef so we'll assume they're semantically equivalent -@compatibility_alias UIFont NSFont; - -// UIViewController.h/NSViewController.h -@compatibility_alias UIViewController NSViewController; - -NS_INLINE NSFont *UIFontWithSize(NSFont *font, CGFloat pointSize) -{ - return [NSFont fontWithDescriptor:font.fontDescriptor size:pointSize]; -} - -NS_INLINE CGFloat UIFontLineHeight(NSFont *font) -{ - return ceilf(font.ascender + ABS(font.descender) + font.leading); -} - -// UIFontDescriptor.h/NSFontDescriptor.h -// Both NSFontDescriptor and UIFontDescriptor are toll-free bridged to CTFontDescriptorRef so we'll assume they're semantically equivalent -@compatibility_alias UIFontDescriptor NSFontDescriptor; -typedef NSFontSymbolicTraits UIFontDescriptorSymbolicTraits; -typedef NSFontWeight UIFontWeight; - -// UIGeometry.h/NSGeometry.h -typedef NSEdgeInsets UIEdgeInsets; - -NS_INLINE NSEdgeInsets UIEdgeInsetsMake(CGFloat top, CGFloat left, CGFloat bottom, CGFloat right) -{ - return NSEdgeInsetsMake(top, left, bottom, right); -} - -// -// functionally equivalent types -// - -// These types have the same purpose but may differ semantically. Use with care! - -#define UIEvent NSEvent -#define UITouchType NSTouchType -#define UIEventButtonMask NSEventButtonMask -#define UIKeyModifierFlags NSEventModifierFlags - -// UIGestureRecognizer -#define UIGestureRecognizer NSGestureRecognizer -#define UIGestureRecognizerDelegate NSGestureRecognizerDelegate -#define RCTUIPanGestureRecognizer NSPanGestureRecognizer - -// UIApplication -#define UIApplication NSApplication - -/** - * An NSImage subclass that caches its CGImage representation. - * - * RCTUIImage solves an issue where NSImage's `CGImageForProposedRect:` returns a new - * autoreleased CGImage each time it's called. When assigned to `CALayer.contents`, these - * autoreleased CGImages get deallocated when the autorelease pool drains, causing rendering - * issues (e.g., blank borders and shadows). - * - * @warning Treat RCTUIImage instances as immutable after creation. Do not modify the image's - * representations or properties after accessing the CGImage property. - */ -@interface RCTUIImage : NSImage - -@property (nonatomic, readonly, nullable) CGImageRef CGImage; - -@property (nonatomic, readonly) CGFloat scale; - -@end - -typedef NS_ENUM(NSInteger, UIImageRenderingMode) { - UIImageRenderingModeAlwaysOriginal, - UIImageRenderingModeAlwaysTemplate, -}; - -#ifdef __cplusplus -extern "C" { -#endif - -CGFloat UIImageGetScale(NSImage *image); -CGImageRef UIImageGetCGImageRef(NSImage *image); - -#ifdef __cplusplus -} -#endif - -NS_INLINE NSImage *UIImageWithContentsOfFile(NSString *filePath) -{ - return [[NSImage alloc] initWithContentsOfFile:filePath]; -} - -NS_INLINE NSImage *UIImageWithData(NSData *imageData) -{ - return [[NSImage alloc] initWithData:imageData]; -} - -NSData *UIImagePNGRepresentation(NSImage *image); -NSData *UIImageJPEGRepresentation(NSImage *image, CGFloat compressionQuality); - -// UIBezierPath -@compatibility_alias UIBezierPath NSBezierPath; - -UIBezierPath *UIBezierPathWithRoundedRect(CGRect rect, CGFloat cornerRadius); - -void UIBezierPathAppendPath(UIBezierPath *path, UIBezierPath *appendPath); - -// -// substantially different types -// - -// UIView -#define RCTPlatformView NSView - -@interface RCTUIView : RCTPlatformView - -@property (nonatomic, readonly) BOOL canBecomeFirstResponder; -- (BOOL)becomeFirstResponder; -@property(nonatomic, readonly) BOOL isFirstResponder; - -@property (nonatomic, getter=isUserInteractionEnabled) BOOL userInteractionEnabled; - -- (NSView *)hitTest:(CGPoint)point withEvent:(UIEvent *_Nullable)event; -- (BOOL)pointInside:(CGPoint)point withEvent:(UIEvent *)event; - -- (void)insertSubview:(NSView *)view atIndex:(NSInteger)index; - -- (void)didMoveToWindow; - -- (void)setNeedsLayout; -- (void)layoutIfNeeded; - -- (void)layoutSubviews; - -- (void)setNeedsDisplay; - -@property (nonatomic, copy) NSColor *backgroundColor; -@property (nonatomic) CGAffineTransform transform; - -/** - * Specifies whether the view should receive the mouse down event when the - * containing window is in the background. - */ -@property (nonatomic, assign) BOOL acceptsFirstMouse; - -@property (nonatomic, assign) BOOL mouseDownCanMoveWindow; - -/** - * Specifies whether the view participates in the key view loop as user tabs through different controls - * This is equivalent to acceptsFirstResponder on mac OS. - */ -@property (nonatomic, assign) BOOL focusable; -/** - * Specifies whether focus ring should be drawn when the view has the first responder status. - */ -@property (nonatomic, assign) BOOL enableFocusRing; - -// [macOS -/** - * iOS compatibility shim. On macOS, this forwards to accessibilityChildren. - */ -@property (nonatomic, copy) NSArray *accessibilityElements; -// macOS] - -@end - -// UIScrollView - -@class RCTUIScrollView; - -/** - * Protocol for objects that want to listen to scroll events on macOS. - * This mirrors the relevant parts of UIScrollViewDelegate for cross-platform compatibility. - */ -@protocol RCTUIScrollViewDelegate -@optional -- (void)scrollViewDidScroll:(RCTUIScrollView *)scrollView; -@end - -@interface RCTUIScrollView : NSScrollView - -// UIScrollView properties missing in NSScrollView -@property (nonatomic, assign) CGPoint contentOffset; -@property (nonatomic, assign) UIEdgeInsets contentInset; -@property (nonatomic, assign) CGSize contentSize; -@property (nonatomic, assign) BOOL showsHorizontalScrollIndicator; -@property (nonatomic, assign) BOOL showsVerticalScrollIndicator; -@property (nonatomic, assign) UIEdgeInsets scrollIndicatorInsets; -@property(nonatomic, assign) CGFloat minimumZoomScale; -@property(nonatomic, assign) CGFloat maximumZoomScale; -@property (nonatomic, assign) CGFloat zoomScale; -@property (nonatomic, assign) BOOL alwaysBounceHorizontal; -@property (nonatomic, assign) BOOL alwaysBounceVertical; -// macOS specific properties -@property (nonatomic, assign) BOOL enableFocusRing; -@property (nonatomic, assign, getter=isScrollEnabled) BOOL scrollEnabled; -@property (nonatomic, weak, nullable) id delegate; - -- (void)setContentOffset:(CGPoint)contentOffset animated:(BOOL)animated; - -@end - -@interface RCTClipView : NSClipView - -@property (nonatomic, assign) BOOL constrainScrolling; - -@end - - -NS_INLINE RCTPlatformView *RCTUIViewHitTestWithEvent(RCTPlatformView *view, CGPoint point, __unused UIEvent *__nullable event) -{ - // [macOS IMPORTANT -- point is in local coordinate space, but OSX expects super coordinate space for hitTest: - NSView *superview = [view superview]; - NSPoint pointInSuperview = superview != nil ? [view convertPoint:point toView:superview] : point; - return [view hitTest:pointInSuperview]; -} - -NS_INLINE void RCTUIViewSetContentModeRedraw(RCTPlatformView *view) -{ - view.layerContentsRedrawPolicy = NSViewLayerContentsRedrawDuringViewResize; -} - -NS_INLINE BOOL RCTUIViewIsDescendantOfView(RCTPlatformView *view, RCTPlatformView *parent) -{ - return [view isDescendantOf:parent]; -} - -NS_INLINE NSValue *NSValueWithCGRect(CGRect rect) -{ - return [NSValue valueWithBytes:&rect objCType:@encode(CGRect)]; -} - -NS_INLINE NSValue *NSValueWithCGSize(CGSize size) -{ - return [NSValue valueWithBytes:&size objCType:@encode(CGSize)]; -} - -NS_INLINE CGRect CGRectValue(NSValue *value) -{ - CGRect rect = CGRectZero; - [value getValue:&rect]; - return rect; -} - -NS_ASSUME_NONNULL_END - -#endif // ] TARGET_OS_OSX - -#if !TARGET_OS_OSX -typedef UIApplication RCTUIApplication; -typedef UIWindow RCTPlatformWindow; -typedef UIViewController RCTPlatformViewController; -#else -typedef NSApplication RCTUIApplication; -typedef NSWindow RCTPlatformWindow; -typedef NSViewController RCTPlatformViewController; -#endif - -// -// fabric component types -// - -// RCTUISlider - -#if !TARGET_OS_OSX -typedef UISlider RCTUISlider; -#else -@protocol RCTUISliderDelegate; - -@interface RCTUISlider : NSSlider -NS_ASSUME_NONNULL_BEGIN -@property (nonatomic, weak) id delegate; -@property (nonatomic, readonly) BOOL pressed; -@property (nonatomic, assign) float value; -@property (nonatomic, assign) float minimumValue; -@property (nonatomic, assign) float maximumValue; -@property (nonatomic, strong) NSColor *minimumTrackTintColor; -@property (nonatomic, strong) NSColor *maximumTrackTintColor; - -- (void)setValue:(float)value animated:(BOOL)animated; -NS_ASSUME_NONNULL_END -@end -#endif - -#if TARGET_OS_OSX // [macOS -@protocol RCTUISliderDelegate -@optional -NS_ASSUME_NONNULL_BEGIN -- (void)slider:(RCTUISlider *)slider didPress:(BOOL)press; -NS_ASSUME_NONNULL_END -@end -#endif // macOS] - -// RCTUILabel - -#if !TARGET_OS_OSX -typedef UILabel RCTUILabel; -#else -@interface RCTUILabel : NSTextField -NS_ASSUME_NONNULL_BEGIN -@property(nonatomic, copy) NSString* _Nullable text; -@property(nonatomic, assign) NSInteger numberOfLines; -@property(nonatomic, assign) NSTextAlignment textAlignment; -NS_ASSUME_NONNULL_END -@end -#endif - -// RCTUISwitch - -#if !TARGET_OS_OSX -typedef UISwitch RCTUISwitch; -#else -@interface RCTUISwitch : NSSwitch -NS_ASSUME_NONNULL_BEGIN -@property (nonatomic, getter=isOn) BOOL on; - -- (void)setOn:(BOOL)on animated:(BOOL)animated; - -NS_ASSUME_NONNULL_END -@end -#endif - -// RCTUIActivityIndicatorView - -#if !TARGET_OS_OSX -typedef UIActivityIndicatorView RCTUIActivityIndicatorView; -#else -@interface RCTUIActivityIndicatorView : NSProgressIndicator -NS_ASSUME_NONNULL_BEGIN -@property (nonatomic, assign) UIActivityIndicatorViewStyle activityIndicatorViewStyle; -@property (nonatomic, assign) BOOL hidesWhenStopped; -@property (nullable, readwrite, nonatomic, strong) RCTUIColor *color; -@property (nonatomic, readonly, getter=isAnimating) BOOL animating; - -- (void)startAnimating; -- (void)stopAnimating; -NS_ASSUME_NONNULL_END -@end - -#endif - -// RCTUITouch - -#if !TARGET_OS_OSX -typedef UITouch RCTUITouch; -#else -@interface RCTUITouch : NSEvent -@end -#endif - -// RCTUIImageView - -#if !TARGET_OS_OSX -typedef UIImageView RCTUIImageView; -#else -@interface RCTUIImageView : NSImageView -NS_ASSUME_NONNULL_BEGIN -@property (nonatomic, strong) RCTUIColor *tintColor; -@property (nonatomic, assign) UIViewContentMode contentMode; -NS_ASSUME_NONNULL_END -@end -#endif - -#if !TARGET_OS_OSX -typedef UIGraphicsImageRendererContext RCTUIGraphicsImageRendererContext; -typedef UIGraphicsImageDrawingActions RCTUIGraphicsImageDrawingActions; -typedef UIGraphicsImageRendererFormat RCTUIGraphicsImageRendererFormat; -typedef UIGraphicsImageRenderer RCTUIGraphicsImageRenderer; -#else -NS_ASSUME_NONNULL_BEGIN -typedef NSGraphicsContext RCTUIGraphicsImageRendererContext; -typedef void (^RCTUIGraphicsImageDrawingActions)(RCTUIGraphicsImageRendererContext *rendererContext); - -@interface RCTUIGraphicsImageRendererFormat : NSObject - -+ (instancetype)defaultFormat; - -@property (nonatomic) CGFloat scale; -@property (nonatomic) BOOL opaque; - -@end - -@interface RCTUIGraphicsImageRenderer : NSObject - -- (instancetype)initWithSize:(CGSize)size; -- (instancetype)initWithSize:(CGSize)size format:(RCTUIGraphicsImageRendererFormat *)format; -- (RCTUIImage *)imageWithActions:(NS_NOESCAPE RCTUIGraphicsImageDrawingActions)actions; - -@end -NS_ASSUME_NONNULL_END -#endif diff --git a/packages/react-native/React/Base/macOS/RCTUIKit.m b/packages/react-native/React/Base/macOS/RCTUIKit.m deleted file mode 100644 index 3838b7563a17..000000000000 --- a/packages/react-native/React/Base/macOS/RCTUIKit.m +++ /dev/null @@ -1,908 +0,0 @@ -/** - * Copyright (c) 2015-present, Facebook, Inc. - * - * This source code is licensed under the MIT license found in the - * LICENSE file in the root directory of this source tree. - */ - -// [macOS] - -#if TARGET_OS_OSX - -#import - -#import - -#import - -#import -#import - -static char RCTGraphicsContextSizeKey; - -// -// semantically equivalent functions -// - -// UIGraphics.h - -CGContextRef UIGraphicsGetCurrentContext(void) -{ - return [[NSGraphicsContext currentContext] CGContext]; -} - -NSImage *UIGraphicsGetImageFromCurrentImageContext(void) -{ - NSImage *image = nil; - NSGraphicsContext *graphicsContext = [NSGraphicsContext currentContext]; - - NSValue *sizeValue = objc_getAssociatedObject(graphicsContext, &RCTGraphicsContextSizeKey); - if (sizeValue != nil) { - CGImageRef cgImage = CGBitmapContextCreateImage([graphicsContext CGContext]); - - if (cgImage != NULL) { - NSBitmapImageRep *imageRep = [[NSBitmapImageRep alloc] initWithCGImage:cgImage]; - image = [[NSImage alloc] initWithSize:[sizeValue sizeValue]]; - [image addRepresentation:imageRep]; - CFRelease(cgImage); - } - } - - return image; -} - -// -// functionally equivalent types -// - -// UIImage - -CGFloat UIImageGetScale(NSImage *image) -{ - if (image == nil) { - return 0.0; - } - - RCTAssert(image.representations.count == 1, @"The scale can only be derived if the image has one representation."); - - NSImageRep *imageRep = image.representations.firstObject; - if (imageRep != nil) { - NSSize imageSize = image.size; - NSSize repSize = CGSizeMake(imageRep.pixelsWide, imageRep.pixelsHigh); - - return round(fmax(repSize.width / imageSize.width, repSize.height / imageSize.height)); - } - - return 1.0; -} - -// RCTUIImage - NSImage subclass with cached CGImage - -@implementation RCTUIImage { - CGImageRef _cachedCGImage; -} - -- (void)dealloc { - if (_cachedCGImage != NULL) { - CGImageRelease(_cachedCGImage); - } -} - -- (CGImageRef)CGImage { - if (_cachedCGImage == NULL) { - CGImageRef cgImage = [self CGImageForProposedRect:NULL context:NULL hints:NULL]; - if (cgImage != NULL) { - _cachedCGImage = CGImageRetain(cgImage); - } - } - return _cachedCGImage; -} - -- (CGFloat)scale { - return UIImageGetScale(self); -} - -@end - -CGImageRef __nullable UIImageGetCGImageRef(NSImage *image) -{ - // If it's an RCTUIImage, use the cached CGImage property - if ([image isKindOfClass:[RCTUIImage class]]) { - return ((RCTUIImage *)image).CGImage; - } - - // Otherwise, fall back to the standard NSImage method - // Note: This returns an autoreleased CGImageRef - return [image CGImageForProposedRect:NULL context:NULL hints:NULL]; -} - -static NSData *NSImageDataForFileType(NSImage *image, NSBitmapImageFileType fileType, NSDictionary *properties) -{ - RCTAssert(image.representations.count == 1, @"Expected only a single representation since UIImage only supports one."); - - NSBitmapImageRep *imageRep = (NSBitmapImageRep *)image.representations.firstObject; - if (![imageRep isKindOfClass:[NSBitmapImageRep class]]) { - RCTAssert([imageRep isKindOfClass:[NSBitmapImageRep class]], @"We need an NSBitmapImageRep to create an image."); - return nil; - } - - return [imageRep representationUsingType:fileType properties:properties]; -} - -NSData *UIImagePNGRepresentation(NSImage *image) { - return NSImageDataForFileType(image, NSBitmapImageFileTypePNG, @{}); -} - -NSData *UIImageJPEGRepresentation(NSImage *image, CGFloat compressionQuality) { - return NSImageDataForFileType(image, - NSBitmapImageFileTypeJPEG, - @{NSImageCompressionFactor: @(compressionQuality)}); -} - -// UIBezierPath -UIBezierPath *UIBezierPathWithRoundedRect(CGRect rect, CGFloat cornerRadius) -{ - return [NSBezierPath bezierPathWithRoundedRect:rect xRadius:cornerRadius yRadius:cornerRadius]; -} - -void UIBezierPathAppendPath(UIBezierPath *path, UIBezierPath *appendPath) -{ - return [path appendBezierPath:appendPath]; -} - -// -// substantially different types -// - -// UIView - - -@implementation RCTUIView -{ -@private - NSColor *_backgroundColor; - BOOL _clipsToBounds; - BOOL _userInteractionEnabled; - BOOL _mouseDownCanMoveWindow; - BOOL _respondsToDisplayLayer; -} - -+ (NSSet *)keyPathsForValuesAffectingValueForKey:(NSString *)key -{ - NSSet *keyPaths = [super keyPathsForValuesAffectingValueForKey:key]; - NSString *alternatePath = nil; - - // alpha is a wrapper for alphaValue - if ([key isEqualToString:@"alpha"]) { - alternatePath = @"alphaValue"; - // isAccessibilityElement is a wrapper for accessibilityElement - } else if ([key isEqualToString:@"isAccessibilityElement"]) { - alternatePath = @"accessibilityElement"; - } - - if (alternatePath != nil) { - keyPaths = keyPaths != nil ? [keyPaths setByAddingObject:alternatePath] : [NSSet setWithObject:alternatePath]; - } - - return keyPaths; -} - -static RCTUIView *RCTUIViewCommonInit(RCTUIView *self) -{ - if (self != nil) { - self.wantsLayer = YES; - self->_userInteractionEnabled = YES; - self->_enableFocusRing = YES; - self->_mouseDownCanMoveWindow = YES; - self->_respondsToDisplayLayer = [self respondsToSelector:@selector(displayLayer:)]; - } - return self; -} - -- (instancetype)initWithFrame:(NSRect)frameRect -{ - return RCTUIViewCommonInit([super initWithFrame:frameRect]); -} - -- (instancetype)initWithCoder:(NSCoder *)coder -{ - return RCTUIViewCommonInit([super initWithCoder:coder]); -} - -- (BOOL)acceptsFirstMouse:(NSEvent *)event -{ - if (self.acceptsFirstMouse || [super acceptsFirstMouse:event]) { - return YES; - } - - // If any RCTUIView view above has acceptsFirstMouse set, then return YES here. - NSView *view = self; - while ((view = view.superview)) { - if ([view isKindOfClass:[RCTUIView class]] && [(RCTUIView *)view acceptsFirstMouse]) { - return YES; - } - } - - return NO; -} - -- (BOOL)acceptsFirstResponder -{ - return [self canBecomeFirstResponder]; -} - -- (BOOL)isFirstResponder { - return [[self window] firstResponder] == self; -} - -- (void)viewDidMoveToWindow -{ - [self didMoveToWindow]; -} - -- (BOOL)mouseDownCanMoveWindow{ - return _mouseDownCanMoveWindow; -} - -- (void)setMouseDownCanMoveWindow:(BOOL)mouseDownCanMoveWindow{ - _mouseDownCanMoveWindow = mouseDownCanMoveWindow; -} - -- (BOOL)isFlipped -{ - return YES; -} - -- (CGFloat)alpha -{ - return self.alphaValue; -} - -- (void)setAlpha:(CGFloat)alpha -{ - self.alphaValue = alpha; -} - - -- (CGAffineTransform)transform -{ - return self.layer.affineTransform; -} - -- (void)setTransform:(CGAffineTransform)transform -{ - self.layer.affineTransform = transform; -} - -- (NSView *)hitTest:(NSPoint)point -{ - // IMPORTANT point is passed in super coordinates by OSX, but expected to be passed in local coordinates - NSView *superview = [self superview]; - NSPoint pointInSelf = superview != nil ? [self convertPoint:point fromView:superview] : point; - return [self hitTest:pointInSelf withEvent:nil]; -} - -- (BOOL)wantsUpdateLayer -{ - return [self respondsToSelector:@selector(displayLayer:)]; -} - -- (void)updateLayer -{ - CALayer *layer = [self layer]; - if (_backgroundColor) { - // updateLayer will be called when the view's current appearance changes. - // The layer's backgroundColor is a CGColor which is not appearance aware - // so it has to be reset from the view's NSColor ivar. - [layer setBackgroundColor:[_backgroundColor CGColor]]; - } - - // In Fabric, wantsUpdateLayer is always enabled and doesn't guarantee that - // the instance has a displayLayer method. - if (_respondsToDisplayLayer) { - [(id)self displayLayer:layer]; - } -} - -- (void)drawRect:(CGRect)rect -{ - if (_backgroundColor) { - [_backgroundColor set]; - NSRectFill(rect); - } - [super drawRect:rect]; -} - -- (void)layout -{ - [super layout]; - if (self.window != nil) { - [self layoutSubviews]; - } -} - -- (BOOL)canBecomeFirstResponder -{ - return [super acceptsFirstResponder]; -} - -- (BOOL)becomeFirstResponder -{ - return [[self window] makeFirstResponder:self]; -} - -@synthesize userInteractionEnabled = _userInteractionEnabled; - -- (NSArray *)accessibilityElements -{ - return self.accessibilityChildren; -} - -- (void)setAccessibilityElements:(NSArray *)accessibilityElements -{ - self.accessibilityChildren = accessibilityElements; -} - -- (NSView *)hitTest:(CGPoint)point withEvent:(__unused UIEvent *)event -{ -// [macOS - // IMPORTANT point is expected to be passed in local coordinates, but OSX expects point to be super - NSView *superview = [self superview]; - NSPoint pointInSuperview = superview != nil ? [self convertPoint:point toView:superview] : point; - return self.userInteractionEnabled ? [super hitTest:pointInSuperview] : nil; -} - -- (BOOL)pointInside:(CGPoint)point withEvent:(__unused UIEvent *)event -{ - return self.userInteractionEnabled ? NSPointInRect(NSPointFromCGPoint(point), self.bounds) : NO; -} - -- (void)insertSubview:(NSView *)view atIndex:(NSInteger)index -{ - NSArray<__kindof NSView *> *subviews = self.subviews; - if ((NSUInteger)index == subviews.count) { - [self addSubview:view]; - } else { - [self addSubview:view positioned:NSWindowBelow relativeTo:subviews[index]]; - } -} - -- (void)didMoveToWindow -{ - [super viewDidMoveToWindow]; -} - -- (void)setNeedsLayout -{ - self.needsLayout = YES; -} - -- (void)layoutIfNeeded -{ - if ([self needsLayout]) { - [self layout]; - } -} - -- (void)layoutSubviews -{ - [super layout]; -} - -- (void)setNeedsDisplay -{ - self.needsDisplay = YES; -} - -@synthesize clipsToBounds = _clipsToBounds; - -@synthesize backgroundColor = _backgroundColor; - -- (void)setBackgroundColor:(NSColor *)backgroundColor -{ - if (_backgroundColor != backgroundColor && ![_backgroundColor isEqual:backgroundColor]) - { - _backgroundColor = [backgroundColor copy]; - [self setNeedsDisplay:YES]; - } -} - -// We purposely don't use RCTCursor for the parameter type here because it would introduce an import cycle: -// RCTUIKit > RCTCursor > RCTConvert > RCTUIKit -- (void)setCursor:(NSInteger)cursor -{ - // This method is required to be defined due to [RCTVirtualTextViewManager view] returning a RCTUIView. -} - -@end - -// RCTUIScrollView - -@implementation RCTUIScrollView - -- (instancetype)initWithFrame:(CGRect)frame -{ - if (self = [super initWithFrame:frame]) { - self.scrollEnabled = YES; - self.drawsBackground = NO; - self.contentView.postsBoundsChangedNotifications = YES; - [[NSNotificationCenter defaultCenter] addObserver:self - selector:@selector(_rctuiHandleBoundsDidChange:) - name:NSViewBoundsDidChangeNotification - object:self.contentView]; - } - - return self; -} - -- (void)_rctuiHandleBoundsDidChange:(NSNotification *)notification -{ - if ([_delegate respondsToSelector:@selector(scrollViewDidScroll:)]) { - [_delegate scrollViewDidScroll:self]; - } -} - -- (void)setEnableFocusRing:(BOOL)enableFocusRing { - if (_enableFocusRing != enableFocusRing) { - _enableFocusRing = enableFocusRing; - } - - if (enableFocusRing) { - // NSTextView has no focus ring by default so let's use the standard Aqua focus ring. - [self setFocusRingType:NSFocusRingTypeExterior]; - } else { - [self setFocusRingType:NSFocusRingTypeNone]; - } -} - -// UIScrollView properties missing from NSScrollView -- (CGPoint)contentOffset -{ - return self.documentVisibleRect.origin; -} - -- (void)setContentOffset:(CGPoint)contentOffset -{ - [self.documentView scrollPoint:contentOffset]; -} - -- (void)setContentOffset:(CGPoint)contentOffset animated:(BOOL)animated -{ - if (animated) { - [NSAnimationContext runAnimationGroup:^(NSAnimationContext *context) { - context.duration = 0.3; // Set the duration of the animation - [self.documentView.animator scrollPoint:contentOffset]; - } completionHandler:nil]; - } else { - [self.documentView scrollPoint:contentOffset]; - } -} - -- (UIEdgeInsets)contentInset -{ - return super.contentInsets; -} - -- (void)setContentInset:(UIEdgeInsets)insets -{ - super.contentInsets = insets; -} - -- (CGSize)contentSize -{ - return self.documentView.frame.size; -} - -- (void)setContentSize:(CGSize)contentSize -{ - CGRect frame = self.documentView.frame; - frame.size = contentSize; - self.documentView.frame = frame; -} - -- (BOOL)showsHorizontalScrollIndicator -{ - return self.hasHorizontalScroller; -} - -- (void)setShowsHorizontalScrollIndicator:(BOOL)show -{ - self.hasHorizontalScroller = show; -} - -- (BOOL)showsVerticalScrollIndicator -{ - return self.hasVerticalScroller; -} - -- (void)setShowsVerticalScrollIndicator:(BOOL)show -{ - self.hasVerticalScroller = show; -} - -- (UIEdgeInsets)scrollIndicatorInsets -{ - return self.scrollerInsets; -} - -- (void)setScrollIndicatorInsets:(UIEdgeInsets)insets -{ - self.scrollerInsets = insets; -} - -- (CGFloat)zoomScale -{ - return self.magnification; -} - -- (void)setZoomScale:(CGFloat)zoomScale -{ - self.magnification = zoomScale; -} - -- (CGFloat)maximumZoomScale -{ - return self.maxMagnification; -} - -- (void)setMaximumZoomScale:(CGFloat)maximumZoomScale -{ - self.maxMagnification = maximumZoomScale; -} - -- (CGFloat)minimumZoomScale -{ - return self.minMagnification; -} - -- (void)setMinimumZoomScale:(CGFloat)minimumZoomScale -{ - self.minMagnification = minimumZoomScale; -} - - -- (BOOL)alwaysBounceHorizontal -{ - return self.horizontalScrollElasticity != NSScrollElasticityNone; -} - -- (void)setAlwaysBounceHorizontal:(BOOL)alwaysBounceHorizontal -{ - self.horizontalScrollElasticity = alwaysBounceHorizontal ? NSScrollElasticityAllowed : NSScrollElasticityNone; -} - -- (BOOL)alwaysBounceVertical -{ - return self.verticalScrollElasticity != NSScrollElasticityNone; -} - -- (void)setAlwaysBounceVertical:(BOOL)alwaysBounceVertical -{ - self.verticalScrollElasticity = alwaysBounceVertical ? NSScrollElasticityAllowed : NSScrollElasticityNone; -} - -@end - -@implementation RCTClipView - -- (instancetype)initWithFrame:(NSRect)frameRect -{ - if (self = [super initWithFrame:frameRect]) { - self.constrainScrolling = NO; - self.drawsBackground = NO; - } - - return self; -} - -- (NSRect)constrainBoundsRect:(NSRect)proposedBounds -{ - if (self.constrainScrolling) { - return NSMakeRect(0, 0, 0, 0); - } - - return [super constrainBoundsRect:proposedBounds]; -} - -@end - -// RCTUISlider - -@implementation RCTUISlider {} - -- (void)setValue:(float)value animated:(__unused BOOL)animated -{ - self.animator.floatValue = value; -} - -@end - - -// RCTUILabel - -@implementation RCTUILabel {} - -- (instancetype)initWithFrame:(NSRect)frameRect -{ - if (self = [super initWithFrame:frameRect]) { - [self setBezeled:NO]; - [self setDrawsBackground:NO]; - [self setEditable:NO]; - [self setSelectable:NO]; - [self setWantsLayer:YES]; - } - - return self; -} - -- (void)setText:(NSString *)text -{ - [self setStringValue:text]; -} - -@end - -@implementation RCTUISwitch - -- (BOOL)isOn -{ - return self.state == NSControlStateValueOn; -} - -- (void)setOn:(BOOL)on -{ - [self setOn:on animated:NO]; -} - -- (void)setOn:(BOOL)on animated:(BOOL)animated { - self.state = on ? NSControlStateValueOn : NSControlStateValueOff; -} - -@end - -// RCTUIActivityIndicatorView - -@interface RCTUIActivityIndicatorView () -@property (nonatomic, readwrite, getter=isAnimating) BOOL animating; -@end - -@implementation RCTUIActivityIndicatorView {} - -- (instancetype)initWithFrame:(CGRect)frame -{ - if ((self = [super initWithFrame:frame])) { - self.displayedWhenStopped = NO; - self.style = NSProgressIndicatorStyleSpinning; - } - return self; -} - -- (void)startAnimating -{ - // `wantsLayer` gets reset after the animation is stopped. We have to - // reset it in order for CALayer filters to take effect. - [self setWantsLayer:YES]; - [self startAnimation:self]; -} - -- (void)stopAnimating -{ - [self stopAnimation:self]; -} - -- (void)startAnimation:(id)sender -{ - [super startAnimation:sender]; - self.animating = YES; -} - -- (void)stopAnimation:(id)sender -{ - [super stopAnimation:sender]; - self.animating = NO; -} - -- (void)setActivityIndicatorViewStyle:(UIActivityIndicatorViewStyle)activityIndicatorViewStyle -{ - _activityIndicatorViewStyle = activityIndicatorViewStyle; - - switch (activityIndicatorViewStyle) { - case UIActivityIndicatorViewStyleLarge: - self.controlSize = NSControlSizeLarge; - break; - case UIActivityIndicatorViewStyleMedium: - self.controlSize = NSControlSizeRegular; - break; - default: - break; - } -} - -- (void)setColor:(RCTUIColor*)color -{ - if (_color != color) { - _color = color; - [self setNeedsDisplay:YES]; - } -} - -- (void)updateLayer -{ - [super updateLayer]; - if (_color != nil) { - CGFloat r, g, b, a; - [[_color colorUsingColorSpace:[NSColorSpace genericRGBColorSpace]] getRed:&r green:&g blue:&b alpha:&a]; - - CIFilter *colorPoly = [CIFilter filterWithName:@"CIColorPolynomial"]; - [colorPoly setDefaults]; - - CIVector *redVector = [CIVector vectorWithX:r Y:0 Z:0 W:0]; - CIVector *greenVector = [CIVector vectorWithX:g Y:0 Z:0 W:0]; - CIVector *blueVector = [CIVector vectorWithX:b Y:0 Z:0 W:0]; - [colorPoly setValue:redVector forKey:@"inputRedCoefficients"]; - [colorPoly setValue:greenVector forKey:@"inputGreenCoefficients"]; - [colorPoly setValue:blueVector forKey:@"inputBlueCoefficients"]; - - [[self layer] setFilters:@[colorPoly]]; - } else { - [[self layer] setFilters:nil]; - } -} - -- (void)setHidesWhenStopped:(BOOL)hidesWhenStopped -{ - self.displayedWhenStopped = !hidesWhenStopped; -} - -- (BOOL)hidesWhenStopped -{ - return !self.displayedWhenStopped; -} - -- (void)setHidden:(BOOL)hidden -{ - if ([self hidesWhenStopped] && ![self isAnimating]) { - [super setHidden:YES]; - } else { - [super setHidden:hidden]; - } -} - -@end - -// RCTUIImageView - -@implementation RCTUIImageView { - CALayer *_tintingLayer; -} - -- (instancetype)initWithFrame:(CGRect)frame -{ - if (self = [super initWithFrame:frame]) { - [self setLayer:[[CALayer alloc] init]]; - [self setWantsLayer:YES]; - } - - return self; -} - -- (void)setContentMode:(UIViewContentMode)contentMode -{ - _contentMode = contentMode; - - CALayer *layer = [self layer]; - switch (contentMode) { - case UIViewContentModeScaleAspectFill: - [layer setContentsGravity:kCAGravityResizeAspectFill]; - break; - - case UIViewContentModeScaleAspectFit: - [layer setContentsGravity:kCAGravityResizeAspect]; - break; - - case UIViewContentModeScaleToFill: - [layer setContentsGravity:kCAGravityResize]; - break; - - case UIViewContentModeCenter: - [layer setContentsGravity:kCAGravityCenter]; - break; - - default: - break; - } -} - -- (RCTPlatformImage *)image -{ - return [[self layer] contents]; -} - -- (void)setImage:(RCTPlatformImage *)image -{ - CALayer *layer = [self layer]; - - if ([layer contents] != image || [layer backgroundColor] != nil) { - if (_tintColor) { - if (!_tintingLayer) { - _tintingLayer = [CALayer new]; - [_tintingLayer setFrame:self.bounds]; - [_tintingLayer setAutoresizingMask:kCALayerWidthSizable | kCALayerHeightSizable]; - [_tintingLayer setZPosition:1.0]; - CIFilter *sourceInCompositingFilter = [CIFilter filterWithName:@"CISourceInCompositing"]; - [sourceInCompositingFilter setDefaults]; - [_tintingLayer setCompositingFilter:sourceInCompositingFilter]; - [layer addSublayer:_tintingLayer]; - } - [_tintingLayer setBackgroundColor:_tintColor.CGColor]; - } else { - [_tintingLayer removeFromSuperlayer]; - _tintingLayer = nil; - } - - if (image != nil && [image resizingMode] == NSImageResizingModeTile) { - [layer setContents:nil]; - [layer setBackgroundColor:[NSColor colorWithPatternImage:image].CGColor]; - } else { - [layer setContents:image]; - [layer setBackgroundColor:nil]; - } - } -} - -@end - -@implementation RCTUIGraphicsImageRendererFormat - -+ (nonnull instancetype)defaultFormat { - RCTUIGraphicsImageRendererFormat *format = [RCTUIGraphicsImageRendererFormat new]; - return format; -} - -@end - -@implementation RCTUIGraphicsImageRenderer -{ - CGSize _size; - RCTUIGraphicsImageRendererFormat *_format; -} - -- (nonnull instancetype)initWithSize:(CGSize)size { - if (self = [super init]) { - self->_size = size; - } - return self; -} - -- (nonnull instancetype)initWithSize:(CGSize)size format:(nonnull RCTUIGraphicsImageRendererFormat *)format { - if (self = [super init]) { - self->_size = size; - self->_format = format; - } - return self; -} - -- (nonnull RCTUIImage *)imageWithActions:(NS_NOESCAPE RCTUIGraphicsImageDrawingActions)actions { - RCTUIImage *image = [RCTUIImage imageWithSize:_size - flipped:YES - drawingHandler:^BOOL(NSRect dstRect) { - - RCTUIGraphicsImageRendererContext *context = [NSGraphicsContext currentContext]; - if (self->_format.opaque) { - CGContextSetAlpha([context CGContext], 1.0); - } - actions(context); - return YES; - }]; - - // Calling these in succession forces the image to render its contents immediately, - // rather than deferring until later. - [image lockFocus]; - [image unlockFocus]; - - return image; -} - -@end - -#endif diff --git a/packages/react-native/React/Base/RCTPlatformDisplayLink.h b/packages/react-native/React/RCTUIKit/RCTPlatformDisplayLink.h similarity index 100% rename from packages/react-native/React/Base/RCTPlatformDisplayLink.h rename to packages/react-native/React/RCTUIKit/RCTPlatformDisplayLink.h diff --git a/packages/react-native/React/Base/macOS/RCTPlatformDisplayLink.m b/packages/react-native/React/RCTUIKit/RCTPlatformDisplayLink.m similarity index 97% rename from packages/react-native/React/Base/macOS/RCTPlatformDisplayLink.m rename to packages/react-native/React/RCTUIKit/RCTPlatformDisplayLink.m index 6ee09fde67a6..6082d4959904 100644 --- a/packages/react-native/React/Base/macOS/RCTPlatformDisplayLink.m +++ b/packages/react-native/React/RCTUIKit/RCTPlatformDisplayLink.m @@ -10,9 +10,6 @@ #import "RCTPlatformDisplayLink.h" -#import -#import - #import #import @@ -89,7 +86,7 @@ - (void)addToRunLoop:(NSRunLoop *)runloop forMode:(NSRunLoopMode)mode if (ret != kCVReturnSuccess) { ret = CVDisplayLinkCreateWithCGDisplay(CGMainDisplayID(), &_displayLink); } - RCTAssert(ret == kCVReturnSuccess, @"Cannot create display link"); + NSCAssert(ret == kCVReturnSuccess, @"Cannot create display link"); CVDisplayLinkSetOutputCallback(_displayLink, &RCTPlatformDisplayLinkCallBack, (__bridge void *)(self)); CVDisplayLinkStart(_displayLink); } diff --git a/packages/react-native/React/RCTUIKit/RCTUIAccessibilityTraits.h b/packages/react-native/React/RCTUIKit/RCTUIAccessibilityTraits.h new file mode 100644 index 000000000000..630b41112629 --- /dev/null +++ b/packages/react-native/React/RCTUIKit/RCTUIAccessibilityTraits.h @@ -0,0 +1,126 @@ +/* + * Copyright (c) Meta Platforms, Inc. and affiliates. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + */ + +// [macOS] + +#pragma once + +#include + +#if !TARGET_OS_OSX + +#import + +NS_ASSUME_NONNULL_BEGIN + +// [macOS RCTUIAccessibilityTraits - typedef to UIAccessibilityTraits on iOS +static const UIAccessibilityTraits RCTUIAccessibilityTraitSwitch = 0x20000000000001; + +typedef UIAccessibilityTraits RCTUIAccessibilityTraits; +#define RCTUIAccessibilityTraitNone UIAccessibilityTraitNone +#define RCTUIAccessibilityTraitButton UIAccessibilityTraitButton +#define RCTUIAccessibilityTraitLink UIAccessibilityTraitLink +#define RCTUIAccessibilityTraitImage UIAccessibilityTraitImage +#define RCTUIAccessibilityTraitSelected UIAccessibilityTraitSelected +#define RCTUIAccessibilityTraitPlaysSound UIAccessibilityTraitPlaysSound +#define RCTUIAccessibilityTraitKeyboardKey UIAccessibilityTraitKeyboardKey +#define RCTUIAccessibilityTraitStaticText UIAccessibilityTraitStaticText +#define RCTUIAccessibilityTraitSummaryElement UIAccessibilityTraitSummaryElement +#define RCTUIAccessibilityTraitNotEnabled UIAccessibilityTraitNotEnabled +#define RCTUIAccessibilityTraitUpdatesFrequently UIAccessibilityTraitUpdatesFrequently +#define RCTUIAccessibilityTraitSearchField UIAccessibilityTraitSearchField +#define RCTUIAccessibilityTraitStartsMediaSession UIAccessibilityTraitStartsMediaSession +#define RCTUIAccessibilityTraitAdjustable UIAccessibilityTraitAdjustable +#define RCTUIAccessibilityTraitAllowsDirectInteraction UIAccessibilityTraitAllowsDirectInteraction +#define RCTUIAccessibilityTraitCausesPageTurn UIAccessibilityTraitCausesPageTurn +#define RCTUIAccessibilityTraitHeader UIAccessibilityTraitHeader +#define RCTUIAccessibilityTraitTabBar UIAccessibilityTraitTabBar +// macOS] + +NS_ASSUME_NONNULL_END + +#else // TARGET_OS_OSX [ + +#import + +NS_ASSUME_NONNULL_BEGIN + +// UIAccessibility.h/NSAccessibility.h +@compatibility_alias UIAccessibilityCustomAction NSAccessibilityCustomAction; + +// [macOS RCTUIAccessibilityTraits - define as bitmask type for macOS +// On macOS these don't directly map to behavior, but allow code to compile +// The actual accessibility role mapping is done in RCTViewAccessibilityElement +typedef uint64_t RCTUIAccessibilityTraits; + +// Trait constants matching iOS UIAccessibilityConstants.h +static const RCTUIAccessibilityTraits RCTUIAccessibilityTraitNone = 0; +static const RCTUIAccessibilityTraits RCTUIAccessibilityTraitButton = (1ULL << 0); +static const RCTUIAccessibilityTraits RCTUIAccessibilityTraitLink = (1ULL << 1); +static const RCTUIAccessibilityTraits RCTUIAccessibilityTraitImage = (1ULL << 2); +static const RCTUIAccessibilityTraits RCTUIAccessibilityTraitSelected = (1ULL << 3); +static const RCTUIAccessibilityTraits RCTUIAccessibilityTraitPlaysSound = (1ULL << 4); +static const RCTUIAccessibilityTraits RCTUIAccessibilityTraitKeyboardKey = (1ULL << 5); +static const RCTUIAccessibilityTraits RCTUIAccessibilityTraitStaticText = (1ULL << 6); +static const RCTUIAccessibilityTraits RCTUIAccessibilityTraitSummaryElement = (1ULL << 7); +static const RCTUIAccessibilityTraits RCTUIAccessibilityTraitNotEnabled = (1ULL << 8); +static const RCTUIAccessibilityTraits RCTUIAccessibilityTraitUpdatesFrequently = (1ULL << 9); +static const RCTUIAccessibilityTraits RCTUIAccessibilityTraitSearchField = (1ULL << 10); +static const RCTUIAccessibilityTraits RCTUIAccessibilityTraitStartsMediaSession = (1ULL << 11); +static const RCTUIAccessibilityTraits RCTUIAccessibilityTraitAdjustable = (1ULL << 12); +static const RCTUIAccessibilityTraits RCTUIAccessibilityTraitAllowsDirectInteraction = (1ULL << 13); +static const RCTUIAccessibilityTraits RCTUIAccessibilityTraitCausesPageTurn = (1ULL << 14); +static const RCTUIAccessibilityTraits RCTUIAccessibilityTraitHeader = (1ULL << 15); +static const RCTUIAccessibilityTraits RCTUIAccessibilityTraitTabBar = (1ULL << 16); +static const RCTUIAccessibilityTraits RCTUIAccessibilityTraitSwitch = (1ULL << 17); + +// Convert RCTUIAccessibilityTraits to NSAccessibilityRole for macOS +NS_INLINE NSAccessibilityRole RCTAccessibilityRoleFromTraits(RCTUIAccessibilityTraits traits) +{ + if (traits & RCTUIAccessibilityTraitSwitch) { + return NSAccessibilityCheckBoxRole; + } + if (traits & RCTUIAccessibilityTraitButton) { + return NSAccessibilityButtonRole; + } + if (traits & RCTUIAccessibilityTraitLink) { + return NSAccessibilityLinkRole; + } + if (traits & RCTUIAccessibilityTraitImage) { + return NSAccessibilityImageRole; + } + if (traits & RCTUIAccessibilityTraitKeyboardKey) { + return NSAccessibilityButtonRole; + } + if (traits & RCTUIAccessibilityTraitHeader) { + return NSAccessibilityStaticTextRole; + } + if (traits & RCTUIAccessibilityTraitStaticText) { + return NSAccessibilityStaticTextRole; + } + if (traits & RCTUIAccessibilityTraitSummaryElement) { + return NSAccessibilityStaticTextRole; + } + if (traits & RCTUIAccessibilityTraitSearchField) { + return NSAccessibilityTextFieldRole; + } + if (traits & RCTUIAccessibilityTraitAdjustable) { + return NSAccessibilitySliderRole; + } + if (traits & RCTUIAccessibilityTraitUpdatesFrequently) { + return NSAccessibilityProgressIndicatorRole; + } + if (traits & RCTUIAccessibilityTraitTabBar) { + return NSAccessibilityTabGroupRole; + } + return NSAccessibilityUnknownRole; +} +// macOS] + +NS_ASSUME_NONNULL_END + +#endif // ] TARGET_OS_OSX diff --git a/packages/react-native/React/RCTUIKit/RCTUIControls.h b/packages/react-native/React/RCTUIKit/RCTUIControls.h new file mode 100644 index 000000000000..06818527d92a --- /dev/null +++ b/packages/react-native/React/RCTUIKit/RCTUIControls.h @@ -0,0 +1,115 @@ +/* + * Copyright (c) Meta Platforms, Inc. and affiliates. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + */ + +// [macOS] + +#pragma once + +#include + +#import + +// RCTUISlider + +#if !TARGET_OS_OSX +typedef UISlider RCTUISlider; +#else +@protocol RCTUISliderDelegate; + +@interface RCTUISlider : NSSlider +NS_ASSUME_NONNULL_BEGIN +@property (nonatomic, weak) id delegate; +@property (nonatomic, readonly) BOOL pressed; +@property (nonatomic, assign) float value; +@property (nonatomic, assign) float minimumValue; +@property (nonatomic, assign) float maximumValue; +@property (nonatomic, strong) NSColor *minimumTrackTintColor; +@property (nonatomic, strong) NSColor *maximumTrackTintColor; + +- (void)setValue:(float)value animated:(BOOL)animated; +NS_ASSUME_NONNULL_END +@end +#endif + +#if TARGET_OS_OSX // [macOS +@protocol RCTUISliderDelegate +@optional +NS_ASSUME_NONNULL_BEGIN +- (void)slider:(RCTUISlider *)slider didPress:(BOOL)press; +NS_ASSUME_NONNULL_END +@end +#endif // macOS] + +// RCTUILabel + +#if !TARGET_OS_OSX +typedef UILabel RCTUILabel; +#else +@interface RCTUILabel : NSTextField +NS_ASSUME_NONNULL_BEGIN +@property(nonatomic, copy) NSString* _Nullable text; +@property(nonatomic, assign) NSInteger numberOfLines; +@property(nonatomic, assign) NSTextAlignment textAlignment; +NS_ASSUME_NONNULL_END +@end +#endif + +// RCTUISwitch + +#if !TARGET_OS_OSX +typedef UISwitch RCTUISwitch; +#else +@interface RCTUISwitch : NSSwitch +NS_ASSUME_NONNULL_BEGIN +@property (nonatomic, getter=isOn) BOOL on; + +- (void)setOn:(BOOL)on animated:(BOOL)animated; + +NS_ASSUME_NONNULL_END +@end +#endif + +// RCTUIActivityIndicatorView + +#if !TARGET_OS_OSX +typedef UIActivityIndicatorView RCTUIActivityIndicatorView; +#else +@interface RCTUIActivityIndicatorView : NSProgressIndicator +NS_ASSUME_NONNULL_BEGIN +@property (nonatomic, assign) UIActivityIndicatorViewStyle activityIndicatorViewStyle; +@property (nonatomic, assign) BOOL hidesWhenStopped; +@property (nullable, readwrite, nonatomic, strong) RCTUIColor *color; +@property (nonatomic, readonly, getter=isAnimating) BOOL animating; + +- (void)startAnimating; +- (void)stopAnimating; +NS_ASSUME_NONNULL_END +@end + +#endif + +// RCTUITouch + +#if !TARGET_OS_OSX +typedef UITouch RCTUITouch; +#else +@interface RCTUITouch : NSEvent +@end +#endif + +// RCTUIImageView + +#if !TARGET_OS_OSX +typedef UIImageView RCTUIImageView; +#else +@interface RCTUIImageView : NSImageView +NS_ASSUME_NONNULL_BEGIN +@property (nonatomic, strong) RCTUIColor *tintColor; +@property (nonatomic, assign) UIViewContentMode contentMode; +NS_ASSUME_NONNULL_END +@end +#endif diff --git a/packages/react-native/React/RCTUIKit/RCTUIControls.m b/packages/react-native/React/RCTUIKit/RCTUIControls.m new file mode 100644 index 000000000000..b9f107bc8e4b --- /dev/null +++ b/packages/react-native/React/RCTUIKit/RCTUIControls.m @@ -0,0 +1,263 @@ +/** + * Copyright (c) 2015-present, Facebook, Inc. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + */ + +// [macOS] + +#if TARGET_OS_OSX + +#import + +#import +#import + +// RCTUISlider + +@implementation RCTUISlider {} + +- (void)setValue:(float)value animated:(__unused BOOL)animated +{ + self.animator.floatValue = value; +} + +@end + + +// RCTUILabel + +@implementation RCTUILabel {} + +- (instancetype)initWithFrame:(NSRect)frameRect +{ + if (self = [super initWithFrame:frameRect]) { + [self setBezeled:NO]; + [self setDrawsBackground:NO]; + [self setEditable:NO]; + [self setSelectable:NO]; + [self setWantsLayer:YES]; + } + + return self; +} + +- (void)setText:(NSString *)text +{ + [self setStringValue:text]; +} + +@end + +@implementation RCTUISwitch + +- (BOOL)isOn +{ + return self.state == NSControlStateValueOn; +} + +- (void)setOn:(BOOL)on +{ + [self setOn:on animated:NO]; +} + +- (void)setOn:(BOOL)on animated:(BOOL)animated { + self.state = on ? NSControlStateValueOn : NSControlStateValueOff; +} + +@end + +// RCTUIActivityIndicatorView + +@interface RCTUIActivityIndicatorView () +@property (nonatomic, readwrite, getter=isAnimating) BOOL animating; +@end + +@implementation RCTUIActivityIndicatorView {} + +- (instancetype)initWithFrame:(CGRect)frame +{ + if ((self = [super initWithFrame:frame])) { + self.displayedWhenStopped = NO; + self.style = NSProgressIndicatorStyleSpinning; + } + return self; +} + +- (void)startAnimating +{ + // `wantsLayer` gets reset after the animation is stopped. We have to + // reset it in order for CALayer filters to take effect. + [self setWantsLayer:YES]; + [self startAnimation:self]; +} + +- (void)stopAnimating +{ + [self stopAnimation:self]; +} + +- (void)startAnimation:(id)sender +{ + [super startAnimation:sender]; + self.animating = YES; +} + +- (void)stopAnimation:(id)sender +{ + [super stopAnimation:sender]; + self.animating = NO; +} + +- (void)setActivityIndicatorViewStyle:(UIActivityIndicatorViewStyle)activityIndicatorViewStyle +{ + _activityIndicatorViewStyle = activityIndicatorViewStyle; + + switch (activityIndicatorViewStyle) { + case UIActivityIndicatorViewStyleLarge: + self.controlSize = NSControlSizeLarge; + break; + case UIActivityIndicatorViewStyleMedium: + self.controlSize = NSControlSizeRegular; + break; + default: + break; + } +} + +- (void)setColor:(RCTUIColor*)color +{ + if (_color != color) { + _color = color; + [self setNeedsDisplay:YES]; + } +} + +- (void)updateLayer +{ + [super updateLayer]; + if (_color != nil) { + CGFloat r, g, b, a; + [[_color colorUsingColorSpace:[NSColorSpace genericRGBColorSpace]] getRed:&r green:&g blue:&b alpha:&a]; + + CIFilter *colorPoly = [CIFilter filterWithName:@"CIColorPolynomial"]; + [colorPoly setDefaults]; + + CIVector *redVector = [CIVector vectorWithX:r Y:0 Z:0 W:0]; + CIVector *greenVector = [CIVector vectorWithX:g Y:0 Z:0 W:0]; + CIVector *blueVector = [CIVector vectorWithX:b Y:0 Z:0 W:0]; + [colorPoly setValue:redVector forKey:@"inputRedCoefficients"]; + [colorPoly setValue:greenVector forKey:@"inputGreenCoefficients"]; + [colorPoly setValue:blueVector forKey:@"inputBlueCoefficients"]; + + [[self layer] setFilters:@[colorPoly]]; + } else { + [[self layer] setFilters:nil]; + } +} + +- (void)setHidesWhenStopped:(BOOL)hidesWhenStopped +{ + self.displayedWhenStopped = !hidesWhenStopped; +} + +- (BOOL)hidesWhenStopped +{ + return !self.displayedWhenStopped; +} + +- (void)setHidden:(BOOL)hidden +{ + if ([self hidesWhenStopped] && ![self isAnimating]) { + [super setHidden:YES]; + } else { + [super setHidden:hidden]; + } +} + +@end + +// RCTUIImageView + +@implementation RCTUIImageView { + CALayer *_tintingLayer; +} + +- (instancetype)initWithFrame:(CGRect)frame +{ + if (self = [super initWithFrame:frame]) { + [self setLayer:[[CALayer alloc] init]]; + [self setWantsLayer:YES]; + } + + return self; +} + +- (void)setContentMode:(UIViewContentMode)contentMode +{ + _contentMode = contentMode; + + CALayer *layer = [self layer]; + switch (contentMode) { + case UIViewContentModeScaleAspectFill: + [layer setContentsGravity:kCAGravityResizeAspectFill]; + break; + + case UIViewContentModeScaleAspectFit: + [layer setContentsGravity:kCAGravityResizeAspect]; + break; + + case UIViewContentModeScaleToFill: + [layer setContentsGravity:kCAGravityResize]; + break; + + case UIViewContentModeCenter: + [layer setContentsGravity:kCAGravityCenter]; + break; + + default: + break; + } +} + +- (RCTPlatformImage *)image +{ + return [[self layer] contents]; +} + +- (void)setImage:(RCTPlatformImage *)image +{ + CALayer *layer = [self layer]; + + if ([layer contents] != image || [layer backgroundColor] != nil) { + if (_tintColor) { + if (!_tintingLayer) { + _tintingLayer = [CALayer new]; + [_tintingLayer setFrame:self.bounds]; + [_tintingLayer setAutoresizingMask:kCALayerWidthSizable | kCALayerHeightSizable]; + [_tintingLayer setZPosition:1.0]; + CIFilter *sourceInCompositingFilter = [CIFilter filterWithName:@"CISourceInCompositing"]; + [sourceInCompositingFilter setDefaults]; + [_tintingLayer setCompositingFilter:sourceInCompositingFilter]; + [layer addSublayer:_tintingLayer]; + } + [_tintingLayer setBackgroundColor:_tintColor.CGColor]; + } else { + [_tintingLayer removeFromSuperlayer]; + _tintingLayer = nil; + } + + if (image != nil && [image resizingMode] == NSImageResizingModeTile) { + [layer setContents:nil]; + [layer setBackgroundColor:[NSColor colorWithPatternImage:image].CGColor]; + } else { + [layer setContents:image]; + [layer setBackgroundColor:nil]; + } + } +} + +@end + +#endif diff --git a/packages/react-native/React/RCTUIKit/RCTUIGeometry.h b/packages/react-native/React/RCTUIKit/RCTUIGeometry.h new file mode 100644 index 000000000000..9e9ab597fa3b --- /dev/null +++ b/packages/react-native/React/RCTUIKit/RCTUIGeometry.h @@ -0,0 +1,87 @@ +/* + * Copyright (c) Meta Platforms, Inc. and affiliates. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + */ + +// [macOS] + +#pragma once + +#include + +#if !TARGET_OS_OSX + +#import + +NS_ASSUME_NONNULL_BEGIN + +UIKIT_STATIC_INLINE NSValue *NSValueWithCGRect(CGRect rect) +{ + return [NSValue valueWithCGRect:rect]; +} + +UIKIT_STATIC_INLINE NSValue *NSValueWithCGSize(CGSize size) +{ + return [NSValue valueWithCGSize:size]; +} + +UIKIT_STATIC_INLINE CGRect CGRectValue(NSValue *value) +{ + return [value CGRectValue]; +} + +NS_ASSUME_NONNULL_END + +#else // TARGET_OS_OSX [ + +#import + +NS_ASSUME_NONNULL_BEGIN + +// UIGeometry.h/NSGeometry.h +NS_INLINE CGRect UIEdgeInsetsInsetRect(CGRect rect, NSEdgeInsets insets) +{ + rect.origin.x += insets.left; + rect.origin.y += insets.top; + rect.size.width -= (insets.left + insets.right); + rect.size.height -= (insets.top + insets.bottom); + return rect; +} + +NS_INLINE BOOL UIEdgeInsetsEqualToEdgeInsets(NSEdgeInsets insets1, NSEdgeInsets insets2) +{ + return NSEdgeInsetsEqual(insets1, insets2); +} + +NS_INLINE NSString *NSStringFromCGSize(CGSize size) +{ + return NSStringFromSize(NSSizeFromCGSize(size)); +} + +NS_INLINE NSString *NSStringFromCGRect(CGRect rect) +{ + return NSStringFromRect(NSRectFromCGRect(rect)); +} + +NS_INLINE NSValue *NSValueWithCGRect(CGRect rect) +{ + return [NSValue valueWithBytes:&rect objCType:@encode(CGRect)]; +} + +NS_INLINE NSValue *NSValueWithCGSize(CGSize size) +{ + return [NSValue valueWithBytes:&size objCType:@encode(CGSize)]; +} + +NS_INLINE CGRect CGRectValue(NSValue *value) +{ + CGRect rect = CGRectZero; + [value getValue:&rect]; + return rect; +} + +NS_ASSUME_NONNULL_END + +#endif // ] TARGET_OS_OSX diff --git a/packages/react-native/React/RCTUIKit/RCTUIGraphics.h b/packages/react-native/React/RCTUIKit/RCTUIGraphics.h new file mode 100644 index 000000000000..c291ab329a51 --- /dev/null +++ b/packages/react-native/React/RCTUIKit/RCTUIGraphics.h @@ -0,0 +1,58 @@ +/* + * Copyright (c) Meta Platforms, Inc. and affiliates. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + */ + +// [macOS] + +#pragma once + +#include + +#if !TARGET_OS_OSX + +#import + +NS_ASSUME_NONNULL_BEGIN + +UIKIT_STATIC_INLINE UIBezierPath *UIBezierPathWithRoundedRect(CGRect rect, CGFloat cornerRadius) +{ + return [UIBezierPath bezierPathWithRoundedRect:rect cornerRadius:cornerRadius]; +} + +UIKIT_STATIC_INLINE void UIBezierPathAppendPath(UIBezierPath *path, UIBezierPath *appendPath) +{ + [path appendPath:appendPath]; +} + +NS_ASSUME_NONNULL_END + +#else // TARGET_OS_OSX [ + +#import + +NS_ASSUME_NONNULL_BEGIN + +#ifdef __cplusplus +extern "C" { +#endif + +// UIGraphics.h +CGContextRef UIGraphicsGetCurrentContext(void); + +#ifdef __cplusplus +} +#endif // __cpusplus + +// UIBezierPath +@compatibility_alias UIBezierPath NSBezierPath; + +UIBezierPath *UIBezierPathWithRoundedRect(CGRect rect, CGFloat cornerRadius); + +void UIBezierPathAppendPath(UIBezierPath *path, UIBezierPath *appendPath); + +NS_ASSUME_NONNULL_END + +#endif // ] TARGET_OS_OSX diff --git a/packages/react-native/React/RCTUIKit/RCTUIGraphics.m b/packages/react-native/React/RCTUIKit/RCTUIGraphics.m new file mode 100644 index 000000000000..1dbd2ff10814 --- /dev/null +++ b/packages/react-native/React/RCTUIKit/RCTUIGraphics.m @@ -0,0 +1,56 @@ +/** + * Copyright (c) 2015-present, Facebook, Inc. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + */ + +// [macOS] + +#if TARGET_OS_OSX + +#import + +#import + +static char RCTGraphicsContextSizeKey; + +// UIGraphics.h + +CGContextRef UIGraphicsGetCurrentContext(void) +{ + return [[NSGraphicsContext currentContext] CGContext]; +} + +NSImage *UIGraphicsGetImageFromCurrentImageContext(void) +{ + NSImage *image = nil; + NSGraphicsContext *graphicsContext = [NSGraphicsContext currentContext]; + + NSValue *sizeValue = objc_getAssociatedObject(graphicsContext, &RCTGraphicsContextSizeKey); + if (sizeValue != nil) { + CGImageRef cgImage = CGBitmapContextCreateImage([graphicsContext CGContext]); + + if (cgImage != NULL) { + NSBitmapImageRep *imageRep = [[NSBitmapImageRep alloc] initWithCGImage:cgImage]; + image = [[NSImage alloc] initWithSize:[sizeValue sizeValue]]; + [image addRepresentation:imageRep]; + CFRelease(cgImage); + } + } + + return image; +} + +// UIBezierPath +UIBezierPath *UIBezierPathWithRoundedRect(CGRect rect, CGFloat cornerRadius) +{ + return [NSBezierPath bezierPathWithRoundedRect:rect xRadius:cornerRadius yRadius:cornerRadius]; +} + +void UIBezierPathAppendPath(UIBezierPath *path, UIBezierPath *appendPath) +{ + return [path appendBezierPath:appendPath]; +} + +#endif diff --git a/packages/react-native/React/RCTUIKit/RCTUIGraphicsImageRenderer.h b/packages/react-native/React/RCTUIKit/RCTUIGraphicsImageRenderer.h new file mode 100644 index 000000000000..2ad1761c2d86 --- /dev/null +++ b/packages/react-native/React/RCTUIKit/RCTUIGraphicsImageRenderer.h @@ -0,0 +1,51 @@ +/* + * Copyright (c) Meta Platforms, Inc. and affiliates. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + */ + +// [macOS] + +#pragma once + +#include + +#import + +#if !TARGET_OS_OSX + +#import + +typedef UIGraphicsImageRendererContext RCTUIGraphicsImageRendererContext; +typedef UIGraphicsImageDrawingActions RCTUIGraphicsImageDrawingActions; +typedef UIGraphicsImageRendererFormat RCTUIGraphicsImageRendererFormat; +typedef UIGraphicsImageRenderer RCTUIGraphicsImageRenderer; + +#else // TARGET_OS_OSX [ + +#import + +NS_ASSUME_NONNULL_BEGIN +typedef NSGraphicsContext RCTUIGraphicsImageRendererContext; +typedef void (^RCTUIGraphicsImageDrawingActions)(RCTUIGraphicsImageRendererContext *rendererContext); + +@interface RCTUIGraphicsImageRendererFormat : NSObject + ++ (instancetype)defaultFormat; + +@property (nonatomic) CGFloat scale; +@property (nonatomic) BOOL opaque; + +@end + +@interface RCTUIGraphicsImageRenderer : NSObject + +- (instancetype)initWithSize:(CGSize)size; +- (instancetype)initWithSize:(CGSize)size format:(RCTUIGraphicsImageRendererFormat *)format; +- (RCTUIImage *)imageWithActions:(NS_NOESCAPE RCTUIGraphicsImageDrawingActions)actions; + +@end +NS_ASSUME_NONNULL_END + +#endif // ] TARGET_OS_OSX diff --git a/packages/react-native/React/RCTUIKit/RCTUIGraphicsImageRenderer.m b/packages/react-native/React/RCTUIKit/RCTUIGraphicsImageRenderer.m new file mode 100644 index 000000000000..58cd8cdd09fe --- /dev/null +++ b/packages/react-native/React/RCTUIKit/RCTUIGraphicsImageRenderer.m @@ -0,0 +1,68 @@ +/** + * Copyright (c) 2015-present, Facebook, Inc. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + */ + +// [macOS] + +#if TARGET_OS_OSX + +#import +#import + +@implementation RCTUIGraphicsImageRendererFormat + ++ (nonnull instancetype)defaultFormat { + RCTUIGraphicsImageRendererFormat *format = [RCTUIGraphicsImageRendererFormat new]; + return format; +} + +@end + +@implementation RCTUIGraphicsImageRenderer +{ + CGSize _size; + RCTUIGraphicsImageRendererFormat *_format; +} + +- (nonnull instancetype)initWithSize:(CGSize)size { + if (self = [super init]) { + self->_size = size; + } + return self; +} + +- (nonnull instancetype)initWithSize:(CGSize)size format:(nonnull RCTUIGraphicsImageRendererFormat *)format { + if (self = [super init]) { + self->_size = size; + self->_format = format; + } + return self; +} + +- (nonnull RCTUIImage *)imageWithActions:(NS_NOESCAPE RCTUIGraphicsImageDrawingActions)actions { + RCTUIImage *image = [RCTUIImage imageWithSize:_size + flipped:YES + drawingHandler:^BOOL(NSRect dstRect) { + + RCTUIGraphicsImageRendererContext *context = [NSGraphicsContext currentContext]; + if (self->_format.opaque) { + CGContextSetAlpha([context CGContext], 1.0); + } + actions(context); + return YES; + }]; + + // Calling these in succession forces the image to render its contents immediately, + // rather than deferring until later. + [image lockFocus]; + [image unlockFocus]; + + return image; +} + +@end + +#endif diff --git a/packages/react-native/React/RCTUIKit/RCTUIImage.h b/packages/react-native/React/RCTUIKit/RCTUIImage.h new file mode 100644 index 000000000000..aa11a9f1a384 --- /dev/null +++ b/packages/react-native/React/RCTUIKit/RCTUIImage.h @@ -0,0 +1,100 @@ +/* + * Copyright (c) Meta Platforms, Inc. and affiliates. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + */ + +// [macOS] + +#pragma once + +#include + +#import + +#if !TARGET_OS_OSX + +#import + +NS_ASSUME_NONNULL_BEGIN + +UIKIT_STATIC_INLINE CGFloat UIImageGetScale(UIImage *image) +{ + return image.scale; +} + +UIKIT_STATIC_INLINE CGImageRef UIImageGetCGImageRef(UIImage *image) +{ + return image.CGImage; +} + +UIKIT_STATIC_INLINE UIImage *UIImageWithContentsOfFile(NSString *filePath) +{ + return [UIImage imageWithContentsOfFile:filePath]; +} + +UIKIT_STATIC_INLINE UIImage *UIImageWithData(NSData *imageData) +{ + return [UIImage imageWithData:imageData]; +} + +NS_ASSUME_NONNULL_END + +#else // TARGET_OS_OSX [ + +#import + +NS_ASSUME_NONNULL_BEGIN + +/** + * An NSImage subclass that caches its CGImage representation. + * + * RCTUIImage solves an issue where NSImage's `CGImageForProposedRect:` returns a new + * autoreleased CGImage each time it's called. When assigned to `CALayer.contents`, these + * autoreleased CGImages get deallocated when the autorelease pool drains, causing rendering + * issues (e.g., blank borders and shadows). + * + * @warning Treat RCTUIImage instances as immutable after creation. Do not modify the image's + * representations or properties after accessing the CGImage property. + */ +@interface RCTUIImage : NSImage + +@property (nonatomic, readonly, nullable) CGImageRef CGImage; + +@property (nonatomic, readonly) CGFloat scale; + +@end + +typedef NS_ENUM(NSInteger, UIImageRenderingMode) { + UIImageRenderingModeAlwaysOriginal, + UIImageRenderingModeAlwaysTemplate, +}; + +#ifdef __cplusplus +extern "C" { +#endif + +CGFloat UIImageGetScale(NSImage *image); +CGImageRef __nullable UIImageGetCGImageRef(NSImage *image); + +#ifdef __cplusplus +} +#endif + +NS_INLINE NSImage *UIImageWithContentsOfFile(NSString *filePath) +{ + return [[NSImage alloc] initWithContentsOfFile:filePath]; +} + +NS_INLINE NSImage *UIImageWithData(NSData *imageData) +{ + return [[NSImage alloc] initWithData:imageData]; +} + +NSData *UIImagePNGRepresentation(NSImage *image); +NSData *UIImageJPEGRepresentation(NSImage *image, CGFloat compressionQuality); + +NS_ASSUME_NONNULL_END + +#endif // ] TARGET_OS_OSX diff --git a/packages/react-native/React/RCTUIKit/RCTUIImage.m b/packages/react-native/React/RCTUIKit/RCTUIImage.m new file mode 100644 index 000000000000..3995667e21ca --- /dev/null +++ b/packages/react-native/React/RCTUIKit/RCTUIImage.m @@ -0,0 +1,98 @@ +/** + * Copyright (c) 2015-present, Facebook, Inc. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + */ + +// [macOS] + +#if TARGET_OS_OSX + +#import + +// UIImage + +CGFloat UIImageGetScale(NSImage *image) +{ + if (image == nil) { + return 0.0; + } + + NSCAssert(image.representations.count == 1, @"The scale can only be derived if the image has one representation."); + + NSImageRep *imageRep = image.representations.firstObject; + if (imageRep != nil) { + NSSize imageSize = image.size; + NSSize repSize = CGSizeMake(imageRep.pixelsWide, imageRep.pixelsHigh); + + return round(fmax(repSize.width / imageSize.width, repSize.height / imageSize.height)); + } + + return 1.0; +} + +// RCTUIImage - NSImage subclass with cached CGImage + +@implementation RCTUIImage { + CGImageRef _cachedCGImage; +} + +- (void)dealloc { + if (_cachedCGImage != NULL) { + CGImageRelease(_cachedCGImage); + } +} + +- (CGImageRef)CGImage { + if (_cachedCGImage == NULL) { + CGImageRef cgImage = [self CGImageForProposedRect:NULL context:NULL hints:NULL]; + if (cgImage != NULL) { + _cachedCGImage = CGImageRetain(cgImage); + } + } + return _cachedCGImage; +} + +- (CGFloat)scale { + return UIImageGetScale(self); +} + +@end + +CGImageRef __nullable UIImageGetCGImageRef(NSImage *image) +{ + // If it's an RCTUIImage, use the cached CGImage property + if ([image isKindOfClass:[RCTUIImage class]]) { + return ((RCTUIImage *)image).CGImage; + } + + // Otherwise, fall back to the standard NSImage method + // Note: This returns an autoreleased CGImageRef + return [image CGImageForProposedRect:NULL context:NULL hints:NULL]; +} + +static NSData *NSImageDataForFileType(NSImage *image, NSBitmapImageFileType fileType, NSDictionary *properties) +{ + NSCAssert(image.representations.count == 1, @"Expected only a single representation since UIImage only supports one."); + + NSBitmapImageRep *imageRep = (NSBitmapImageRep *)image.representations.firstObject; + if (![imageRep isKindOfClass:[NSBitmapImageRep class]]) { + NSCAssert([imageRep isKindOfClass:[NSBitmapImageRep class]], @"We need an NSBitmapImageRep to create an image."); + return nil; + } + + return [imageRep representationUsingType:fileType properties:properties]; +} + +NSData *UIImagePNGRepresentation(NSImage *image) { + return NSImageDataForFileType(image, NSBitmapImageFileTypePNG, @{}); +} + +NSData *UIImageJPEGRepresentation(NSImage *image, CGFloat compressionQuality) { + return NSImageDataForFileType(image, + NSBitmapImageFileTypeJPEG, + @{NSImageCompressionFactor: @(compressionQuality)}); +} + +#endif diff --git a/packages/react-native/React/RCTUIKit/RCTUIKit.h b/packages/react-native/React/RCTUIKit/RCTUIKit.h new file mode 100644 index 000000000000..c9c904dde921 --- /dev/null +++ b/packages/react-native/React/RCTUIKit/RCTUIKit.h @@ -0,0 +1,19 @@ +/* + * Copyright (c) Meta Platforms, Inc. and affiliates. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + */ + +// [macOS] +// Umbrella header for RCTUIKit — the UIKit/AppKit compatibility layer. + +#import +#import +#import +#import +#import +#import +#import +#import +#import diff --git a/packages/react-native/React/RCTUIKit/RCTUIKitCompat.h b/packages/react-native/React/RCTUIKit/RCTUIKitCompat.h new file mode 100644 index 000000000000..f3f643c10dfb --- /dev/null +++ b/packages/react-native/React/RCTUIKit/RCTUIKitCompat.h @@ -0,0 +1,225 @@ +/* + * Copyright (c) Meta Platforms, Inc. and affiliates. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + */ + +// [macOS] + +#pragma once + +#include + +#if !TARGET_OS_OSX + +#import + +NS_ASSUME_NONNULL_BEGIN + +// UIView +#define RCTPlatformView UIView +#define RCTUIView UIView +#define RCTUIScrollView UIScrollView +#define RCTUIScrollViewDelegate UIScrollViewDelegate +#define RCTPlatformImage UIImage +#define RCTUIImage UIImage +#define RCTUIPanGestureRecognizer UIPanGestureRecognizer + +// UIColor.h +#define RCTUIColor UIColor + +NS_ASSUME_NONNULL_END + +#else // TARGET_OS_OSX [ + +#import + +NS_ASSUME_NONNULL_BEGIN + +#define RCTPlatformImage NSImage + +// +// semantically equivalent constants +// + +// UIApplication.h/NSApplication.h +#define UIApplicationDidBecomeActiveNotification NSApplicationDidBecomeActiveNotification +#define UIApplicationDidEnterBackgroundNotification NSApplicationDidHideNotification +#define UIApplicationDidFinishLaunchingNotification NSApplicationDidFinishLaunchingNotification +#define UIApplicationWillResignActiveNotification NSApplicationWillResignActiveNotification +#define UIApplicationWillEnterForegroundNotification NSApplicationWillUnhideNotification + +// UIFontDescriptor.h/NSFontDescriptor.h +#define UIFontDescriptorFamilyAttribute NSFontFamilyAttribute; +#define UIFontDescriptorNameAttribute NSFontNameAttribute; +#define UIFontDescriptorFaceAttribute NSFontFaceAttribute; +#define UIFontDescriptorSizeAttribute NSFontSizeAttribute + +#define UIFontDescriptorTraitsAttribute NSFontTraitsAttribute +#define UIFontDescriptorFeatureSettingsAttribute NSFontFeatureSettingsAttribute + +#define UIFontSymbolicTrait NSFontSymbolicTrait +#define UIFontWeightTrait NSFontWeightTrait +#define UIFontFeatureTypeIdentifierKey NSFontFeatureTypeIdentifierKey +#define UIFontFeatureSelectorIdentifierKey NSFontFeatureSelectorIdentifierKey + +#define UIFontWeightUltraLight NSFontWeightUltraLight +#define UIFontWeightThin NSFontWeightThin +#define UIFontWeightLight NSFontWeightLight +#define UIFontWeightRegular NSFontWeightRegular +#define UIFontWeightMedium NSFontWeightMedium +#define UIFontWeightSemibold NSFontWeightSemibold +#define UIFontWeightBold NSFontWeightBold +#define UIFontWeightHeavy NSFontWeightHeavy +#define UIFontWeightBlack NSFontWeightBlack + +#define UIFontDescriptorSystemDesign NSFontDescriptorSystemDesign +#define UIFontDescriptorSystemDesignDefault NSFontDescriptorSystemDesignDefault +#define UIFontDescriptorSystemDesignSerif NSFontDescriptorSystemDesignSerif +#define UIFontDescriptorSystemDesignRounded NSFontDescriptorSystemDesignRounded +#define UIFontDescriptorSystemDesignMonospaced NSFontDescriptorSystemDesignMonospaced + + +// RCTActivityIndicatorView.h +#define UIActivityIndicatorView NSProgressIndicator + + +// UIGeometry.h/NSGeometry.h +#define UIEdgeInsetsZero NSEdgeInsetsZero + +// UIView.h/NSLayoutConstraint.h +#define UIViewNoIntrinsicMetric -1 +// NSViewNoIntrinsicMetric is defined to -1 but is only available on macOS 10.11 and higher. On previous versions it was NSViewNoInstrinsicMetric (misspelled) and also defined to -1. + +// UIInterface.h/NSUserInterfaceLayout.h +#define UIUserInterfaceLayoutDirection NSUserInterfaceLayoutDirection + +// +// semantically equivalent enums +// + +// UIGestureRecognizer.h/NSGestureRecognizer.h +enum +{ + UIGestureRecognizerStatePossible = NSGestureRecognizerStatePossible, + UIGestureRecognizerStateBegan = NSGestureRecognizerStateBegan, + UIGestureRecognizerStateChanged = NSGestureRecognizerStateChanged, + UIGestureRecognizerStateEnded = NSGestureRecognizerStateEnded, + UIGestureRecognizerStateCancelled = NSGestureRecognizerStateCancelled, + UIGestureRecognizerStateFailed = NSGestureRecognizerStateFailed, + UIGestureRecognizerStateRecognized = NSGestureRecognizerStateRecognized, +}; + +// UIFontDescriptor.h/NSFontDescriptor.h +enum +{ + UIFontDescriptorTraitItalic = NSFontItalicTrait, + UIFontDescriptorTraitBold = NSFontBoldTrait, + UIFontDescriptorTraitCondensed = NSFontCondensedTrait, +}; + +// UIView.h/NSView.h +enum : NSUInteger +{ + UIViewAutoresizingNone = NSViewNotSizable, + UIViewAutoresizingFlexibleLeftMargin = NSViewMinXMargin, + UIViewAutoresizingFlexibleWidth = NSViewWidthSizable, + UIViewAutoresizingFlexibleRightMargin = NSViewMaxXMargin, + UIViewAutoresizingFlexibleTopMargin = NSViewMinYMargin, + UIViewAutoresizingFlexibleHeight = NSViewHeightSizable, + UIViewAutoresizingFlexibleBottomMargin = NSViewMaxYMargin, +}; + +// UIView/NSView.h +typedef NS_ENUM(NSInteger, UIViewContentMode) { + UIViewContentModeScaleAspectFill = NSViewLayerContentsPlacementScaleProportionallyToFill, + UIViewContentModeScaleAspectFit = NSViewLayerContentsPlacementScaleProportionallyToFit, + UIViewContentModeScaleToFill = NSViewLayerContentsPlacementScaleAxesIndependently, + UIViewContentModeCenter = NSViewLayerContentsPlacementCenter, + UIViewContentModeTopLeft = NSViewLayerContentsPlacementTopLeft, +}; + +// UIInterface.h/NSUserInterfaceLayout.h +enum : NSInteger +{ + UIUserInterfaceLayoutDirectionLeftToRight = NSUserInterfaceLayoutDirectionLeftToRight, + UIUserInterfaceLayoutDirectionRightToLeft = NSUserInterfaceLayoutDirectionRightToLeft, +}; + +// RCTActivityIndicatorView.h +typedef NS_ENUM(NSInteger, UIActivityIndicatorViewStyle) { + UIActivityIndicatorViewStyleLarge, + UIActivityIndicatorViewStyleMedium, +}; + +// UIColor.h/NSColor.h +#define RCTUIColor NSColor + +// UIFont.h/NSFont.h +// Both NSFont and UIFont are toll-free bridged to CTFontRef so we'll assume they're semantically equivalent +@compatibility_alias UIFont NSFont; + +// UIViewController.h/NSViewController.h +@compatibility_alias UIViewController NSViewController; + +NS_INLINE NSFont *UIFontWithSize(NSFont *font, CGFloat pointSize) +{ + return [NSFont fontWithDescriptor:font.fontDescriptor size:pointSize]; +} + +NS_INLINE CGFloat UIFontLineHeight(NSFont *font) +{ + return ceilf(font.ascender + ABS(font.descender) + font.leading); +} + +// UIFontDescriptor.h/NSFontDescriptor.h +// Both NSFontDescriptor and UIFontDescriptor are toll-free bridged to CTFontDescriptorRef so we'll assume they're semantically equivalent +@compatibility_alias UIFontDescriptor NSFontDescriptor; +typedef NSFontSymbolicTraits UIFontDescriptorSymbolicTraits; +typedef NSFontWeight UIFontWeight; + +// UIGeometry.h/NSGeometry.h +typedef NSEdgeInsets UIEdgeInsets; + +NS_INLINE NSEdgeInsets UIEdgeInsetsMake(CGFloat top, CGFloat left, CGFloat bottom, CGFloat right) +{ + return NSEdgeInsetsMake(top, left, bottom, right); +} + +// +// functionally equivalent types +// + +// These types have the same purpose but may differ semantically. Use with care! + +#define UIEvent NSEvent +#define UITouchType NSTouchType +#define UIEventButtonMask NSEventButtonMask +#define UIKeyModifierFlags NSEventModifierFlags + +// UIGestureRecognizer +#define UIGestureRecognizer NSGestureRecognizer +#define UIGestureRecognizerDelegate NSGestureRecognizerDelegate +#define RCTUIPanGestureRecognizer NSPanGestureRecognizer + +// UIApplication +#define UIApplication NSApplication + +NS_ASSUME_NONNULL_END + +#endif // ] TARGET_OS_OSX + +// +// Cross-platform typedefs +// + +#if !TARGET_OS_OSX +typedef UIApplication RCTUIApplication; +typedef UIWindow RCTPlatformWindow; +typedef UIViewController RCTPlatformViewController; +#else +typedef NSApplication RCTUIApplication; +typedef NSWindow RCTPlatformWindow; +typedef NSViewController RCTPlatformViewController; +#endif diff --git a/packages/react-native/React/RCTUIKit/RCTUIView.h b/packages/react-native/React/RCTUIKit/RCTUIView.h new file mode 100644 index 000000000000..be0f7f3af88d --- /dev/null +++ b/packages/react-native/React/RCTUIKit/RCTUIView.h @@ -0,0 +1,163 @@ +/* + * Copyright (c) Meta Platforms, Inc. and affiliates. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + */ + +// [macOS] + +#pragma once + +#include + +#import + +#if !TARGET_OS_OSX + +#import + +NS_ASSUME_NONNULL_BEGIN + +UIKIT_STATIC_INLINE RCTPlatformView *RCTUIViewHitTestWithEvent(RCTPlatformView *view, CGPoint point, __unused UIEvent *__nullable event) +{ + return [view hitTest:point withEvent:event]; +} + +UIKIT_STATIC_INLINE void RCTUIViewSetContentModeRedraw(UIView *view) +{ + view.contentMode = UIViewContentModeRedraw; +} + +UIKIT_STATIC_INLINE BOOL RCTUIViewIsDescendantOfView(RCTPlatformView *view, RCTPlatformView *parent) +{ + return [view isDescendantOfView:parent]; +} + +NS_ASSUME_NONNULL_END + +#else // TARGET_OS_OSX [ + +#import + +NS_ASSUME_NONNULL_BEGIN + +// UIView +#define RCTPlatformView NSView + +@interface RCTUIView : RCTPlatformView + +@property (nonatomic, readonly) BOOL canBecomeFirstResponder; +- (BOOL)becomeFirstResponder; +@property(nonatomic, readonly) BOOL isFirstResponder; + +@property (nonatomic, getter=isUserInteractionEnabled) BOOL userInteractionEnabled; + +- (NSView *)hitTest:(CGPoint)point withEvent:(UIEvent *_Nullable)event; +- (BOOL)pointInside:(CGPoint)point withEvent:(UIEvent *)event; + +- (void)insertSubview:(NSView *)view atIndex:(NSInteger)index; + +- (void)didMoveToWindow; + +- (void)setNeedsLayout; +- (void)layoutIfNeeded; + +- (void)layoutSubviews; + +- (void)setNeedsDisplay; + +@property (nonatomic, copy) NSColor *backgroundColor; +@property (nonatomic) CGAffineTransform transform; + +/** + * Specifies whether the view should receive the mouse down event when the + * containing window is in the background. + */ +@property (nonatomic, assign) BOOL acceptsFirstMouse; + +@property (nonatomic, assign) BOOL mouseDownCanMoveWindow; + +/** + * Specifies whether the view participates in the key view loop as user tabs through different controls + * This is equivalent to acceptsFirstResponder on mac OS. + */ +@property (nonatomic, assign) BOOL focusable; +/** + * Specifies whether focus ring should be drawn when the view has the first responder status. + */ +@property (nonatomic, assign) BOOL enableFocusRing; + +// [macOS +/** + * iOS compatibility shim. On macOS, this forwards to accessibilityChildren. + */ +@property (nonatomic, copy) NSArray *accessibilityElements; +// macOS] + +@end + +// UIScrollView + +@class RCTUIScrollView; + +/** + * Protocol for objects that want to listen to scroll events on macOS. + * This mirrors the relevant parts of UIScrollViewDelegate for cross-platform compatibility. + */ +@protocol RCTUIScrollViewDelegate +@optional +- (void)scrollViewDidScroll:(RCTUIScrollView *)scrollView; +@end + +@interface RCTUIScrollView : NSScrollView + +// UIScrollView properties missing in NSScrollView +@property (nonatomic, assign) CGPoint contentOffset; +@property (nonatomic, assign) UIEdgeInsets contentInset; +@property (nonatomic, assign) CGSize contentSize; +@property (nonatomic, assign) BOOL showsHorizontalScrollIndicator; +@property (nonatomic, assign) BOOL showsVerticalScrollIndicator; +@property (nonatomic, assign) UIEdgeInsets scrollIndicatorInsets; +@property(nonatomic, assign) CGFloat minimumZoomScale; +@property(nonatomic, assign) CGFloat maximumZoomScale; +@property (nonatomic, assign) CGFloat zoomScale; +@property (nonatomic, assign) BOOL alwaysBounceHorizontal; +@property (nonatomic, assign) BOOL alwaysBounceVertical; +// macOS specific properties +@property (nonatomic, assign) BOOL enableFocusRing; +@property (nonatomic, assign, getter=isScrollEnabled) BOOL scrollEnabled; +@property (nonatomic, weak, nullable) id delegate; + +- (void)setContentOffset:(CGPoint)contentOffset animated:(BOOL)animated; + +@end + +@interface RCTClipView : NSClipView + +@property (nonatomic, assign) BOOL constrainScrolling; + +@end + + +NS_INLINE RCTPlatformView *RCTUIViewHitTestWithEvent(RCTPlatformView *view, CGPoint point, __unused UIEvent *__nullable event) +{ + // [macOS IMPORTANT -- point is in local coordinate space, but OSX expects super coordinate space for hitTest: + NSView *superview = [view superview]; + NSPoint pointInSuperview = superview != nil ? [view convertPoint:point toView:superview] : point; + return [view hitTest:pointInSuperview]; +} + +NS_INLINE void RCTUIViewSetContentModeRedraw(RCTPlatformView *view) +{ + view.layerContentsRedrawPolicy = NSViewLayerContentsRedrawDuringViewResize; +} + +NS_INLINE BOOL RCTUIViewIsDescendantOfView(RCTPlatformView *view, RCTPlatformView *parent) +{ + return [view isDescendantOf:parent]; +} + +NS_ASSUME_NONNULL_END + +#endif // ] TARGET_OS_OSX diff --git a/packages/react-native/React/RCTUIKit/RCTUIView.m b/packages/react-native/React/RCTUIKit/RCTUIView.m new file mode 100644 index 000000000000..bb9860b12b91 --- /dev/null +++ b/packages/react-native/React/RCTUIKit/RCTUIView.m @@ -0,0 +1,465 @@ +/** + * Copyright (c) 2015-present, Facebook, Inc. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + */ + +// [macOS] + +#if TARGET_OS_OSX + +#import + +// UIView + +@implementation RCTUIView +{ +@private + NSColor *_backgroundColor; + BOOL _clipsToBounds; + BOOL _userInteractionEnabled; + BOOL _mouseDownCanMoveWindow; + BOOL _respondsToDisplayLayer; +} + ++ (NSSet *)keyPathsForValuesAffectingValueForKey:(NSString *)key +{ + NSSet *keyPaths = [super keyPathsForValuesAffectingValueForKey:key]; + NSString *alternatePath = nil; + + // alpha is a wrapper for alphaValue + if ([key isEqualToString:@"alpha"]) { + alternatePath = @"alphaValue"; + // isAccessibilityElement is a wrapper for accessibilityElement + } else if ([key isEqualToString:@"isAccessibilityElement"]) { + alternatePath = @"accessibilityElement"; + } + + if (alternatePath != nil) { + keyPaths = keyPaths != nil ? [keyPaths setByAddingObject:alternatePath] : [NSSet setWithObject:alternatePath]; + } + + return keyPaths; +} + +static RCTUIView *RCTUIViewCommonInit(RCTUIView *self) +{ + if (self != nil) { + self.wantsLayer = YES; + self->_userInteractionEnabled = YES; + self->_enableFocusRing = YES; + self->_mouseDownCanMoveWindow = YES; + self->_respondsToDisplayLayer = [self respondsToSelector:@selector(displayLayer:)]; + } + return self; +} + +- (instancetype)initWithFrame:(NSRect)frameRect +{ + return RCTUIViewCommonInit([super initWithFrame:frameRect]); +} + +- (instancetype)initWithCoder:(NSCoder *)coder +{ + return RCTUIViewCommonInit([super initWithCoder:coder]); +} + +- (BOOL)acceptsFirstMouse:(NSEvent *)event +{ + if (self.acceptsFirstMouse || [super acceptsFirstMouse:event]) { + return YES; + } + + // If any RCTUIView view above has acceptsFirstMouse set, then return YES here. + NSView *view = self; + while ((view = view.superview)) { + if ([view isKindOfClass:[RCTUIView class]] && [(RCTUIView *)view acceptsFirstMouse]) { + return YES; + } + } + + return NO; +} + +- (BOOL)acceptsFirstResponder +{ + return [self canBecomeFirstResponder]; +} + +- (BOOL)isFirstResponder { + return [[self window] firstResponder] == self; +} + +- (void)viewDidMoveToWindow +{ + [self didMoveToWindow]; +} + +- (BOOL)mouseDownCanMoveWindow{ + return _mouseDownCanMoveWindow; +} + +- (void)setMouseDownCanMoveWindow:(BOOL)mouseDownCanMoveWindow{ + _mouseDownCanMoveWindow = mouseDownCanMoveWindow; +} + +- (BOOL)isFlipped +{ + return YES; +} + +- (CGFloat)alpha +{ + return self.alphaValue; +} + +- (void)setAlpha:(CGFloat)alpha +{ + self.alphaValue = alpha; +} + + +- (CGAffineTransform)transform +{ + return self.layer.affineTransform; +} + +- (void)setTransform:(CGAffineTransform)transform +{ + self.layer.affineTransform = transform; +} + +- (NSView *)hitTest:(NSPoint)point +{ + // IMPORTANT point is passed in super coordinates by OSX, but expected to be passed in local coordinates + NSView *superview = [self superview]; + NSPoint pointInSelf = superview != nil ? [self convertPoint:point fromView:superview] : point; + return [self hitTest:pointInSelf withEvent:nil]; +} + +- (BOOL)wantsUpdateLayer +{ + return [self respondsToSelector:@selector(displayLayer:)]; +} + +- (void)updateLayer +{ + CALayer *layer = [self layer]; + if (_backgroundColor) { + // updateLayer will be called when the view's current appearance changes. + // The layer's backgroundColor is a CGColor which is not appearance aware + // so it has to be reset from the view's NSColor ivar. + [layer setBackgroundColor:[_backgroundColor CGColor]]; + } + + // In Fabric, wantsUpdateLayer is always enabled and doesn't guarantee that + // the instance has a displayLayer method. + if (_respondsToDisplayLayer) { + [(id)self displayLayer:layer]; + } +} + +- (void)drawRect:(CGRect)rect +{ + if (_backgroundColor) { + [_backgroundColor set]; + NSRectFill(rect); + } + [super drawRect:rect]; +} + +- (void)layout +{ + [super layout]; + if (self.window != nil) { + [self layoutSubviews]; + } +} + +- (BOOL)canBecomeFirstResponder +{ + return [super acceptsFirstResponder]; +} + +- (BOOL)becomeFirstResponder +{ + return [[self window] makeFirstResponder:self]; +} + +@synthesize userInteractionEnabled = _userInteractionEnabled; + +- (NSArray *)accessibilityElements +{ + return self.accessibilityChildren; +} + +- (void)setAccessibilityElements:(NSArray *)accessibilityElements +{ + self.accessibilityChildren = accessibilityElements; +} + +- (NSView *)hitTest:(CGPoint)point withEvent:(__unused UIEvent *)event +{ +// [macOS + // IMPORTANT point is expected to be passed in local coordinates, but OSX expects point to be super + NSView *superview = [self superview]; + NSPoint pointInSuperview = superview != nil ? [self convertPoint:point toView:superview] : point; + return self.userInteractionEnabled ? [super hitTest:pointInSuperview] : nil; +} + +- (BOOL)pointInside:(CGPoint)point withEvent:(__unused UIEvent *)event +{ + return self.userInteractionEnabled ? NSPointInRect(NSPointFromCGPoint(point), self.bounds) : NO; +} + +- (void)insertSubview:(NSView *)view atIndex:(NSInteger)index +{ + NSArray<__kindof NSView *> *subviews = self.subviews; + if ((NSUInteger)index == subviews.count) { + [self addSubview:view]; + } else { + [self addSubview:view positioned:NSWindowBelow relativeTo:subviews[index]]; + } +} + +- (void)didMoveToWindow +{ + [super viewDidMoveToWindow]; +} + +- (void)setNeedsLayout +{ + self.needsLayout = YES; +} + +- (void)layoutIfNeeded +{ + if ([self needsLayout]) { + [self layout]; + } +} + +- (void)layoutSubviews +{ + [super layout]; +} + +- (void)setNeedsDisplay +{ + self.needsDisplay = YES; +} + +@synthesize clipsToBounds = _clipsToBounds; + +@synthesize backgroundColor = _backgroundColor; + +- (void)setBackgroundColor:(NSColor *)backgroundColor +{ + if (_backgroundColor != backgroundColor && ![_backgroundColor isEqual:backgroundColor]) + { + _backgroundColor = [backgroundColor copy]; + [self setNeedsDisplay:YES]; + } +} + +// We purposely don't use RCTCursor for the parameter type here because it would introduce an import cycle: +// RCTUIKit > RCTCursor > RCTConvert > RCTUIKit +- (void)setCursor:(NSInteger)cursor +{ + // This method is required to be defined due to [RCTVirtualTextViewManager view] returning a RCTUIView. +} + +@end + +// RCTUIScrollView + +@implementation RCTUIScrollView + +- (instancetype)initWithFrame:(CGRect)frame +{ + if (self = [super initWithFrame:frame]) { + self.scrollEnabled = YES; + self.drawsBackground = NO; + self.contentView.postsBoundsChangedNotifications = YES; + [[NSNotificationCenter defaultCenter] addObserver:self + selector:@selector(_rctuiHandleBoundsDidChange:) + name:NSViewBoundsDidChangeNotification + object:self.contentView]; + } + + return self; +} + +- (void)_rctuiHandleBoundsDidChange:(NSNotification *)notification +{ + if ([_delegate respondsToSelector:@selector(scrollViewDidScroll:)]) { + [_delegate scrollViewDidScroll:self]; + } +} + +- (void)setEnableFocusRing:(BOOL)enableFocusRing { + if (_enableFocusRing != enableFocusRing) { + _enableFocusRing = enableFocusRing; + } + + if (enableFocusRing) { + // NSTextView has no focus ring by default so let's use the standard Aqua focus ring. + [self setFocusRingType:NSFocusRingTypeExterior]; + } else { + [self setFocusRingType:NSFocusRingTypeNone]; + } +} + +// UIScrollView properties missing from NSScrollView +- (CGPoint)contentOffset +{ + return self.documentVisibleRect.origin; +} + +- (void)setContentOffset:(CGPoint)contentOffset +{ + [self.documentView scrollPoint:contentOffset]; +} + +- (void)setContentOffset:(CGPoint)contentOffset animated:(BOOL)animated +{ + if (animated) { + [NSAnimationContext runAnimationGroup:^(NSAnimationContext *context) { + context.duration = 0.3; // Set the duration of the animation + [self.documentView.animator scrollPoint:contentOffset]; + } completionHandler:nil]; + } else { + [self.documentView scrollPoint:contentOffset]; + } +} + +- (UIEdgeInsets)contentInset +{ + return super.contentInsets; +} + +- (void)setContentInset:(UIEdgeInsets)insets +{ + super.contentInsets = insets; +} + +- (CGSize)contentSize +{ + return self.documentView.frame.size; +} + +- (void)setContentSize:(CGSize)contentSize +{ + CGRect frame = self.documentView.frame; + frame.size = contentSize; + self.documentView.frame = frame; +} + +- (BOOL)showsHorizontalScrollIndicator +{ + return self.hasHorizontalScroller; +} + +- (void)setShowsHorizontalScrollIndicator:(BOOL)show +{ + self.hasHorizontalScroller = show; +} + +- (BOOL)showsVerticalScrollIndicator +{ + return self.hasVerticalScroller; +} + +- (void)setShowsVerticalScrollIndicator:(BOOL)show +{ + self.hasVerticalScroller = show; +} + +- (UIEdgeInsets)scrollIndicatorInsets +{ + return self.scrollerInsets; +} + +- (void)setScrollIndicatorInsets:(UIEdgeInsets)insets +{ + self.scrollerInsets = insets; +} + +- (CGFloat)zoomScale +{ + return self.magnification; +} + +- (void)setZoomScale:(CGFloat)zoomScale +{ + self.magnification = zoomScale; +} + +- (CGFloat)maximumZoomScale +{ + return self.maxMagnification; +} + +- (void)setMaximumZoomScale:(CGFloat)maximumZoomScale +{ + self.maxMagnification = maximumZoomScale; +} + +- (CGFloat)minimumZoomScale +{ + return self.minMagnification; +} + +- (void)setMinimumZoomScale:(CGFloat)minimumZoomScale +{ + self.minMagnification = minimumZoomScale; +} + + +- (BOOL)alwaysBounceHorizontal +{ + return self.horizontalScrollElasticity != NSScrollElasticityNone; +} + +- (void)setAlwaysBounceHorizontal:(BOOL)alwaysBounceHorizontal +{ + self.horizontalScrollElasticity = alwaysBounceHorizontal ? NSScrollElasticityAllowed : NSScrollElasticityNone; +} + +- (BOOL)alwaysBounceVertical +{ + return self.verticalScrollElasticity != NSScrollElasticityNone; +} + +- (void)setAlwaysBounceVertical:(BOOL)alwaysBounceVertical +{ + self.verticalScrollElasticity = alwaysBounceVertical ? NSScrollElasticityAllowed : NSScrollElasticityNone; +} + +@end + +@implementation RCTClipView + +- (instancetype)initWithFrame:(NSRect)frameRect +{ + if (self = [super initWithFrame:frameRect]) { + self.constrainScrolling = NO; + self.drawsBackground = NO; + } + + return self; +} + +- (NSRect)constrainBoundsRect:(NSRect)proposedBounds +{ + if (self.constrainScrolling) { + return NSMakeRect(0, 0, 0, 0); + } + + return [super constrainBoundsRect:proposedBounds]; +} + +@end + +#endif diff --git a/packages/react-native/scripts/react_native_pods.rb b/packages/react-native/scripts/react_native_pods.rb index bc2f4c5a50f2..ca9a677645e3 100644 --- a/packages/react-native/scripts/react_native_pods.rb +++ b/packages/react-native/scripts/react_native_pods.rb @@ -132,6 +132,7 @@ def use_react_native! ( if !ReactNativeCoreUtils.build_rncore_from_source() pod 'React-Core-prebuilt', :podspec => "#{prefix}/React-Core-prebuilt.podspec", :modular_headers => true end + pod 'React-RCTUIKit', :path => "#{prefix}/" pod 'React-Core', :path => "#{prefix}/" pod 'React-CoreModules', :path => "#{prefix}/React/CoreModules" pod 'React-RCTRuntime', :path => "#{prefix}/React/Runtime" diff --git a/packages/rn-tester/Podfile.lock b/packages/rn-tester/Podfile.lock index b121f5cf05f9..76864ca7f2e5 100644 --- a/packages/rn-tester/Podfile.lock +++ b/packages/rn-tester/Podfile.lock @@ -160,6 +160,7 @@ PODS: - React-jsinspectorcdp - React-jsitooling - React-perflogger + - React-RCTUIKit - React-runtimeexecutor - React-runtimescheduler - React-utils @@ -185,6 +186,7 @@ PODS: - React-jsinspectorcdp - React-jsitooling - React-perflogger + - React-RCTUIKit - React-runtimeexecutor - React-runtimescheduler - React-utils @@ -209,6 +211,7 @@ PODS: - React-jsinspectorcdp - React-jsitooling - React-perflogger + - React-RCTUIKit - React-runtimeexecutor - React-runtimescheduler - React-utils @@ -235,6 +238,7 @@ PODS: - React-jsinspectorcdp - React-jsitooling - React-perflogger + - React-RCTUIKit - React-runtimeexecutor - React-runtimescheduler - React-utils @@ -260,6 +264,7 @@ PODS: - React-jsinspectorcdp - React-jsitooling - React-perflogger + - React-RCTUIKit - React-runtimeexecutor - React-runtimescheduler - React-utils @@ -285,6 +290,7 @@ PODS: - React-jsinspectorcdp - React-jsitooling - React-perflogger + - React-RCTUIKit - React-runtimeexecutor - React-runtimescheduler - React-utils @@ -310,6 +316,7 @@ PODS: - React-jsinspectorcdp - React-jsitooling - React-perflogger + - React-RCTUIKit - React-runtimeexecutor - React-runtimescheduler - React-utils @@ -335,6 +342,7 @@ PODS: - React-jsinspectorcdp - React-jsitooling - React-perflogger + - React-RCTUIKit - React-runtimeexecutor - React-runtimescheduler - React-utils @@ -360,6 +368,7 @@ PODS: - React-jsinspectorcdp - React-jsitooling - React-perflogger + - React-RCTUIKit - React-runtimeexecutor - React-runtimescheduler - React-utils @@ -385,6 +394,7 @@ PODS: - React-jsinspectorcdp - React-jsitooling - React-perflogger + - React-RCTUIKit - React-runtimeexecutor - React-runtimescheduler - React-utils @@ -410,6 +420,7 @@ PODS: - React-jsinspectorcdp - React-jsitooling - React-perflogger + - React-RCTUIKit - React-runtimeexecutor - React-runtimescheduler - React-utils @@ -435,6 +446,7 @@ PODS: - React-jsinspectorcdp - React-jsitooling - React-perflogger + - React-RCTUIKit - React-runtimeexecutor - React-runtimescheduler - React-utils @@ -460,6 +472,7 @@ PODS: - React-jsinspectorcdp - React-jsitooling - React-perflogger + - React-RCTUIKit - React-runtimeexecutor - React-runtimescheduler - React-utils @@ -485,6 +498,7 @@ PODS: - React-jsinspectorcdp - React-jsitooling - React-perflogger + - React-RCTUIKit - React-runtimeexecutor - React-runtimescheduler - React-utils @@ -510,6 +524,7 @@ PODS: - React-jsinspectorcdp - React-jsitooling - React-perflogger + - React-RCTUIKit - React-runtimeexecutor - React-runtimescheduler - React-utils @@ -2126,6 +2141,7 @@ PODS: - React-RCTText (1000.0.0): - React-Core/RCTTextHeaders (= 1000.0.0) - Yoga + - React-RCTUIKit (1000.0.0) - React-RCTVibration (1000.0.0): - boost - DoubleConversion @@ -2473,6 +2489,7 @@ DEPENDENCIES: - React-RCTSettings (from `../react-native/Libraries/Settings`) - React-RCTTest (from `./RCTTest`) - React-RCTText (from `../react-native/Libraries/Text`) + - React-RCTUIKit (from `../react-native/`) - React-RCTVibration (from `../react-native/Libraries/Vibration`) - React-rendererconsistency (from `../react-native/ReactCommon/react/renderer/consistency`) - React-renderercss (from `../react-native/ReactCommon/react/renderer/css`) @@ -2621,6 +2638,8 @@ EXTERNAL SOURCES: :path: "./RCTTest" React-RCTText: :path: "../react-native/Libraries/Text" + React-RCTUIKit: + :path: "../react-native/" React-RCTVibration: :path: "../react-native/Libraries/Vibration" React-rendererconsistency: @@ -2660,7 +2679,7 @@ SPEC CHECKSUMS: boost: cea1d4f90a3a59537f3deb03ff5656489d7133dd DoubleConversion: d31b1eb37f6d6f456530c4fd9124b857d6889cab fast_float: 20817c22759af6ac8d4d67e6e059b8b499953656 - FBLazyVector: ff8d586687e981f0959b565e4e2af315f59242a4 + FBLazyVector: c7b890b69ef2a6065ac451cab027e93f4f964892 fmt: 24e7591456deb60b4a77518f83d9a916ac84223f glog: 0b31c25149b9d350b2666c7d459229861a00ec07 hermes-engine: 6685af7f27b851cd7fa2675bdeef4b291383b2fc @@ -2670,73 +2689,74 @@ SPEC CHECKSUMS: OSSLibraryExample: 5105eecb9aa325c0d65c59023fd8dc5f5753e777 RCT-Folly: c803cf33238782d5fd21a5e02d44f64068e0e130 RCTDeprecation: 3808e36294137f9ee5668f4df2e73dc079cd1dcf - RCTRequired: fcf4fca7673f720813bb4b8618a3d0a28b5eac9c - RCTTypeSafety: 9eded7b70d225a214480cb71d79eb8653d66c0fa - React: e74be670a7c0ee983ac53ae3dc0c37ef5403d90b - React-callinvoker: f210fd7bb4d2d45b9b7631301d8716d13c1ca662 - React-Core: 524869337c6f7ffac9e04e738a77aecf7ecd8d46 - React-CoreModules: c2d86e0aff17ed129bfdd1e138a2afce77be24b4 - React-cxxreact: 64d4e59292e72cded6099e1d679db6d2cfa07320 - React-debug: 1234d144cceec92fb6f9942c17be53d04f96d240 - React-defaultsnativemodule: 810a0cefffcd61d9b6f009cc43824e703d6bda0b - React-domnativemodule: 5d6a71d43d0d0faf62ea8dde5afdc0ef13fd363d - React-Fabric: a4cf10caf19446ff997a65c36e8f4b3d34117af7 - React-FabricComponents: 50a68026db84967d42949458731785c431cc3dc5 - React-FabricImage: f057df19142e16a44c7d192206c5e196625fd639 - React-featureflags: dc6334be05bfbd48c9914e080c7f7b256bd9eba2 - React-featureflagsnativemodule: 382af100918d5ff4ee9a0c3201350d5a55de2e4b - React-graphics: 8e7cb680d1cb1f394fa18d3b9ed2e29ddc8b24dd - React-hermes: 5182b1999cb84d8253901bd32d8a84a196c82172 - React-idlecallbacksnativemodule: dfe8d534df6bf821877bb46be8a4962758bef2b8 - React-ImageManager: 6eb19a37bd3ecb875dd81d3edeba3b414c49950f - React-jserrorhandler: d65e7e02c88f63e5d9efa2de3cdc27fca6199c4c - React-jsi: 67f127b513bc617dfdf9d8cc63cefae70201b970 - React-jsiexecutor: c1f53b9e2a458d46cf92970dff9b9c3581539702 - React-jsinspector: 29d8b4c3c282beb8694d6e725b19e4f8d1397d28 - React-jsinspectorcdp: 11815d4554ddc9b9d5b4b238d6145e4d18bcf62f - React-jsinspectornetwork: 49e87294bd06807cdbe9f5967af07ddd9f416170 - React-jsinspectortracing: d8e3e5c8ab6853a9fe396f73019009c5c70c3ae4 - React-jsitooling: 3f946dc1482e0a019413de4c3150dcaa24d5811c - React-jsitracing: ef2d6d9c920e926fba10aa06f681c8b4535181a4 - React-logger: 71b74db29a4e888a4b9c3ad7152efb172c622068 - React-Mapbuffer: 8de7c095c9433e672a42f5c68357ce11ae4d5766 - React-microtasksnativemodule: e58c566e1be78842c0cf8cc998f4434d6500a97b - React-NativeModulesApple: 628dd217d2c80f85679b486a308bf569d7de34cb - React-oscompat: 9950d69cca9677eb4e3ff3f0f95f24088fdd2e5d - React-perflogger: 8d3c3cf9c5c592ee00e0419d1ed3c15de2aea96e - React-performancetimeline: 9ddd20862e20e706ff113a0a8fb46a264173cd69 - React-RCTActionSheet: 7a38b584fe58cab8e552b3b2b5addeb792311af1 - React-RCTAnimation: 08e46cf2c824bd9ac8ce341b97ab448d86c58ba7 - React-RCTAppDelegate: 759ec38ba00ca3686f55b5751e3af053ab3b251e - React-RCTBlob: 447e14b45aac53d30cc6bf2fa4af3c626483502b - React-RCTFabric: 4582f88ac2f20866c87050b643aef4bc79c67194 - React-RCTFBReactNativeSpec: 91ad88d697431c1ef99b6a065620d7a70734a946 - React-RCTImage: f5f7d61ee772f39935809de505c053a2c7a40e9e - React-RCTLinking: 4537d2fa4ee192dcac8549eaacd782452bb2daa7 - React-RCTNetwork: 3dee683420da03f436849e4f863bf134d70bb906 - React-RCTPushNotification: e5bbe843b37442db010895112be6334e111d6761 - React-RCTRuntime: 406357f56462cbc9fa33716b577d489da9227588 - React-RCTSettings: 738283bbe0de1088ea72d51a8e69563ad2acac34 - React-RCTTest: 6232880a06e85f8fb0117e2ea12081655da39c5d - React-RCTText: 5f58a449ca9cd96ec73befa95ab8bc04369e6c9f - React-RCTVibration: 39997ef5ae0ec8c93263519ef306bb3bd324e385 - React-rendererconsistency: 59fe0d561f5b5fdc8efa7a5014068d434ede4761 - React-renderercss: e58750a2b9988d18e8fc59b8953bc9fe96dc7b70 - React-rendererdebug: 879c8bbef67e96fc5dec1f0ded6ae75bad39d1f8 - React-RuntimeApple: ab5176231f8e1493b9bfbd209be92b7dd2de0832 - React-RuntimeCore: 2e6d98af5b1d4b0f5ac360fa27c036f2e0a955cf - React-runtimeexecutor: c5043ba8e3bfaecfb3b2e9bedd635c51935ba1fd - React-RuntimeHermes: f0d557e216d6349ff88ecc9f152ee984ae3039ba - React-runtimescheduler: 2b5c3caa8c71dbb1f3c2efd21dad423d42e73fd2 - React-timing: adbe50b48108d12013ed32bf269dc108a855c1d7 - React-utils: 6095fe443bd42cb02dd550310a7885271d036c30 - ReactAppDependencyProvider: 9df6086e37c9491dfa8ff748762260e5020388a0 + RCTRequired: 274607329cc254e14b6a28c903bb747402c05418 + RCTTypeSafety: d4a386d20765a33b1d8c4ddfc861ab15c80e6cf4 + React: 930f249eefcdcf5609086bd26c7e2e857b3cc4fa + React-callinvoker: da114f59edc0e6441a7c95802d445afa3454ceaf + React-Core: 419883322b1eacc0f0ff45a24203595a6b555504 + React-CoreModules: 2e5a68cc2a87e52e22ba4b9f57e4f97e49bd2ee2 + React-cxxreact: 984a2a3c5dd651579b4eb2ffa505baef206a282e + React-debug: 8bf9abebb537a63a8efc3f98186bfcc43615185c + React-defaultsnativemodule: 1e26faca5d859402ff4bbee82078c120faba6b8b + React-domnativemodule: 7ae3e9eea7f8eb39076f3a7ee7b9fa967afa563f + React-Fabric: e25594c4fd8dd18d97e26c6228ada963de08af72 + React-FabricComponents: 9f3955018e9e2425f2e35e957c4de6ed0eaf119b + React-FabricImage: badef29e8895701cfea55bf2beae00f3b2d069b2 + React-featureflags: 447be21640968c4bfbaeb0a902138304c595b7be + React-featureflagsnativemodule: dceeba1e8c8f162703d5fba665279499c5903f0e + React-graphics: 164c63f8603efe5e767af3665d53ccd76ec3b474 + React-hermes: 5da2abe39df0ab30d73f7bd0530da12a6eba2829 + React-idlecallbacksnativemodule: 863a4ea807d1bce7019d4dffb055f478e437a148 + React-ImageManager: af4528fea06482f7e44f467766280718ddbf6138 + React-jserrorhandler: 6855b88718ebcce68a66916cc9b3b197921842d6 + React-jsi: 4a49a45141f4626ba8018d0f3377d3d625d6aa11 + React-jsiexecutor: 2b2255a76b3f991946f8ce04e65cfabb94a24e3e + React-jsinspector: 2cc1c746a948f3364fed67261e308f41bca63547 + React-jsinspectorcdp: 74d038bcf91fca8abe61535b90d19b1ed179a953 + React-jsinspectornetwork: a2ab0071fc0907970193993e4e10962f8943b7fd + React-jsinspectortracing: 370624ea83f1524a05eb08f8386ed1d15e0ac315 + React-jsitooling: b5e53dffcae2fa956a77a5b503e6b4e02992181f + React-jsitracing: 43a1bb48e7d68e279549f9c93d39ff4b3fe33478 + React-logger: d506ef13cb4522a4b4cce06edb0e0ac98041b4fc + React-Mapbuffer: 0a178e6cbb22d093e5810b1cbb64c6c5a9dda84d + React-microtasksnativemodule: 861156de53f81e4d5c1a7a0def769765bcec90b7 + React-NativeModulesApple: 84c44036eeb6b6ad2985024886a4ee53b2d1dcaa + React-oscompat: 954d8b5b7855347362c3007d7311998292623a69 + React-perflogger: 5a32fd56cc69391180a9ec9c6fd678c339a77f24 + React-performancetimeline: 55eed1a5c6c6147462b6d3c3693db3297320c1e3 + React-RCTActionSheet: 0ccbcf7137d0f6738edb2271e0a502f14f8e88c1 + React-RCTAnimation: e80e504c0437370c74e12a6f61d0f706db85c307 + React-RCTAppDelegate: 4b7ec615378f00ee56bcae9d38549cc964ceed50 + React-RCTBlob: 62ca5e2309a7bc445b9b1dcf1383e8b0ad82104d + React-RCTFabric: a624e48cd887844fcf2cc910f31c6547d6364cf2 + React-RCTFBReactNativeSpec: 9713a2d5d1b22dd14bd0a3c089b7a4aec75671de + React-RCTImage: c64f6af45cf3c6e7341bae261b6490de865e4e70 + React-RCTLinking: a2d4676b5cc2c95df571df9618b76dee3c8ec79b + React-RCTNetwork: a913abd5a0fcbf1cf5f26137c11878931cd3e703 + React-RCTPushNotification: ce6a29d6a5714ba9420d506ccb9f4dbf58a6b739 + React-RCTRuntime: 80e5be9066f7ba85bd55097f15ffb61e8c5a9084 + React-RCTSettings: 1ad5132a6e70f0b81ba63b7b0717d0e07e588e34 + React-RCTTest: 5aaca2f430f931405e2de224b1e096cdb648a89a + React-RCTText: 45007a59bedde49b886e322965454aaab363c3d2 + React-RCTUIKit: e343b3a6bc0c03a1b1c6a056d6af0263128144dc + React-RCTVibration: fc6016098fd6f0ac16747a1bd3f644d715a424e4 + React-rendererconsistency: 8239dde9dd4ed1aae5ef1aec2c90bc805372d6d8 + React-renderercss: 97670a37f6d8d13ca5fc8741b0413e3c60d6a6c4 + React-rendererdebug: d951ca359c96f0257957ae4025d11ed497698f75 + React-RuntimeApple: a1099c7312bdc18c0dc8eb5a40ed7dff2a07dee1 + React-RuntimeCore: 349443a05f6813855472782c6b55df85cd84e555 + React-runtimeexecutor: 011c263b2c28caf33e81c64f35be1b22d02c2d92 + React-RuntimeHermes: 7b75f16a1250fdae2872451d1f51e53b2e0bf207 + React-runtimescheduler: 2a1123cf29212016edd37c4963f3b07bb6add017 + React-timing: eaa51caa267b03cd485ab6862e873ccb541d0790 + React-utils: c8041e8f8c55d1522e452529beec18940e4e6c47 + ReactAppDependencyProvider: 7b3b301e8c0525b6c87250dcbbccf58757e05666 ReactCodegen: 45d2e543e9f1958ea9cf32b87ffa06b550db3683 - ReactCommon: f76cf81b04e39bc559008ed681f067dd31cd05ab - ReactCommon-Samples: 70f2dba45c645bde7c46bb8ecd1ac89e17b9347b + ReactCommon: 63e15f5c2bd41af08fcad4acdc3728e184478c9e + ReactCommon-Samples: 733c5cc2f9bc6d5c93a7da4d8f854ebca31621b5 ScreenshotManager: 10713952cbe264b56dfd36670e881ddd028daef5 SocketRocket: d4aabe649be1e368d1318fdf28a022d714d65748 - Yoga: bbcfacbda6772a0b33772997bc9dc9f377867e7e + Yoga: cdd92b67325602211751bf8eb90aeb56cf9d80e2 PODFILE CHECKSUM: 86f155f7e9c92081bc7cd14b59aa0c1774a88f73 From 9efdeb28465c0bfe6966a7ddb5747fe7c018909f Mon Sep 17 00:00:00 2001 From: Saad Najmi Date: Mon, 9 Mar 2026 12:54:16 -0700 Subject: [PATCH 2/6] refactor: split controls into individual files --- .../RCTUIKit/RCTUIActivityIndicatorView.h | 31 +++ .../RCTUIKit/RCTUIActivityIndicatorView.m | 125 +++++++++ .../React/RCTUIKit/RCTUIControls.h | 115 -------- .../React/RCTUIKit/RCTUIControls.m | 263 ------------------ .../React/RCTUIKit/RCTUIImageView.h | 25 ++ .../React/RCTUIKit/RCTUIImageView.m | 96 +++++++ .../react-native/React/RCTUIKit/RCTUIKit.h | 8 +- .../react-native/React/RCTUIKit/RCTUILabel.h | 26 ++ .../react-native/React/RCTUIKit/RCTUILabel.m | 36 +++ .../React/RCTUIKit/RCTUIScrollView.h | 68 +++++ .../React/RCTUIKit/RCTUIScrollView.m | 204 ++++++++++++++ .../react-native/React/RCTUIKit/RCTUISlider.h | 43 +++ .../react-native/React/RCTUIKit/RCTUISlider.m | 23 ++ .../react-native/React/RCTUIKit/RCTUISwitch.h | 27 ++ .../react-native/React/RCTUIKit/RCTUISwitch.m | 32 +++ .../react-native/React/RCTUIKit/RCTUITouch.h | 21 ++ .../react-native/React/RCTUIKit/RCTUIView.h | 42 --- .../react-native/React/RCTUIKit/RCTUIView.m | 190 ------------- packages/rn-tester/Podfile.lock | 132 ++++----- 19 files changed, 830 insertions(+), 677 deletions(-) create mode 100644 packages/react-native/React/RCTUIKit/RCTUIActivityIndicatorView.h create mode 100644 packages/react-native/React/RCTUIKit/RCTUIActivityIndicatorView.m delete mode 100644 packages/react-native/React/RCTUIKit/RCTUIControls.h delete mode 100644 packages/react-native/React/RCTUIKit/RCTUIControls.m create mode 100644 packages/react-native/React/RCTUIKit/RCTUIImageView.h create mode 100644 packages/react-native/React/RCTUIKit/RCTUIImageView.m create mode 100644 packages/react-native/React/RCTUIKit/RCTUILabel.h create mode 100644 packages/react-native/React/RCTUIKit/RCTUILabel.m create mode 100644 packages/react-native/React/RCTUIKit/RCTUIScrollView.h create mode 100644 packages/react-native/React/RCTUIKit/RCTUIScrollView.m create mode 100644 packages/react-native/React/RCTUIKit/RCTUISlider.h create mode 100644 packages/react-native/React/RCTUIKit/RCTUISlider.m create mode 100644 packages/react-native/React/RCTUIKit/RCTUISwitch.h create mode 100644 packages/react-native/React/RCTUIKit/RCTUISwitch.m create mode 100644 packages/react-native/React/RCTUIKit/RCTUITouch.h diff --git a/packages/react-native/React/RCTUIKit/RCTUIActivityIndicatorView.h b/packages/react-native/React/RCTUIKit/RCTUIActivityIndicatorView.h new file mode 100644 index 000000000000..04fb7051e392 --- /dev/null +++ b/packages/react-native/React/RCTUIKit/RCTUIActivityIndicatorView.h @@ -0,0 +1,31 @@ +/* + * Copyright (c) Meta Platforms, Inc. and affiliates. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + */ + +// [macOS] + +#pragma once + +#include + +#import + +#if !TARGET_OS_OSX +typedef UIActivityIndicatorView RCTUIActivityIndicatorView; +#else +@interface RCTUIActivityIndicatorView : NSProgressIndicator +NS_ASSUME_NONNULL_BEGIN +@property (nonatomic, assign) UIActivityIndicatorViewStyle activityIndicatorViewStyle; +@property (nonatomic, assign) BOOL hidesWhenStopped; +@property (nullable, readwrite, nonatomic, strong) RCTUIColor *color; +@property (nonatomic, readonly, getter=isAnimating) BOOL animating; + +- (void)startAnimating; +- (void)stopAnimating; +NS_ASSUME_NONNULL_END +@end + +#endif diff --git a/packages/react-native/React/RCTUIKit/RCTUIActivityIndicatorView.m b/packages/react-native/React/RCTUIKit/RCTUIActivityIndicatorView.m new file mode 100644 index 000000000000..1568469253e8 --- /dev/null +++ b/packages/react-native/React/RCTUIKit/RCTUIActivityIndicatorView.m @@ -0,0 +1,125 @@ +/** + * Copyright (c) 2015-present, Facebook, Inc. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + */ + +// [macOS] + +#if TARGET_OS_OSX + +#import + +#import +#import + +@interface RCTUIActivityIndicatorView () +@property (nonatomic, readwrite, getter=isAnimating) BOOL animating; +@end + +@implementation RCTUIActivityIndicatorView {} + +- (instancetype)initWithFrame:(CGRect)frame +{ + if ((self = [super initWithFrame:frame])) { + self.displayedWhenStopped = NO; + self.style = NSProgressIndicatorStyleSpinning; + } + return self; +} + +- (void)startAnimating +{ + // `wantsLayer` gets reset after the animation is stopped. We have to + // reset it in order for CALayer filters to take effect. + [self setWantsLayer:YES]; + [self startAnimation:self]; +} + +- (void)stopAnimating +{ + [self stopAnimation:self]; +} + +- (void)startAnimation:(id)sender +{ + [super startAnimation:sender]; + self.animating = YES; +} + +- (void)stopAnimation:(id)sender +{ + [super stopAnimation:sender]; + self.animating = NO; +} + +- (void)setActivityIndicatorViewStyle:(UIActivityIndicatorViewStyle)activityIndicatorViewStyle +{ + _activityIndicatorViewStyle = activityIndicatorViewStyle; + + switch (activityIndicatorViewStyle) { + case UIActivityIndicatorViewStyleLarge: + self.controlSize = NSControlSizeLarge; + break; + case UIActivityIndicatorViewStyleMedium: + self.controlSize = NSControlSizeRegular; + break; + default: + break; + } +} + +- (void)setColor:(RCTUIColor*)color +{ + if (_color != color) { + _color = color; + [self setNeedsDisplay:YES]; + } +} + +- (void)updateLayer +{ + [super updateLayer]; + if (_color != nil) { + CGFloat r, g, b, a; + [[_color colorUsingColorSpace:[NSColorSpace genericRGBColorSpace]] getRed:&r green:&g blue:&b alpha:&a]; + + CIFilter *colorPoly = [CIFilter filterWithName:@"CIColorPolynomial"]; + [colorPoly setDefaults]; + + CIVector *redVector = [CIVector vectorWithX:r Y:0 Z:0 W:0]; + CIVector *greenVector = [CIVector vectorWithX:g Y:0 Z:0 W:0]; + CIVector *blueVector = [CIVector vectorWithX:b Y:0 Z:0 W:0]; + [colorPoly setValue:redVector forKey:@"inputRedCoefficients"]; + [colorPoly setValue:greenVector forKey:@"inputGreenCoefficients"]; + [colorPoly setValue:blueVector forKey:@"inputBlueCoefficients"]; + + [[self layer] setFilters:@[colorPoly]]; + } else { + [[self layer] setFilters:nil]; + } +} + +- (void)setHidesWhenStopped:(BOOL)hidesWhenStopped +{ + self.displayedWhenStopped = !hidesWhenStopped; +} + +- (BOOL)hidesWhenStopped +{ + return !self.displayedWhenStopped; +} + +- (void)setHidden:(BOOL)hidden +{ + if ([self hidesWhenStopped] && ![self isAnimating]) { + [super setHidden:YES]; + } else { + [super setHidden:hidden]; + } +} + +@end + +#endif diff --git a/packages/react-native/React/RCTUIKit/RCTUIControls.h b/packages/react-native/React/RCTUIKit/RCTUIControls.h deleted file mode 100644 index 06818527d92a..000000000000 --- a/packages/react-native/React/RCTUIKit/RCTUIControls.h +++ /dev/null @@ -1,115 +0,0 @@ -/* - * Copyright (c) Meta Platforms, Inc. and affiliates. - * - * This source code is licensed under the MIT license found in the - * LICENSE file in the root directory of this source tree. - */ - -// [macOS] - -#pragma once - -#include - -#import - -// RCTUISlider - -#if !TARGET_OS_OSX -typedef UISlider RCTUISlider; -#else -@protocol RCTUISliderDelegate; - -@interface RCTUISlider : NSSlider -NS_ASSUME_NONNULL_BEGIN -@property (nonatomic, weak) id delegate; -@property (nonatomic, readonly) BOOL pressed; -@property (nonatomic, assign) float value; -@property (nonatomic, assign) float minimumValue; -@property (nonatomic, assign) float maximumValue; -@property (nonatomic, strong) NSColor *minimumTrackTintColor; -@property (nonatomic, strong) NSColor *maximumTrackTintColor; - -- (void)setValue:(float)value animated:(BOOL)animated; -NS_ASSUME_NONNULL_END -@end -#endif - -#if TARGET_OS_OSX // [macOS -@protocol RCTUISliderDelegate -@optional -NS_ASSUME_NONNULL_BEGIN -- (void)slider:(RCTUISlider *)slider didPress:(BOOL)press; -NS_ASSUME_NONNULL_END -@end -#endif // macOS] - -// RCTUILabel - -#if !TARGET_OS_OSX -typedef UILabel RCTUILabel; -#else -@interface RCTUILabel : NSTextField -NS_ASSUME_NONNULL_BEGIN -@property(nonatomic, copy) NSString* _Nullable text; -@property(nonatomic, assign) NSInteger numberOfLines; -@property(nonatomic, assign) NSTextAlignment textAlignment; -NS_ASSUME_NONNULL_END -@end -#endif - -// RCTUISwitch - -#if !TARGET_OS_OSX -typedef UISwitch RCTUISwitch; -#else -@interface RCTUISwitch : NSSwitch -NS_ASSUME_NONNULL_BEGIN -@property (nonatomic, getter=isOn) BOOL on; - -- (void)setOn:(BOOL)on animated:(BOOL)animated; - -NS_ASSUME_NONNULL_END -@end -#endif - -// RCTUIActivityIndicatorView - -#if !TARGET_OS_OSX -typedef UIActivityIndicatorView RCTUIActivityIndicatorView; -#else -@interface RCTUIActivityIndicatorView : NSProgressIndicator -NS_ASSUME_NONNULL_BEGIN -@property (nonatomic, assign) UIActivityIndicatorViewStyle activityIndicatorViewStyle; -@property (nonatomic, assign) BOOL hidesWhenStopped; -@property (nullable, readwrite, nonatomic, strong) RCTUIColor *color; -@property (nonatomic, readonly, getter=isAnimating) BOOL animating; - -- (void)startAnimating; -- (void)stopAnimating; -NS_ASSUME_NONNULL_END -@end - -#endif - -// RCTUITouch - -#if !TARGET_OS_OSX -typedef UITouch RCTUITouch; -#else -@interface RCTUITouch : NSEvent -@end -#endif - -// RCTUIImageView - -#if !TARGET_OS_OSX -typedef UIImageView RCTUIImageView; -#else -@interface RCTUIImageView : NSImageView -NS_ASSUME_NONNULL_BEGIN -@property (nonatomic, strong) RCTUIColor *tintColor; -@property (nonatomic, assign) UIViewContentMode contentMode; -NS_ASSUME_NONNULL_END -@end -#endif diff --git a/packages/react-native/React/RCTUIKit/RCTUIControls.m b/packages/react-native/React/RCTUIKit/RCTUIControls.m deleted file mode 100644 index b9f107bc8e4b..000000000000 --- a/packages/react-native/React/RCTUIKit/RCTUIControls.m +++ /dev/null @@ -1,263 +0,0 @@ -/** - * Copyright (c) 2015-present, Facebook, Inc. - * - * This source code is licensed under the MIT license found in the - * LICENSE file in the root directory of this source tree. - */ - -// [macOS] - -#if TARGET_OS_OSX - -#import - -#import -#import - -// RCTUISlider - -@implementation RCTUISlider {} - -- (void)setValue:(float)value animated:(__unused BOOL)animated -{ - self.animator.floatValue = value; -} - -@end - - -// RCTUILabel - -@implementation RCTUILabel {} - -- (instancetype)initWithFrame:(NSRect)frameRect -{ - if (self = [super initWithFrame:frameRect]) { - [self setBezeled:NO]; - [self setDrawsBackground:NO]; - [self setEditable:NO]; - [self setSelectable:NO]; - [self setWantsLayer:YES]; - } - - return self; -} - -- (void)setText:(NSString *)text -{ - [self setStringValue:text]; -} - -@end - -@implementation RCTUISwitch - -- (BOOL)isOn -{ - return self.state == NSControlStateValueOn; -} - -- (void)setOn:(BOOL)on -{ - [self setOn:on animated:NO]; -} - -- (void)setOn:(BOOL)on animated:(BOOL)animated { - self.state = on ? NSControlStateValueOn : NSControlStateValueOff; -} - -@end - -// RCTUIActivityIndicatorView - -@interface RCTUIActivityIndicatorView () -@property (nonatomic, readwrite, getter=isAnimating) BOOL animating; -@end - -@implementation RCTUIActivityIndicatorView {} - -- (instancetype)initWithFrame:(CGRect)frame -{ - if ((self = [super initWithFrame:frame])) { - self.displayedWhenStopped = NO; - self.style = NSProgressIndicatorStyleSpinning; - } - return self; -} - -- (void)startAnimating -{ - // `wantsLayer` gets reset after the animation is stopped. We have to - // reset it in order for CALayer filters to take effect. - [self setWantsLayer:YES]; - [self startAnimation:self]; -} - -- (void)stopAnimating -{ - [self stopAnimation:self]; -} - -- (void)startAnimation:(id)sender -{ - [super startAnimation:sender]; - self.animating = YES; -} - -- (void)stopAnimation:(id)sender -{ - [super stopAnimation:sender]; - self.animating = NO; -} - -- (void)setActivityIndicatorViewStyle:(UIActivityIndicatorViewStyle)activityIndicatorViewStyle -{ - _activityIndicatorViewStyle = activityIndicatorViewStyle; - - switch (activityIndicatorViewStyle) { - case UIActivityIndicatorViewStyleLarge: - self.controlSize = NSControlSizeLarge; - break; - case UIActivityIndicatorViewStyleMedium: - self.controlSize = NSControlSizeRegular; - break; - default: - break; - } -} - -- (void)setColor:(RCTUIColor*)color -{ - if (_color != color) { - _color = color; - [self setNeedsDisplay:YES]; - } -} - -- (void)updateLayer -{ - [super updateLayer]; - if (_color != nil) { - CGFloat r, g, b, a; - [[_color colorUsingColorSpace:[NSColorSpace genericRGBColorSpace]] getRed:&r green:&g blue:&b alpha:&a]; - - CIFilter *colorPoly = [CIFilter filterWithName:@"CIColorPolynomial"]; - [colorPoly setDefaults]; - - CIVector *redVector = [CIVector vectorWithX:r Y:0 Z:0 W:0]; - CIVector *greenVector = [CIVector vectorWithX:g Y:0 Z:0 W:0]; - CIVector *blueVector = [CIVector vectorWithX:b Y:0 Z:0 W:0]; - [colorPoly setValue:redVector forKey:@"inputRedCoefficients"]; - [colorPoly setValue:greenVector forKey:@"inputGreenCoefficients"]; - [colorPoly setValue:blueVector forKey:@"inputBlueCoefficients"]; - - [[self layer] setFilters:@[colorPoly]]; - } else { - [[self layer] setFilters:nil]; - } -} - -- (void)setHidesWhenStopped:(BOOL)hidesWhenStopped -{ - self.displayedWhenStopped = !hidesWhenStopped; -} - -- (BOOL)hidesWhenStopped -{ - return !self.displayedWhenStopped; -} - -- (void)setHidden:(BOOL)hidden -{ - if ([self hidesWhenStopped] && ![self isAnimating]) { - [super setHidden:YES]; - } else { - [super setHidden:hidden]; - } -} - -@end - -// RCTUIImageView - -@implementation RCTUIImageView { - CALayer *_tintingLayer; -} - -- (instancetype)initWithFrame:(CGRect)frame -{ - if (self = [super initWithFrame:frame]) { - [self setLayer:[[CALayer alloc] init]]; - [self setWantsLayer:YES]; - } - - return self; -} - -- (void)setContentMode:(UIViewContentMode)contentMode -{ - _contentMode = contentMode; - - CALayer *layer = [self layer]; - switch (contentMode) { - case UIViewContentModeScaleAspectFill: - [layer setContentsGravity:kCAGravityResizeAspectFill]; - break; - - case UIViewContentModeScaleAspectFit: - [layer setContentsGravity:kCAGravityResizeAspect]; - break; - - case UIViewContentModeScaleToFill: - [layer setContentsGravity:kCAGravityResize]; - break; - - case UIViewContentModeCenter: - [layer setContentsGravity:kCAGravityCenter]; - break; - - default: - break; - } -} - -- (RCTPlatformImage *)image -{ - return [[self layer] contents]; -} - -- (void)setImage:(RCTPlatformImage *)image -{ - CALayer *layer = [self layer]; - - if ([layer contents] != image || [layer backgroundColor] != nil) { - if (_tintColor) { - if (!_tintingLayer) { - _tintingLayer = [CALayer new]; - [_tintingLayer setFrame:self.bounds]; - [_tintingLayer setAutoresizingMask:kCALayerWidthSizable | kCALayerHeightSizable]; - [_tintingLayer setZPosition:1.0]; - CIFilter *sourceInCompositingFilter = [CIFilter filterWithName:@"CISourceInCompositing"]; - [sourceInCompositingFilter setDefaults]; - [_tintingLayer setCompositingFilter:sourceInCompositingFilter]; - [layer addSublayer:_tintingLayer]; - } - [_tintingLayer setBackgroundColor:_tintColor.CGColor]; - } else { - [_tintingLayer removeFromSuperlayer]; - _tintingLayer = nil; - } - - if (image != nil && [image resizingMode] == NSImageResizingModeTile) { - [layer setContents:nil]; - [layer setBackgroundColor:[NSColor colorWithPatternImage:image].CGColor]; - } else { - [layer setContents:image]; - [layer setBackgroundColor:nil]; - } - } -} - -@end - -#endif diff --git a/packages/react-native/React/RCTUIKit/RCTUIImageView.h b/packages/react-native/React/RCTUIKit/RCTUIImageView.h new file mode 100644 index 000000000000..8868ccaa420a --- /dev/null +++ b/packages/react-native/React/RCTUIKit/RCTUIImageView.h @@ -0,0 +1,25 @@ +/* + * Copyright (c) Meta Platforms, Inc. and affiliates. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + */ + +// [macOS] + +#pragma once + +#include + +#import + +#if !TARGET_OS_OSX +typedef UIImageView RCTUIImageView; +#else +@interface RCTUIImageView : NSImageView +NS_ASSUME_NONNULL_BEGIN +@property (nonatomic, strong) RCTUIColor *tintColor; +@property (nonatomic, assign) UIViewContentMode contentMode; +NS_ASSUME_NONNULL_END +@end +#endif diff --git a/packages/react-native/React/RCTUIKit/RCTUIImageView.m b/packages/react-native/React/RCTUIKit/RCTUIImageView.m new file mode 100644 index 000000000000..4e064a581082 --- /dev/null +++ b/packages/react-native/React/RCTUIKit/RCTUIImageView.m @@ -0,0 +1,96 @@ +/** + * Copyright (c) 2015-present, Facebook, Inc. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + */ + +// [macOS] + +#if TARGET_OS_OSX + +#import + +#import + +@implementation RCTUIImageView { + CALayer *_tintingLayer; +} + +- (instancetype)initWithFrame:(CGRect)frame +{ + if (self = [super initWithFrame:frame]) { + [self setLayer:[[CALayer alloc] init]]; + [self setWantsLayer:YES]; + } + + return self; +} + +- (void)setContentMode:(UIViewContentMode)contentMode +{ + _contentMode = contentMode; + + CALayer *layer = [self layer]; + switch (contentMode) { + case UIViewContentModeScaleAspectFill: + [layer setContentsGravity:kCAGravityResizeAspectFill]; + break; + + case UIViewContentModeScaleAspectFit: + [layer setContentsGravity:kCAGravityResizeAspect]; + break; + + case UIViewContentModeScaleToFill: + [layer setContentsGravity:kCAGravityResize]; + break; + + case UIViewContentModeCenter: + [layer setContentsGravity:kCAGravityCenter]; + break; + + default: + break; + } +} + +- (RCTPlatformImage *)image +{ + return [[self layer] contents]; +} + +- (void)setImage:(RCTPlatformImage *)image +{ + CALayer *layer = [self layer]; + + if ([layer contents] != image || [layer backgroundColor] != nil) { + if (_tintColor) { + if (!_tintingLayer) { + _tintingLayer = [CALayer new]; + [_tintingLayer setFrame:self.bounds]; + [_tintingLayer setAutoresizingMask:kCALayerWidthSizable | kCALayerHeightSizable]; + [_tintingLayer setZPosition:1.0]; + CIFilter *sourceInCompositingFilter = [CIFilter filterWithName:@"CISourceInCompositing"]; + [sourceInCompositingFilter setDefaults]; + [_tintingLayer setCompositingFilter:sourceInCompositingFilter]; + [layer addSublayer:_tintingLayer]; + } + [_tintingLayer setBackgroundColor:_tintColor.CGColor]; + } else { + [_tintingLayer removeFromSuperlayer]; + _tintingLayer = nil; + } + + if (image != nil && [image resizingMode] == NSImageResizingModeTile) { + [layer setContents:nil]; + [layer setBackgroundColor:[NSColor colorWithPatternImage:image].CGColor]; + } else { + [layer setContents:image]; + [layer setBackgroundColor:nil]; + } + } +} + +@end + +#endif diff --git a/packages/react-native/React/RCTUIKit/RCTUIKit.h b/packages/react-native/React/RCTUIKit/RCTUIKit.h index c9c904dde921..2933ca068fdd 100644 --- a/packages/react-native/React/RCTUIKit/RCTUIKit.h +++ b/packages/react-native/React/RCTUIKit/RCTUIKit.h @@ -14,6 +14,12 @@ #import #import #import -#import +#import +#import +#import +#import +#import +#import +#import #import #import diff --git a/packages/react-native/React/RCTUIKit/RCTUILabel.h b/packages/react-native/React/RCTUIKit/RCTUILabel.h new file mode 100644 index 000000000000..4dce1302ce66 --- /dev/null +++ b/packages/react-native/React/RCTUIKit/RCTUILabel.h @@ -0,0 +1,26 @@ +/* + * Copyright (c) Meta Platforms, Inc. and affiliates. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + */ + +// [macOS] + +#pragma once + +#include + +#import + +#if !TARGET_OS_OSX +typedef UILabel RCTUILabel; +#else +@interface RCTUILabel : NSTextField +NS_ASSUME_NONNULL_BEGIN +@property(nonatomic, copy) NSString* _Nullable text; +@property(nonatomic, assign) NSInteger numberOfLines; +@property(nonatomic, assign) NSTextAlignment textAlignment; +NS_ASSUME_NONNULL_END +@end +#endif diff --git a/packages/react-native/React/RCTUIKit/RCTUILabel.m b/packages/react-native/React/RCTUIKit/RCTUILabel.m new file mode 100644 index 000000000000..6f95938c5a35 --- /dev/null +++ b/packages/react-native/React/RCTUIKit/RCTUILabel.m @@ -0,0 +1,36 @@ +/** + * Copyright (c) 2015-present, Facebook, Inc. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + */ + +// [macOS] + +#if TARGET_OS_OSX + +#import + +@implementation RCTUILabel {} + +- (instancetype)initWithFrame:(NSRect)frameRect +{ + if (self = [super initWithFrame:frameRect]) { + [self setBezeled:NO]; + [self setDrawsBackground:NO]; + [self setEditable:NO]; + [self setSelectable:NO]; + [self setWantsLayer:YES]; + } + + return self; +} + +- (void)setText:(NSString *)text +{ + [self setStringValue:text]; +} + +@end + +#endif diff --git a/packages/react-native/React/RCTUIKit/RCTUIScrollView.h b/packages/react-native/React/RCTUIKit/RCTUIScrollView.h new file mode 100644 index 000000000000..411ac2597058 --- /dev/null +++ b/packages/react-native/React/RCTUIKit/RCTUIScrollView.h @@ -0,0 +1,68 @@ +/* + * Copyright (c) Meta Platforms, Inc. and affiliates. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + */ + +// [macOS] + +#pragma once + +#include + +#import + +#if !TARGET_OS_OSX + +#import + +#else // TARGET_OS_OSX [ + +#import + +NS_ASSUME_NONNULL_BEGIN + +@class RCTUIScrollView; + +/** + * Protocol for objects that want to listen to scroll events on macOS. + * This mirrors the relevant parts of UIScrollViewDelegate for cross-platform compatibility. + */ +@protocol RCTUIScrollViewDelegate +@optional +- (void)scrollViewDidScroll:(RCTUIScrollView *)scrollView; +@end + +@interface RCTUIScrollView : NSScrollView + +// UIScrollView properties missing in NSScrollView +@property (nonatomic, assign) CGPoint contentOffset; +@property (nonatomic, assign) UIEdgeInsets contentInset; +@property (nonatomic, assign) CGSize contentSize; +@property (nonatomic, assign) BOOL showsHorizontalScrollIndicator; +@property (nonatomic, assign) BOOL showsVerticalScrollIndicator; +@property (nonatomic, assign) UIEdgeInsets scrollIndicatorInsets; +@property(nonatomic, assign) CGFloat minimumZoomScale; +@property(nonatomic, assign) CGFloat maximumZoomScale; +@property (nonatomic, assign) CGFloat zoomScale; +@property (nonatomic, assign) BOOL alwaysBounceHorizontal; +@property (nonatomic, assign) BOOL alwaysBounceVertical; +// macOS specific properties +@property (nonatomic, assign) BOOL enableFocusRing; +@property (nonatomic, assign, getter=isScrollEnabled) BOOL scrollEnabled; +@property (nonatomic, weak, nullable) id delegate; + +- (void)setContentOffset:(CGPoint)contentOffset animated:(BOOL)animated; + +@end + +@interface RCTClipView : NSClipView + +@property (nonatomic, assign) BOOL constrainScrolling; + +@end + +NS_ASSUME_NONNULL_END + +#endif // ] TARGET_OS_OSX diff --git a/packages/react-native/React/RCTUIKit/RCTUIScrollView.m b/packages/react-native/React/RCTUIKit/RCTUIScrollView.m new file mode 100644 index 000000000000..c08e827a81fb --- /dev/null +++ b/packages/react-native/React/RCTUIKit/RCTUIScrollView.m @@ -0,0 +1,204 @@ +/** + * Copyright (c) 2015-present, Facebook, Inc. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + */ + +// [macOS] + +#if TARGET_OS_OSX + +#import + +// RCTUIScrollView + +@implementation RCTUIScrollView + +- (instancetype)initWithFrame:(CGRect)frame +{ + if (self = [super initWithFrame:frame]) { + self.scrollEnabled = YES; + self.drawsBackground = NO; + self.contentView.postsBoundsChangedNotifications = YES; + [[NSNotificationCenter defaultCenter] addObserver:self + selector:@selector(_rctuiHandleBoundsDidChange:) + name:NSViewBoundsDidChangeNotification + object:self.contentView]; + } + + return self; +} + +- (void)_rctuiHandleBoundsDidChange:(NSNotification *)notification +{ + if ([_delegate respondsToSelector:@selector(scrollViewDidScroll:)]) { + [_delegate scrollViewDidScroll:self]; + } +} + +- (void)setEnableFocusRing:(BOOL)enableFocusRing { + if (_enableFocusRing != enableFocusRing) { + _enableFocusRing = enableFocusRing; + } + + if (enableFocusRing) { + // NSTextView has no focus ring by default so let's use the standard Aqua focus ring. + [self setFocusRingType:NSFocusRingTypeExterior]; + } else { + [self setFocusRingType:NSFocusRingTypeNone]; + } +} + +// UIScrollView properties missing from NSScrollView +- (CGPoint)contentOffset +{ + return self.documentVisibleRect.origin; +} + +- (void)setContentOffset:(CGPoint)contentOffset +{ + [self.documentView scrollPoint:contentOffset]; +} + +- (void)setContentOffset:(CGPoint)contentOffset animated:(BOOL)animated +{ + if (animated) { + [NSAnimationContext runAnimationGroup:^(NSAnimationContext *context) { + context.duration = 0.3; // Set the duration of the animation + [self.documentView.animator scrollPoint:contentOffset]; + } completionHandler:nil]; + } else { + [self.documentView scrollPoint:contentOffset]; + } +} + +- (UIEdgeInsets)contentInset +{ + return super.contentInsets; +} + +- (void)setContentInset:(UIEdgeInsets)insets +{ + super.contentInsets = insets; +} + +- (CGSize)contentSize +{ + return self.documentView.frame.size; +} + +- (void)setContentSize:(CGSize)contentSize +{ + CGRect frame = self.documentView.frame; + frame.size = contentSize; + self.documentView.frame = frame; +} + +- (BOOL)showsHorizontalScrollIndicator +{ + return self.hasHorizontalScroller; +} + +- (void)setShowsHorizontalScrollIndicator:(BOOL)show +{ + self.hasHorizontalScroller = show; +} + +- (BOOL)showsVerticalScrollIndicator +{ + return self.hasVerticalScroller; +} + +- (void)setShowsVerticalScrollIndicator:(BOOL)show +{ + self.hasVerticalScroller = show; +} + +- (UIEdgeInsets)scrollIndicatorInsets +{ + return self.scrollerInsets; +} + +- (void)setScrollIndicatorInsets:(UIEdgeInsets)insets +{ + self.scrollerInsets = insets; +} + +- (CGFloat)zoomScale +{ + return self.magnification; +} + +- (void)setZoomScale:(CGFloat)zoomScale +{ + self.magnification = zoomScale; +} + +- (CGFloat)maximumZoomScale +{ + return self.maxMagnification; +} + +- (void)setMaximumZoomScale:(CGFloat)maximumZoomScale +{ + self.maxMagnification = maximumZoomScale; +} + +- (CGFloat)minimumZoomScale +{ + return self.minMagnification; +} + +- (void)setMinimumZoomScale:(CGFloat)minimumZoomScale +{ + self.minMagnification = minimumZoomScale; +} + + +- (BOOL)alwaysBounceHorizontal +{ + return self.horizontalScrollElasticity != NSScrollElasticityNone; +} + +- (void)setAlwaysBounceHorizontal:(BOOL)alwaysBounceHorizontal +{ + self.horizontalScrollElasticity = alwaysBounceHorizontal ? NSScrollElasticityAllowed : NSScrollElasticityNone; +} + +- (BOOL)alwaysBounceVertical +{ + return self.verticalScrollElasticity != NSScrollElasticityNone; +} + +- (void)setAlwaysBounceVertical:(BOOL)alwaysBounceVertical +{ + self.verticalScrollElasticity = alwaysBounceVertical ? NSScrollElasticityAllowed : NSScrollElasticityNone; +} + +@end + +@implementation RCTClipView + +- (instancetype)initWithFrame:(NSRect)frameRect +{ + if (self = [super initWithFrame:frameRect]) { + self.constrainScrolling = NO; + self.drawsBackground = NO; + } + + return self; +} + +- (NSRect)constrainBoundsRect:(NSRect)proposedBounds +{ + if (self.constrainScrolling) { + return NSMakeRect(0, 0, 0, 0); + } + + return [super constrainBoundsRect:proposedBounds]; +} + +@end + +#endif diff --git a/packages/react-native/React/RCTUIKit/RCTUISlider.h b/packages/react-native/React/RCTUIKit/RCTUISlider.h new file mode 100644 index 000000000000..833ef04ce77c --- /dev/null +++ b/packages/react-native/React/RCTUIKit/RCTUISlider.h @@ -0,0 +1,43 @@ +/* + * Copyright (c) Meta Platforms, Inc. and affiliates. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + */ + +// [macOS] + +#pragma once + +#include + +#import + +#if !TARGET_OS_OSX +typedef UISlider RCTUISlider; +#else +@protocol RCTUISliderDelegate; + +@interface RCTUISlider : NSSlider +NS_ASSUME_NONNULL_BEGIN +@property (nonatomic, weak) id delegate; +@property (nonatomic, readonly) BOOL pressed; +@property (nonatomic, assign) float value; +@property (nonatomic, assign) float minimumValue; +@property (nonatomic, assign) float maximumValue; +@property (nonatomic, strong) NSColor *minimumTrackTintColor; +@property (nonatomic, strong) NSColor *maximumTrackTintColor; + +- (void)setValue:(float)value animated:(BOOL)animated; +NS_ASSUME_NONNULL_END +@end +#endif + +#if TARGET_OS_OSX // [macOS +@protocol RCTUISliderDelegate +@optional +NS_ASSUME_NONNULL_BEGIN +- (void)slider:(RCTUISlider *)slider didPress:(BOOL)press; +NS_ASSUME_NONNULL_END +@end +#endif // macOS] diff --git a/packages/react-native/React/RCTUIKit/RCTUISlider.m b/packages/react-native/React/RCTUIKit/RCTUISlider.m new file mode 100644 index 000000000000..bfe8ad9276da --- /dev/null +++ b/packages/react-native/React/RCTUIKit/RCTUISlider.m @@ -0,0 +1,23 @@ +/** + * Copyright (c) 2015-present, Facebook, Inc. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + */ + +// [macOS] + +#if TARGET_OS_OSX + +#import + +@implementation RCTUISlider {} + +- (void)setValue:(float)value animated:(__unused BOOL)animated +{ + self.animator.floatValue = value; +} + +@end + +#endif diff --git a/packages/react-native/React/RCTUIKit/RCTUISwitch.h b/packages/react-native/React/RCTUIKit/RCTUISwitch.h new file mode 100644 index 000000000000..8657d00c39ce --- /dev/null +++ b/packages/react-native/React/RCTUIKit/RCTUISwitch.h @@ -0,0 +1,27 @@ +/* + * Copyright (c) Meta Platforms, Inc. and affiliates. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + */ + +// [macOS] + +#pragma once + +#include + +#import + +#if !TARGET_OS_OSX +typedef UISwitch RCTUISwitch; +#else +@interface RCTUISwitch : NSSwitch +NS_ASSUME_NONNULL_BEGIN +@property (nonatomic, getter=isOn) BOOL on; + +- (void)setOn:(BOOL)on animated:(BOOL)animated; + +NS_ASSUME_NONNULL_END +@end +#endif diff --git a/packages/react-native/React/RCTUIKit/RCTUISwitch.m b/packages/react-native/React/RCTUIKit/RCTUISwitch.m new file mode 100644 index 000000000000..7533180f22a0 --- /dev/null +++ b/packages/react-native/React/RCTUIKit/RCTUISwitch.m @@ -0,0 +1,32 @@ +/** + * Copyright (c) 2015-present, Facebook, Inc. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + */ + +// [macOS] + +#if TARGET_OS_OSX + +#import + +@implementation RCTUISwitch + +- (BOOL)isOn +{ + return self.state == NSControlStateValueOn; +} + +- (void)setOn:(BOOL)on +{ + [self setOn:on animated:NO]; +} + +- (void)setOn:(BOOL)on animated:(BOOL)animated { + self.state = on ? NSControlStateValueOn : NSControlStateValueOff; +} + +@end + +#endif diff --git a/packages/react-native/React/RCTUIKit/RCTUITouch.h b/packages/react-native/React/RCTUIKit/RCTUITouch.h new file mode 100644 index 000000000000..45f2518efd5c --- /dev/null +++ b/packages/react-native/React/RCTUIKit/RCTUITouch.h @@ -0,0 +1,21 @@ +/* + * Copyright (c) Meta Platforms, Inc. and affiliates. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + */ + +// [macOS] + +#pragma once + +#include + +#if !TARGET_OS_OSX +#import +typedef UITouch RCTUITouch; +#else +#import +@interface RCTUITouch : NSEvent +@end +#endif diff --git a/packages/react-native/React/RCTUIKit/RCTUIView.h b/packages/react-native/React/RCTUIKit/RCTUIView.h index be0f7f3af88d..0ba7a38b0873 100644 --- a/packages/react-native/React/RCTUIKit/RCTUIView.h +++ b/packages/react-native/React/RCTUIKit/RCTUIView.h @@ -97,48 +97,6 @@ NS_ASSUME_NONNULL_BEGIN @end -// UIScrollView - -@class RCTUIScrollView; - -/** - * Protocol for objects that want to listen to scroll events on macOS. - * This mirrors the relevant parts of UIScrollViewDelegate for cross-platform compatibility. - */ -@protocol RCTUIScrollViewDelegate -@optional -- (void)scrollViewDidScroll:(RCTUIScrollView *)scrollView; -@end - -@interface RCTUIScrollView : NSScrollView - -// UIScrollView properties missing in NSScrollView -@property (nonatomic, assign) CGPoint contentOffset; -@property (nonatomic, assign) UIEdgeInsets contentInset; -@property (nonatomic, assign) CGSize contentSize; -@property (nonatomic, assign) BOOL showsHorizontalScrollIndicator; -@property (nonatomic, assign) BOOL showsVerticalScrollIndicator; -@property (nonatomic, assign) UIEdgeInsets scrollIndicatorInsets; -@property(nonatomic, assign) CGFloat minimumZoomScale; -@property(nonatomic, assign) CGFloat maximumZoomScale; -@property (nonatomic, assign) CGFloat zoomScale; -@property (nonatomic, assign) BOOL alwaysBounceHorizontal; -@property (nonatomic, assign) BOOL alwaysBounceVertical; -// macOS specific properties -@property (nonatomic, assign) BOOL enableFocusRing; -@property (nonatomic, assign, getter=isScrollEnabled) BOOL scrollEnabled; -@property (nonatomic, weak, nullable) id delegate; - -- (void)setContentOffset:(CGPoint)contentOffset animated:(BOOL)animated; - -@end - -@interface RCTClipView : NSClipView - -@property (nonatomic, assign) BOOL constrainScrolling; - -@end - NS_INLINE RCTPlatformView *RCTUIViewHitTestWithEvent(RCTPlatformView *view, CGPoint point, __unused UIEvent *__nullable event) { diff --git a/packages/react-native/React/RCTUIKit/RCTUIView.m b/packages/react-native/React/RCTUIKit/RCTUIView.m index bb9860b12b91..d57949c7ff03 100644 --- a/packages/react-native/React/RCTUIKit/RCTUIView.m +++ b/packages/react-native/React/RCTUIKit/RCTUIView.m @@ -272,194 +272,4 @@ - (void)setCursor:(NSInteger)cursor @end -// RCTUIScrollView - -@implementation RCTUIScrollView - -- (instancetype)initWithFrame:(CGRect)frame -{ - if (self = [super initWithFrame:frame]) { - self.scrollEnabled = YES; - self.drawsBackground = NO; - self.contentView.postsBoundsChangedNotifications = YES; - [[NSNotificationCenter defaultCenter] addObserver:self - selector:@selector(_rctuiHandleBoundsDidChange:) - name:NSViewBoundsDidChangeNotification - object:self.contentView]; - } - - return self; -} - -- (void)_rctuiHandleBoundsDidChange:(NSNotification *)notification -{ - if ([_delegate respondsToSelector:@selector(scrollViewDidScroll:)]) { - [_delegate scrollViewDidScroll:self]; - } -} - -- (void)setEnableFocusRing:(BOOL)enableFocusRing { - if (_enableFocusRing != enableFocusRing) { - _enableFocusRing = enableFocusRing; - } - - if (enableFocusRing) { - // NSTextView has no focus ring by default so let's use the standard Aqua focus ring. - [self setFocusRingType:NSFocusRingTypeExterior]; - } else { - [self setFocusRingType:NSFocusRingTypeNone]; - } -} - -// UIScrollView properties missing from NSScrollView -- (CGPoint)contentOffset -{ - return self.documentVisibleRect.origin; -} - -- (void)setContentOffset:(CGPoint)contentOffset -{ - [self.documentView scrollPoint:contentOffset]; -} - -- (void)setContentOffset:(CGPoint)contentOffset animated:(BOOL)animated -{ - if (animated) { - [NSAnimationContext runAnimationGroup:^(NSAnimationContext *context) { - context.duration = 0.3; // Set the duration of the animation - [self.documentView.animator scrollPoint:contentOffset]; - } completionHandler:nil]; - } else { - [self.documentView scrollPoint:contentOffset]; - } -} - -- (UIEdgeInsets)contentInset -{ - return super.contentInsets; -} - -- (void)setContentInset:(UIEdgeInsets)insets -{ - super.contentInsets = insets; -} - -- (CGSize)contentSize -{ - return self.documentView.frame.size; -} - -- (void)setContentSize:(CGSize)contentSize -{ - CGRect frame = self.documentView.frame; - frame.size = contentSize; - self.documentView.frame = frame; -} - -- (BOOL)showsHorizontalScrollIndicator -{ - return self.hasHorizontalScroller; -} - -- (void)setShowsHorizontalScrollIndicator:(BOOL)show -{ - self.hasHorizontalScroller = show; -} - -- (BOOL)showsVerticalScrollIndicator -{ - return self.hasVerticalScroller; -} - -- (void)setShowsVerticalScrollIndicator:(BOOL)show -{ - self.hasVerticalScroller = show; -} - -- (UIEdgeInsets)scrollIndicatorInsets -{ - return self.scrollerInsets; -} - -- (void)setScrollIndicatorInsets:(UIEdgeInsets)insets -{ - self.scrollerInsets = insets; -} - -- (CGFloat)zoomScale -{ - return self.magnification; -} - -- (void)setZoomScale:(CGFloat)zoomScale -{ - self.magnification = zoomScale; -} - -- (CGFloat)maximumZoomScale -{ - return self.maxMagnification; -} - -- (void)setMaximumZoomScale:(CGFloat)maximumZoomScale -{ - self.maxMagnification = maximumZoomScale; -} - -- (CGFloat)minimumZoomScale -{ - return self.minMagnification; -} - -- (void)setMinimumZoomScale:(CGFloat)minimumZoomScale -{ - self.minMagnification = minimumZoomScale; -} - - -- (BOOL)alwaysBounceHorizontal -{ - return self.horizontalScrollElasticity != NSScrollElasticityNone; -} - -- (void)setAlwaysBounceHorizontal:(BOOL)alwaysBounceHorizontal -{ - self.horizontalScrollElasticity = alwaysBounceHorizontal ? NSScrollElasticityAllowed : NSScrollElasticityNone; -} - -- (BOOL)alwaysBounceVertical -{ - return self.verticalScrollElasticity != NSScrollElasticityNone; -} - -- (void)setAlwaysBounceVertical:(BOOL)alwaysBounceVertical -{ - self.verticalScrollElasticity = alwaysBounceVertical ? NSScrollElasticityAllowed : NSScrollElasticityNone; -} - -@end - -@implementation RCTClipView - -- (instancetype)initWithFrame:(NSRect)frameRect -{ - if (self = [super initWithFrame:frameRect]) { - self.constrainScrolling = NO; - self.drawsBackground = NO; - } - - return self; -} - -- (NSRect)constrainBoundsRect:(NSRect)proposedBounds -{ - if (self.constrainScrolling) { - return NSMakeRect(0, 0, 0, 0); - } - - return [super constrainBoundsRect:proposedBounds]; -} - -@end - #endif diff --git a/packages/rn-tester/Podfile.lock b/packages/rn-tester/Podfile.lock index 76864ca7f2e5..89d2c9734ef5 100644 --- a/packages/rn-tester/Podfile.lock +++ b/packages/rn-tester/Podfile.lock @@ -2679,7 +2679,7 @@ SPEC CHECKSUMS: boost: cea1d4f90a3a59537f3deb03ff5656489d7133dd DoubleConversion: d31b1eb37f6d6f456530c4fd9124b857d6889cab fast_float: 20817c22759af6ac8d4d67e6e059b8b499953656 - FBLazyVector: c7b890b69ef2a6065ac451cab027e93f4f964892 + FBLazyVector: 883d23b435763ffeb26ec0cba67f17b2a7b52add fmt: 24e7591456deb60b4a77518f83d9a916ac84223f glog: 0b31c25149b9d350b2666c7d459229861a00ec07 hermes-engine: 6685af7f27b851cd7fa2675bdeef4b291383b2fc @@ -2689,74 +2689,74 @@ SPEC CHECKSUMS: OSSLibraryExample: 5105eecb9aa325c0d65c59023fd8dc5f5753e777 RCT-Folly: c803cf33238782d5fd21a5e02d44f64068e0e130 RCTDeprecation: 3808e36294137f9ee5668f4df2e73dc079cd1dcf - RCTRequired: 274607329cc254e14b6a28c903bb747402c05418 - RCTTypeSafety: d4a386d20765a33b1d8c4ddfc861ab15c80e6cf4 - React: 930f249eefcdcf5609086bd26c7e2e857b3cc4fa - React-callinvoker: da114f59edc0e6441a7c95802d445afa3454ceaf - React-Core: 419883322b1eacc0f0ff45a24203595a6b555504 - React-CoreModules: 2e5a68cc2a87e52e22ba4b9f57e4f97e49bd2ee2 - React-cxxreact: 984a2a3c5dd651579b4eb2ffa505baef206a282e - React-debug: 8bf9abebb537a63a8efc3f98186bfcc43615185c - React-defaultsnativemodule: 1e26faca5d859402ff4bbee82078c120faba6b8b - React-domnativemodule: 7ae3e9eea7f8eb39076f3a7ee7b9fa967afa563f - React-Fabric: e25594c4fd8dd18d97e26c6228ada963de08af72 - React-FabricComponents: 9f3955018e9e2425f2e35e957c4de6ed0eaf119b - React-FabricImage: badef29e8895701cfea55bf2beae00f3b2d069b2 - React-featureflags: 447be21640968c4bfbaeb0a902138304c595b7be - React-featureflagsnativemodule: dceeba1e8c8f162703d5fba665279499c5903f0e - React-graphics: 164c63f8603efe5e767af3665d53ccd76ec3b474 - React-hermes: 5da2abe39df0ab30d73f7bd0530da12a6eba2829 - React-idlecallbacksnativemodule: 863a4ea807d1bce7019d4dffb055f478e437a148 - React-ImageManager: af4528fea06482f7e44f467766280718ddbf6138 - React-jserrorhandler: 6855b88718ebcce68a66916cc9b3b197921842d6 - React-jsi: 4a49a45141f4626ba8018d0f3377d3d625d6aa11 - React-jsiexecutor: 2b2255a76b3f991946f8ce04e65cfabb94a24e3e - React-jsinspector: 2cc1c746a948f3364fed67261e308f41bca63547 - React-jsinspectorcdp: 74d038bcf91fca8abe61535b90d19b1ed179a953 - React-jsinspectornetwork: a2ab0071fc0907970193993e4e10962f8943b7fd - React-jsinspectortracing: 370624ea83f1524a05eb08f8386ed1d15e0ac315 - React-jsitooling: b5e53dffcae2fa956a77a5b503e6b4e02992181f - React-jsitracing: 43a1bb48e7d68e279549f9c93d39ff4b3fe33478 - React-logger: d506ef13cb4522a4b4cce06edb0e0ac98041b4fc - React-Mapbuffer: 0a178e6cbb22d093e5810b1cbb64c6c5a9dda84d - React-microtasksnativemodule: 861156de53f81e4d5c1a7a0def769765bcec90b7 - React-NativeModulesApple: 84c44036eeb6b6ad2985024886a4ee53b2d1dcaa - React-oscompat: 954d8b5b7855347362c3007d7311998292623a69 - React-perflogger: 5a32fd56cc69391180a9ec9c6fd678c339a77f24 - React-performancetimeline: 55eed1a5c6c6147462b6d3c3693db3297320c1e3 - React-RCTActionSheet: 0ccbcf7137d0f6738edb2271e0a502f14f8e88c1 - React-RCTAnimation: e80e504c0437370c74e12a6f61d0f706db85c307 - React-RCTAppDelegate: 4b7ec615378f00ee56bcae9d38549cc964ceed50 - React-RCTBlob: 62ca5e2309a7bc445b9b1dcf1383e8b0ad82104d - React-RCTFabric: a624e48cd887844fcf2cc910f31c6547d6364cf2 - React-RCTFBReactNativeSpec: 9713a2d5d1b22dd14bd0a3c089b7a4aec75671de - React-RCTImage: c64f6af45cf3c6e7341bae261b6490de865e4e70 - React-RCTLinking: a2d4676b5cc2c95df571df9618b76dee3c8ec79b - React-RCTNetwork: a913abd5a0fcbf1cf5f26137c11878931cd3e703 - React-RCTPushNotification: ce6a29d6a5714ba9420d506ccb9f4dbf58a6b739 - React-RCTRuntime: 80e5be9066f7ba85bd55097f15ffb61e8c5a9084 - React-RCTSettings: 1ad5132a6e70f0b81ba63b7b0717d0e07e588e34 - React-RCTTest: 5aaca2f430f931405e2de224b1e096cdb648a89a - React-RCTText: 45007a59bedde49b886e322965454aaab363c3d2 - React-RCTUIKit: e343b3a6bc0c03a1b1c6a056d6af0263128144dc - React-RCTVibration: fc6016098fd6f0ac16747a1bd3f644d715a424e4 - React-rendererconsistency: 8239dde9dd4ed1aae5ef1aec2c90bc805372d6d8 - React-renderercss: 97670a37f6d8d13ca5fc8741b0413e3c60d6a6c4 - React-rendererdebug: d951ca359c96f0257957ae4025d11ed497698f75 - React-RuntimeApple: a1099c7312bdc18c0dc8eb5a40ed7dff2a07dee1 - React-RuntimeCore: 349443a05f6813855472782c6b55df85cd84e555 - React-runtimeexecutor: 011c263b2c28caf33e81c64f35be1b22d02c2d92 - React-RuntimeHermes: 7b75f16a1250fdae2872451d1f51e53b2e0bf207 - React-runtimescheduler: 2a1123cf29212016edd37c4963f3b07bb6add017 - React-timing: eaa51caa267b03cd485ab6862e873ccb541d0790 - React-utils: c8041e8f8c55d1522e452529beec18940e4e6c47 - ReactAppDependencyProvider: 7b3b301e8c0525b6c87250dcbbccf58757e05666 + RCTRequired: 51921b51508d6ef3be419e67fcdbf771608cbc19 + RCTTypeSafety: 131a0039844d64a74c7216102eff2ad8481bcff0 + React: 17dfab6575595b3e8c05981f3551b9abc1cb4638 + React-callinvoker: a2cf876fa6ff549021c82fab9d8a844ebf3edb26 + React-Core: 6689d6d8c840c346b4fb33bedd3b4ab0998977b9 + React-CoreModules: 6229a45c4541a71ee6d98efc699041f4822d034e + React-cxxreact: dde26d5ff2290d256ba2f54361b6b25d66692b6f + React-debug: 12114c2c85860bd1ae063e8395dfe1acfdbd8e52 + React-defaultsnativemodule: a6f47f4d3a27be6ab8219be9c291e07d88be905c + React-domnativemodule: cabe322920f0924390bb1f773eaff8c78ce00811 + React-Fabric: a58f497cf6e43fdc977e809e344a41fe982a816d + React-FabricComponents: ed64f37c5bbedc7fc6d53bbdfb26bf762133279a + React-FabricImage: 2df53db37380f92a783b1aeebd0b8743346eab37 + React-featureflags: f618e7376b5d60cf50e6ecc54cc8d8f8bea7f533 + React-featureflagsnativemodule: 059ddc2ede24b334027f2c8bf20998b6e831952f + React-graphics: 82f3372e393a5df8ac8c6bc7eb375de56e2fd864 + React-hermes: fa3cfba79ca3ada41ba44164a3ef6c188bf5e4cd + React-idlecallbacksnativemodule: 5745409ad4aa6a532b39402142e7a8cef79d028a + React-ImageManager: 2be9a311a8eaa5a3fe61cae37cae80ae22a054f8 + React-jserrorhandler: 202b40c70dbb27be5cfce7b08ea2622087d2f68b + React-jsi: 02b339fbda34a660011f9f5f2a20a4ef2b7daa34 + React-jsiexecutor: fb7702654f79856cb4f481841862f3d20011416d + React-jsinspector: 1fd9b2f8f6cc1c27e392a29f78a6b68a92ea9f42 + React-jsinspectorcdp: 9a7b13a3c6609800cda10056fa93e4393fc3b996 + React-jsinspectornetwork: e1e25e2b7cc89dabe1510c833e571ab085359303 + React-jsinspectortracing: ffd28c432635828f25731713819d014460b3fa85 + React-jsitooling: ede7b163d214a8a3d2b433d866cf433da1de268d + React-jsitracing: ec3d60a5cb0f4cb56af78ecd34da6f57885fe416 + React-logger: 135e4abf56127b967fffff5bc0b2ef4584de4d7d + React-Mapbuffer: 53dca8beb377fde16e00009969ca2b5fd0f20f60 + React-microtasksnativemodule: 3d6a681dec1d7f7ae998ab8dde7004c549d8354c + React-NativeModulesApple: 6016a2fc496946028b816bec6196ff94ea2e1e79 + React-oscompat: 8ad747df4f44d49b553721acbf823a59f34f29ed + React-perflogger: 3b9810997047cad4744250472679c66f086c6b1c + React-performancetimeline: d743f996c984d740146884e6701b4ffc849c5b1c + React-RCTActionSheet: 517b6b7ef2d331cfe73c50497d3b18e5365e9d76 + React-RCTAnimation: 6290b0750ad9f7725e545ea49c7e37cdec99b2f6 + React-RCTAppDelegate: dbd82637e081e7e992cd117093c40f8531d47e8a + React-RCTBlob: 8319c310008dafaf5bd4a286e1e9a31bbb70a82a + React-RCTFabric: 6a1a3b0e6c8afcb5c6047e6fcc38db2c36019f64 + React-RCTFBReactNativeSpec: ac36c80d54a2cb41f29de51da352f08822204ce2 + React-RCTImage: 2c5cf5aa49b5aa7c2996dc70656e45025e5ed9a9 + React-RCTLinking: b32854bda6832be0f99b4a66135ebb33f8d5e9c0 + React-RCTNetwork: 1f245ae633aaa0a32bc31003384e7319610ae2ed + React-RCTPushNotification: 0421f26b78ede0214cf8d54bdb325d2377d77fd9 + React-RCTRuntime: b7deaa678c5c0fb3aa7d9b85290f2c7c16be791e + React-RCTSettings: 48f3c42e09e8ad94ce8aa65ead8832f74ae37050 + React-RCTTest: 9af0697ac1f84d2ce4a5a3f801757294f87089ce + React-RCTText: 4507043f2dabd4cb7137695d5e1ec935374a28cd + React-RCTUIKit: 0e209d063e5ea1e2932e91290113271e6d7e3b05 + React-RCTVibration: eb64d2a8f7cb554813ccc2d46453e09f8c3346cc + React-rendererconsistency: 5dda1a2c3c3e32aa69025d09de976c7c32641fb4 + React-renderercss: 06b267fdad0b96950c19178bbbdc3c44c74f3483 + React-rendererdebug: 96839422f2e87ba948f14dcd73c9c831e498b629 + React-RuntimeApple: 876fef1ebdc838d23a0e290b254210d6a36d76b3 + React-RuntimeCore: 7d1ec1a8ea0a676c78af8a5c9127b0ff93d6e2cc + React-runtimeexecutor: cf91d5d1ad62c324b73152f41bc92f30483b3192 + React-RuntimeHermes: d41e2636727bbc43a15d993060729d72d21ec344 + React-runtimescheduler: 952cf9e2dfa52bc346778b66e4a0bcb84695bf4c + React-timing: 9ba4a42a794a6c4362f91ee414dddfe8cd0b55fd + React-utils: f4cc581df2d9566393a574c2c123a871145158d1 + ReactAppDependencyProvider: a442a82933c528431a4fbb90a7aa113681fa0020 ReactCodegen: 45d2e543e9f1958ea9cf32b87ffa06b550db3683 - ReactCommon: 63e15f5c2bd41af08fcad4acdc3728e184478c9e - ReactCommon-Samples: 733c5cc2f9bc6d5c93a7da4d8f854ebca31621b5 + ReactCommon: 7803a3e81ce4850dc577b4f1929a1d776b3877ee + ReactCommon-Samples: 7ff26d71ada1a09525d6fc7c466c83aa9e29add2 ScreenshotManager: 10713952cbe264b56dfd36670e881ddd028daef5 SocketRocket: d4aabe649be1e368d1318fdf28a022d714d65748 - Yoga: cdd92b67325602211751bf8eb90aeb56cf9d80e2 + Yoga: fe5ea7afbb80f9d777066a728fa44f77d227ddd5 PODFILE CHECKSUM: 86f155f7e9c92081bc7cd14b59aa0c1774a88f73 From 3c8af35a5d8f26b1f223132f81de7d55c9b04156 Mon Sep 17 00:00:00 2001 From: Saad Najmi Date: Mon, 9 Mar 2026 13:27:45 -0700 Subject: [PATCH 3/6] refactor: inline platform conditionals --- .../RCTUIKit/RCTUIActivityIndicatorView.h | 2 +- .../RCTUIKit/RCTUIActivityIndicatorView.m | 2 +- .../React/RCTUIKit/RCTUIGeometry.h | 53 ++--- .../React/RCTUIKit/RCTUIGraphics.h | 50 ++--- .../react-native/React/RCTUIKit/RCTUIImage.h | 79 +++++--- .../React/RCTUIKit/RCTUIImageView.h | 3 +- .../React/RCTUIKit/RCTUIKitCompat.h | 191 +++++++++--------- .../React/RCTUIKit/RCTUIScrollView.h | 3 + .../react-native/React/RCTUIKit/RCTUIView.h | 55 ++--- .../react-native/React/RCTUIKit/README.md | 44 ++++ .../React/Views/RCTActivityIndicatorView.h | 2 +- .../React/Views/RCTActivityIndicatorView.m | 2 +- packages/rn-tester/Podfile.lock | 132 ++++++------ 13 files changed, 353 insertions(+), 265 deletions(-) create mode 100644 packages/react-native/React/RCTUIKit/README.md diff --git a/packages/react-native/React/RCTUIKit/RCTUIActivityIndicatorView.h b/packages/react-native/React/RCTUIKit/RCTUIActivityIndicatorView.h index 04fb7051e392..054cf5ef11e0 100644 --- a/packages/react-native/React/RCTUIKit/RCTUIActivityIndicatorView.h +++ b/packages/react-native/React/RCTUIKit/RCTUIActivityIndicatorView.h @@ -20,7 +20,7 @@ typedef UIActivityIndicatorView RCTUIActivityIndicatorView; NS_ASSUME_NONNULL_BEGIN @property (nonatomic, assign) UIActivityIndicatorViewStyle activityIndicatorViewStyle; @property (nonatomic, assign) BOOL hidesWhenStopped; -@property (nullable, readwrite, nonatomic, strong) RCTUIColor *color; +@property (nullable, readwrite, nonatomic, strong) RCTPlatformColor *color; @property (nonatomic, readonly, getter=isAnimating) BOOL animating; - (void)startAnimating; diff --git a/packages/react-native/React/RCTUIKit/RCTUIActivityIndicatorView.m b/packages/react-native/React/RCTUIKit/RCTUIActivityIndicatorView.m index 1568469253e8..b608e5703794 100644 --- a/packages/react-native/React/RCTUIKit/RCTUIActivityIndicatorView.m +++ b/packages/react-native/React/RCTUIKit/RCTUIActivityIndicatorView.m @@ -70,7 +70,7 @@ - (void)setActivityIndicatorViewStyle:(UIActivityIndicatorViewStyle)activityIndi } } -- (void)setColor:(RCTUIColor*)color +- (void)setColor:(RCTPlatformColor*)color { if (_color != color) { _color = color; diff --git a/packages/react-native/React/RCTUIKit/RCTUIGeometry.h b/packages/react-native/React/RCTUIKit/RCTUIGeometry.h index 9e9ab597fa3b..65dcdfe5c9cc 100644 --- a/packages/react-native/React/RCTUIKit/RCTUIGeometry.h +++ b/packages/react-native/React/RCTUIKit/RCTUIGeometry.h @@ -12,11 +12,17 @@ #include #if !TARGET_OS_OSX - #import +#else +#import +#endif NS_ASSUME_NONNULL_BEGIN +// MARK: - NSValue geometry helpers + +#if !TARGET_OS_OSX + UIKIT_STATIC_INLINE NSValue *NSValueWithCGRect(CGRect rect) { return [NSValue valueWithCGRect:rect]; @@ -32,15 +38,31 @@ UIKIT_STATIC_INLINE CGRect CGRectValue(NSValue *value) return [value CGRectValue]; } -NS_ASSUME_NONNULL_END +#else // TARGET_OS_OSX -#else // TARGET_OS_OSX [ +NS_INLINE NSValue *NSValueWithCGRect(CGRect rect) +{ + return [NSValue valueWithBytes:&rect objCType:@encode(CGRect)]; +} -#import +NS_INLINE NSValue *NSValueWithCGSize(CGSize size) +{ + return [NSValue valueWithBytes:&size objCType:@encode(CGSize)]; +} -NS_ASSUME_NONNULL_BEGIN +NS_INLINE CGRect CGRectValue(NSValue *value) +{ + CGRect rect = CGRectZero; + [value getValue:&rect]; + return rect; +} + +#endif + +// MARK: - macOS-only UIKit geometry shims + +#if TARGET_OS_OSX -// UIGeometry.h/NSGeometry.h NS_INLINE CGRect UIEdgeInsetsInsetRect(CGRect rect, NSEdgeInsets insets) { rect.origin.x += insets.left; @@ -65,23 +87,6 @@ NS_INLINE NSString *NSStringFromCGRect(CGRect rect) return NSStringFromRect(NSRectFromCGRect(rect)); } -NS_INLINE NSValue *NSValueWithCGRect(CGRect rect) -{ - return [NSValue valueWithBytes:&rect objCType:@encode(CGRect)]; -} - -NS_INLINE NSValue *NSValueWithCGSize(CGSize size) -{ - return [NSValue valueWithBytes:&size objCType:@encode(CGSize)]; -} - -NS_INLINE CGRect CGRectValue(NSValue *value) -{ - CGRect rect = CGRectZero; - [value getValue:&rect]; - return rect; -} +#endif // TARGET_OS_OSX NS_ASSUME_NONNULL_END - -#endif // ] TARGET_OS_OSX diff --git a/packages/react-native/React/RCTUIKit/RCTUIGraphics.h b/packages/react-native/React/RCTUIKit/RCTUIGraphics.h index c291ab329a51..2161acb66df0 100644 --- a/packages/react-native/React/RCTUIKit/RCTUIGraphics.h +++ b/packages/react-native/React/RCTUIKit/RCTUIGraphics.h @@ -12,47 +12,51 @@ #include #if !TARGET_OS_OSX - #import - -NS_ASSUME_NONNULL_BEGIN - -UIKIT_STATIC_INLINE UIBezierPath *UIBezierPathWithRoundedRect(CGRect rect, CGFloat cornerRadius) -{ - return [UIBezierPath bezierPathWithRoundedRect:rect cornerRadius:cornerRadius]; -} - -UIKIT_STATIC_INLINE void UIBezierPathAppendPath(UIBezierPath *path, UIBezierPath *appendPath) -{ - [path appendPath:appendPath]; -} - -NS_ASSUME_NONNULL_END - -#else // TARGET_OS_OSX [ - +#else #import +#endif NS_ASSUME_NONNULL_BEGIN +// MARK: - UIGraphicsGetCurrentContext + +#if TARGET_OS_OSX #ifdef __cplusplus extern "C" { #endif -// UIGraphics.h CGContextRef UIGraphicsGetCurrentContext(void); #ifdef __cplusplus } -#endif // __cpusplus +#endif +#endif // TARGET_OS_OSX + +// MARK: - UIBezierPath helpers -// UIBezierPath +#if TARGET_OS_OSX @compatibility_alias UIBezierPath NSBezierPath; +#endif + +#if !TARGET_OS_OSX + +UIKIT_STATIC_INLINE UIBezierPath *UIBezierPathWithRoundedRect(CGRect rect, CGFloat cornerRadius) +{ + return [UIBezierPath bezierPathWithRoundedRect:rect cornerRadius:cornerRadius]; +} + +UIKIT_STATIC_INLINE void UIBezierPathAppendPath(UIBezierPath *path, UIBezierPath *appendPath) +{ + [path appendPath:appendPath]; +} + +#else // TARGET_OS_OSX UIBezierPath *UIBezierPathWithRoundedRect(CGRect rect, CGFloat cornerRadius); void UIBezierPathAppendPath(UIBezierPath *path, UIBezierPath *appendPath); -NS_ASSUME_NONNULL_END +#endif -#endif // ] TARGET_OS_OSX +NS_ASSUME_NONNULL_END diff --git a/packages/react-native/React/RCTUIKit/RCTUIImage.h b/packages/react-native/React/RCTUIKit/RCTUIImage.h index aa11a9f1a384..e5483c81ca22 100644 --- a/packages/react-native/React/RCTUIKit/RCTUIImage.h +++ b/packages/react-native/React/RCTUIKit/RCTUIImage.h @@ -14,38 +14,19 @@ #import #if !TARGET_OS_OSX - #import +#define RCTPlatformImage UIImage +#define RCTUIImage UIImage +#else +#import +#define RCTPlatformImage NSImage +#endif NS_ASSUME_NONNULL_BEGIN -UIKIT_STATIC_INLINE CGFloat UIImageGetScale(UIImage *image) -{ - return image.scale; -} - -UIKIT_STATIC_INLINE CGImageRef UIImageGetCGImageRef(UIImage *image) -{ - return image.CGImage; -} - -UIKIT_STATIC_INLINE UIImage *UIImageWithContentsOfFile(NSString *filePath) -{ - return [UIImage imageWithContentsOfFile:filePath]; -} - -UIKIT_STATIC_INLINE UIImage *UIImageWithData(NSData *imageData) -{ - return [UIImage imageWithData:imageData]; -} - -NS_ASSUME_NONNULL_END - -#else // TARGET_OS_OSX [ - -#import +// MARK: - RCTUIImage class (macOS only) -NS_ASSUME_NONNULL_BEGIN +#if TARGET_OS_OSX /** * An NSImage subclass that caches its CGImage representation. @@ -71,6 +52,24 @@ typedef NS_ENUM(NSInteger, UIImageRenderingMode) { UIImageRenderingModeAlwaysTemplate, }; +#endif // TARGET_OS_OSX + +// MARK: - Image helper functions + +#if !TARGET_OS_OSX + +UIKIT_STATIC_INLINE CGFloat UIImageGetScale(UIImage *image) +{ + return image.scale; +} + +UIKIT_STATIC_INLINE CGImageRef UIImageGetCGImageRef(UIImage *image) +{ + return image.CGImage; +} + +#else // TARGET_OS_OSX + #ifdef __cplusplus extern "C" { #endif @@ -82,6 +81,24 @@ CGImageRef __nullable UIImageGetCGImageRef(NSImage *image); } #endif +#endif + +// MARK: - Image creation helpers + +#if !TARGET_OS_OSX + +UIKIT_STATIC_INLINE UIImage *UIImageWithContentsOfFile(NSString *filePath) +{ + return [UIImage imageWithContentsOfFile:filePath]; +} + +UIKIT_STATIC_INLINE UIImage *UIImageWithData(NSData *imageData) +{ + return [UIImage imageWithData:imageData]; +} + +#else // TARGET_OS_OSX + NS_INLINE NSImage *UIImageWithContentsOfFile(NSString *filePath) { return [[NSImage alloc] initWithContentsOfFile:filePath]; @@ -92,9 +109,13 @@ NS_INLINE NSImage *UIImageWithData(NSData *imageData) return [[NSImage alloc] initWithData:imageData]; } +#endif + +// MARK: - Image encoding (macOS only) + +#if TARGET_OS_OSX NSData *UIImagePNGRepresentation(NSImage *image); NSData *UIImageJPEGRepresentation(NSImage *image, CGFloat compressionQuality); +#endif NS_ASSUME_NONNULL_END - -#endif // ] TARGET_OS_OSX diff --git a/packages/react-native/React/RCTUIKit/RCTUIImageView.h b/packages/react-native/React/RCTUIKit/RCTUIImageView.h index 8868ccaa420a..e4bd90440e26 100644 --- a/packages/react-native/React/RCTUIKit/RCTUIImageView.h +++ b/packages/react-native/React/RCTUIKit/RCTUIImageView.h @@ -12,13 +12,14 @@ #include #import +#import #if !TARGET_OS_OSX typedef UIImageView RCTUIImageView; #else @interface RCTUIImageView : NSImageView NS_ASSUME_NONNULL_BEGIN -@property (nonatomic, strong) RCTUIColor *tintColor; +@property (nonatomic, strong) RCTPlatformColor *tintColor; @property (nonatomic, assign) UIViewContentMode contentMode; NS_ASSUME_NONNULL_END @end diff --git a/packages/react-native/React/RCTUIKit/RCTUIKitCompat.h b/packages/react-native/React/RCTUIKit/RCTUIKitCompat.h index f3f643c10dfb..b60aa0a818e0 100644 --- a/packages/react-native/React/RCTUIKit/RCTUIKitCompat.h +++ b/packages/react-native/React/RCTUIKit/RCTUIKitCompat.h @@ -12,45 +12,47 @@ #include #if !TARGET_OS_OSX - #import +#else +#import +#endif NS_ASSUME_NONNULL_BEGIN -// UIView -#define RCTPlatformView UIView -#define RCTUIView UIView -#define RCTUIScrollView UIScrollView -#define RCTUIScrollViewDelegate UIScrollViewDelegate -#define RCTPlatformImage UIImage -#define RCTUIImage UIImage -#define RCTUIPanGestureRecognizer UIPanGestureRecognizer - -// UIColor.h -#define RCTUIColor UIColor - -NS_ASSUME_NONNULL_END +// MARK: - Color -#else // TARGET_OS_OSX [ +#if !TARGET_OS_OSX +#define RCTPlatformColor UIColor +#else +#define RCTPlatformColor NSColor +#endif -#import +// Backward compatibility +#define RCTUIColor RCTPlatformColor -NS_ASSUME_NONNULL_BEGIN +// MARK: - Event types -#define RCTPlatformImage NSImage +#if TARGET_OS_OSX +#define UIEvent NSEvent +#define UITouchType NSTouchType +#define UIEventButtonMask NSEventButtonMask +#define UIKeyModifierFlags NSEventModifierFlags +#endif -// -// semantically equivalent constants -// +// MARK: - Application notifications -// UIApplication.h/NSApplication.h +#if TARGET_OS_OSX #define UIApplicationDidBecomeActiveNotification NSApplicationDidBecomeActiveNotification #define UIApplicationDidEnterBackgroundNotification NSApplicationDidHideNotification #define UIApplicationDidFinishLaunchingNotification NSApplicationDidFinishLaunchingNotification #define UIApplicationWillResignActiveNotification NSApplicationWillResignActiveNotification -#define UIApplicationWillEnterForegroundNotification NSApplicationWillUnhideNotification +#define UIApplicationWillEnterForegroundNotification NSApplicationWillUnhideNotification +#endif + +// MARK: - Font constants + +#if TARGET_OS_OSX -// UIFontDescriptor.h/NSFontDescriptor.h #define UIFontDescriptorFamilyAttribute NSFontFamilyAttribute; #define UIFontDescriptorNameAttribute NSFontNameAttribute; #define UIFontDescriptorFaceAttribute NSFontFaceAttribute; @@ -80,26 +82,63 @@ NS_ASSUME_NONNULL_BEGIN #define UIFontDescriptorSystemDesignRounded NSFontDescriptorSystemDesignRounded #define UIFontDescriptorSystemDesignMonospaced NSFontDescriptorSystemDesignMonospaced +#endif // TARGET_OS_OSX -// RCTActivityIndicatorView.h -#define UIActivityIndicatorView NSProgressIndicator +// MARK: - Font type compatibility + +#if TARGET_OS_OSX + +// Both NSFont and UIFont are toll-free bridged to CTFontRef +@compatibility_alias UIFont NSFont; +@compatibility_alias UIFontDescriptor NSFontDescriptor; +typedef NSFontSymbolicTraits UIFontDescriptorSymbolicTraits; +typedef NSFontWeight UIFontWeight; + +NS_INLINE NSFont *UIFontWithSize(NSFont *font, CGFloat pointSize) +{ + return [NSFont fontWithDescriptor:font.fontDescriptor size:pointSize]; +} + +NS_INLINE CGFloat UIFontLineHeight(NSFont *font) +{ + return ceilf(font.ascender + ABS(font.descender) + font.leading); +} + +#endif // TARGET_OS_OSX + +// MARK: - View controller + +#if TARGET_OS_OSX +@compatibility_alias UIViewController NSViewController; +#endif +// MARK: - Geometry + +#if TARGET_OS_OSX -// UIGeometry.h/NSGeometry.h #define UIEdgeInsetsZero NSEdgeInsetsZero +typedef NSEdgeInsets UIEdgeInsets; -// UIView.h/NSLayoutConstraint.h -#define UIViewNoIntrinsicMetric -1 -// NSViewNoIntrinsicMetric is defined to -1 but is only available on macOS 10.11 and higher. On previous versions it was NSViewNoInstrinsicMetric (misspelled) and also defined to -1. +NS_INLINE NSEdgeInsets UIEdgeInsetsMake(CGFloat top, CGFloat left, CGFloat bottom, CGFloat right) +{ + return NSEdgeInsetsMake(top, left, bottom, right); +} + +#endif // TARGET_OS_OSX + +// MARK: - Misc constants -// UIInterface.h/NSUserInterfaceLayout.h +#if TARGET_OS_OSX +#define UIActivityIndicatorView NSProgressIndicator +#define UIViewNoIntrinsicMetric -1 #define UIUserInterfaceLayoutDirection NSUserInterfaceLayoutDirection +#endif -// -// semantically equivalent enums -// +// MARK: - Enums -// UIGestureRecognizer.h/NSGestureRecognizer.h +#if TARGET_OS_OSX + +// UIGestureRecognizer states enum { UIGestureRecognizerStatePossible = NSGestureRecognizerStatePossible, @@ -111,7 +150,7 @@ enum UIGestureRecognizerStateRecognized = NSGestureRecognizerStateRecognized, }; -// UIFontDescriptor.h/NSFontDescriptor.h +// UIFontDescriptor symbolic traits enum { UIFontDescriptorTraitItalic = NSFontItalicTrait, @@ -119,7 +158,7 @@ enum UIFontDescriptorTraitCondensed = NSFontCondensedTrait, }; -// UIView.h/NSView.h +// UIView autoresizing enum : NSUInteger { UIViewAutoresizingNone = NSViewNotSizable, @@ -131,7 +170,7 @@ enum : NSUInteger UIViewAutoresizingFlexibleBottomMargin = NSViewMaxYMargin, }; -// UIView/NSView.h +// UIViewContentMode typedef NS_ENUM(NSInteger, UIViewContentMode) { UIViewContentModeScaleAspectFill = NSViewLayerContentsPlacementScaleProportionallyToFill, UIViewContentModeScaleAspectFit = NSViewLayerContentsPlacementScaleProportionallyToFit, @@ -140,86 +179,48 @@ typedef NS_ENUM(NSInteger, UIViewContentMode) { UIViewContentModeTopLeft = NSViewLayerContentsPlacementTopLeft, }; -// UIInterface.h/NSUserInterfaceLayout.h +// UIUserInterfaceLayoutDirection enum : NSInteger { UIUserInterfaceLayoutDirectionLeftToRight = NSUserInterfaceLayoutDirectionLeftToRight, UIUserInterfaceLayoutDirectionRightToLeft = NSUserInterfaceLayoutDirectionRightToLeft, }; -// RCTActivityIndicatorView.h +// UIActivityIndicatorViewStyle typedef NS_ENUM(NSInteger, UIActivityIndicatorViewStyle) { UIActivityIndicatorViewStyleLarge, UIActivityIndicatorViewStyleMedium, }; -// UIColor.h/NSColor.h -#define RCTUIColor NSColor - -// UIFont.h/NSFont.h -// Both NSFont and UIFont are toll-free bridged to CTFontRef so we'll assume they're semantically equivalent -@compatibility_alias UIFont NSFont; - -// UIViewController.h/NSViewController.h -@compatibility_alias UIViewController NSViewController; - -NS_INLINE NSFont *UIFontWithSize(NSFont *font, CGFloat pointSize) -{ - return [NSFont fontWithDescriptor:font.fontDescriptor size:pointSize]; -} - -NS_INLINE CGFloat UIFontLineHeight(NSFont *font) -{ - return ceilf(font.ascender + ABS(font.descender) + font.leading); -} +#endif // TARGET_OS_OSX -// UIFontDescriptor.h/NSFontDescriptor.h -// Both NSFontDescriptor and UIFontDescriptor are toll-free bridged to CTFontDescriptorRef so we'll assume they're semantically equivalent -@compatibility_alias UIFontDescriptor NSFontDescriptor; -typedef NSFontSymbolicTraits UIFontDescriptorSymbolicTraits; -typedef NSFontWeight UIFontWeight; +// MARK: - Gesture recognizer -// UIGeometry.h/NSGeometry.h -typedef NSEdgeInsets UIEdgeInsets; - -NS_INLINE NSEdgeInsets UIEdgeInsetsMake(CGFloat top, CGFloat left, CGFloat bottom, CGFloat right) -{ - return NSEdgeInsetsMake(top, left, bottom, right); -} - -// -// functionally equivalent types -// - -// These types have the same purpose but may differ semantically. Use with care! - -#define UIEvent NSEvent -#define UITouchType NSTouchType -#define UIEventButtonMask NSEventButtonMask -#define UIKeyModifierFlags NSEventModifierFlags - -// UIGestureRecognizer +#if !TARGET_OS_OSX +#define RCTPlatformPanGestureRecognizer UIPanGestureRecognizer +#else #define UIGestureRecognizer NSGestureRecognizer #define UIGestureRecognizerDelegate NSGestureRecognizerDelegate -#define RCTUIPanGestureRecognizer NSPanGestureRecognizer - -// UIApplication +#define RCTPlatformPanGestureRecognizer NSPanGestureRecognizer #define UIApplication NSApplication +#endif -NS_ASSUME_NONNULL_END - -#endif // ] TARGET_OS_OSX +// Backward compatibility +#define RCTUIPanGestureRecognizer RCTPlatformPanGestureRecognizer -// -// Cross-platform typedefs -// +// MARK: - Cross-platform typedefs #if !TARGET_OS_OSX -typedef UIApplication RCTUIApplication; +typedef UIApplication RCTPlatformApplication; typedef UIWindow RCTPlatformWindow; typedef UIViewController RCTPlatformViewController; #else -typedef NSApplication RCTUIApplication; +typedef NSApplication RCTPlatformApplication; typedef NSWindow RCTPlatformWindow; typedef NSViewController RCTPlatformViewController; #endif + +// Backward compatibility +#define RCTUIApplication RCTPlatformApplication + +NS_ASSUME_NONNULL_END diff --git a/packages/react-native/React/RCTUIKit/RCTUIScrollView.h b/packages/react-native/React/RCTUIKit/RCTUIScrollView.h index 411ac2597058..31bce195e46c 100644 --- a/packages/react-native/React/RCTUIKit/RCTUIScrollView.h +++ b/packages/react-native/React/RCTUIKit/RCTUIScrollView.h @@ -17,6 +17,9 @@ #import +#define RCTUIScrollView UIScrollView +#define RCTUIScrollViewDelegate UIScrollViewDelegate + #else // TARGET_OS_OSX [ #import diff --git a/packages/react-native/React/RCTUIKit/RCTUIView.h b/packages/react-native/React/RCTUIKit/RCTUIView.h index 0ba7a38b0873..7579666ceaac 100644 --- a/packages/react-native/React/RCTUIKit/RCTUIView.h +++ b/packages/react-native/React/RCTUIKit/RCTUIView.h @@ -14,35 +14,22 @@ #import #if !TARGET_OS_OSX - #import +#else +#import +#endif NS_ASSUME_NONNULL_BEGIN -UIKIT_STATIC_INLINE RCTPlatformView *RCTUIViewHitTestWithEvent(RCTPlatformView *view, CGPoint point, __unused UIEvent *__nullable event) -{ - return [view hitTest:point withEvent:event]; -} - -UIKIT_STATIC_INLINE void RCTUIViewSetContentModeRedraw(UIView *view) -{ - view.contentMode = UIViewContentModeRedraw; -} +// MARK: - RCTPlatformView / RCTUIView -UIKIT_STATIC_INLINE BOOL RCTUIViewIsDescendantOfView(RCTPlatformView *view, RCTPlatformView *parent) -{ - return [view isDescendantOfView:parent]; -} - -NS_ASSUME_NONNULL_END +#if !TARGET_OS_OSX -#else // TARGET_OS_OSX [ +#define RCTPlatformView UIView +#define RCTUIView UIView -#import - -NS_ASSUME_NONNULL_BEGIN +#else // TARGET_OS_OSX -// UIView #define RCTPlatformView NSView @interface RCTUIView : RCTPlatformView @@ -97,6 +84,28 @@ NS_ASSUME_NONNULL_BEGIN @end +#endif // TARGET_OS_OSX + +// MARK: - View utility functions + +#if !TARGET_OS_OSX + +UIKIT_STATIC_INLINE RCTPlatformView *RCTUIViewHitTestWithEvent(RCTPlatformView *view, CGPoint point, __unused UIEvent *__nullable event) +{ + return [view hitTest:point withEvent:event]; +} + +UIKIT_STATIC_INLINE void RCTUIViewSetContentModeRedraw(UIView *view) +{ + view.contentMode = UIViewContentModeRedraw; +} + +UIKIT_STATIC_INLINE BOOL RCTUIViewIsDescendantOfView(RCTPlatformView *view, RCTPlatformView *parent) +{ + return [view isDescendantOfView:parent]; +} + +#else // TARGET_OS_OSX NS_INLINE RCTPlatformView *RCTUIViewHitTestWithEvent(RCTPlatformView *view, CGPoint point, __unused UIEvent *__nullable event) { @@ -116,6 +125,6 @@ NS_INLINE BOOL RCTUIViewIsDescendantOfView(RCTPlatformView *view, RCTPlatformVie return [view isDescendantOf:parent]; } -NS_ASSUME_NONNULL_END +#endif -#endif // ] TARGET_OS_OSX +NS_ASSUME_NONNULL_END diff --git a/packages/react-native/React/RCTUIKit/README.md b/packages/react-native/React/RCTUIKit/README.md new file mode 100644 index 000000000000..2831f17949f5 --- /dev/null +++ b/packages/react-native/React/RCTUIKit/README.md @@ -0,0 +1,44 @@ +# RCTUIKit + +RCTUIKit is a UIKit/AppKit compatibility layer for React Native macOS. It lets the rest of the +codebase use UIKit-style types and APIs on both iOS and macOS by providing: + +- **`#define` / `typedef` aliases** — On iOS, names like `RCTUIView` resolve to their UIKit + equivalents (`UIView`). On macOS, they resolve to custom `NSView` subclasses that fill in + missing UIKit API surface. +- **Inline helper functions** — Small cross-platform wrappers (e.g. `RCTUIViewHitTestWithEvent`, + `UIImageGetScale`) that smooth over behavioral differences between the two frameworks. +- **UIKit → AppKit shims** — Constants, enums, notifications, and font defines that let code + written against UIKit compile on macOS without `#if` guards everywhere. + +## Naming convention: `RCTUI` vs `RCTPlatform` + +There are two prefixes used in this layer, and the distinction matters: + +```objc +#if !TARGET_OS_OSX // iOS +#define RCTPlatformBar UIBar // RCTPlatform — plain alias +#define RCTUIFoo UIFoo // RCTUI — plain alias +#else +// macOS +#define RCTPlatformBar NSBar // RCTPlatform — plain alias +@interface RCTUIFoo : NSFoo. // RCTUI — Subclass for iOS compatibility +... +@end +#endif +``` + +| Prefix | Meaning | iOS | macOS | Examples | +|--------|---------|-----|-------|----------| +| **`RCTPlatform`** | Plain typedef / `#define` alias — no extra API | Resolves to UIKit type | Resolves to AppKit type | `RCTPlatformColor`, `RCTPlatformView`, `RCTPlatformImage` | +| **`RCTUI`** | Real subclass that adds UIKit-compatible API on macOS | `#define` to UIKit type | Custom `@interface` (e.g. `NSView` subclass) | `RCTUIView`, `RCTUIScrollView`, `RCTUIImage` | + +Use `RCTUI`-prefixed types when you need the extra UIKit compatibility surface that the macOS +subclass provides. Use `RCTPlatform`-prefixed types when you just need a type-safe way to refer +to "the color class" or "the base view class" without caring about additional API. + +For backward compatibility, the old `RCTUI` names still exist as aliases for the three types +that were moved to `RCTPlatform`: `RCTUIColor`, `RCTUIPanGestureRecognizer`, `RCTUIApplication`. + +The `.m` files are wrapped in `#if TARGET_OS_OSX ... #endif` since they only contain macOS +implementations. \ No newline at end of file diff --git a/packages/react-native/React/Views/RCTActivityIndicatorView.h b/packages/react-native/React/Views/RCTActivityIndicatorView.h index 81a3c5e02c20..df6885a4f2a2 100644 --- a/packages/react-native/React/Views/RCTActivityIndicatorView.h +++ b/packages/react-native/React/Views/RCTActivityIndicatorView.h @@ -12,7 +12,7 @@ #if TARGET_OS_OSX // [macOS @property (nonatomic, assign) UIActivityIndicatorViewStyle activityIndicatorViewStyle; @property (nonatomic, assign) BOOL hidesWhenStopped; -@property (nullable, readwrite, nonatomic, strong) RCTUIColor *color; // [macOS] +@property (nullable, readwrite, nonatomic, strong) RCTPlatformColor *color; // [macOS] @property (nonatomic, readonly, getter=isAnimating) BOOL animating; - (void)startAnimating; - (void)stopAnimating; diff --git a/packages/react-native/React/Views/RCTActivityIndicatorView.m b/packages/react-native/React/Views/RCTActivityIndicatorView.m index 936691dddb21..a90c693d5a43 100644 --- a/packages/react-native/React/Views/RCTActivityIndicatorView.m +++ b/packages/react-native/React/Views/RCTActivityIndicatorView.m @@ -70,7 +70,7 @@ - (void)setActivityIndicatorViewStyle:(UIActivityIndicatorViewStyle)activityIndi } } -- (void)setColor:(RCTUIColor*)color +- (void)setColor:(RCTPlatformColor*)color { if (_color != color) { _color = color; diff --git a/packages/rn-tester/Podfile.lock b/packages/rn-tester/Podfile.lock index 89d2c9734ef5..2505737d86a1 100644 --- a/packages/rn-tester/Podfile.lock +++ b/packages/rn-tester/Podfile.lock @@ -2679,7 +2679,7 @@ SPEC CHECKSUMS: boost: cea1d4f90a3a59537f3deb03ff5656489d7133dd DoubleConversion: d31b1eb37f6d6f456530c4fd9124b857d6889cab fast_float: 20817c22759af6ac8d4d67e6e059b8b499953656 - FBLazyVector: 883d23b435763ffeb26ec0cba67f17b2a7b52add + FBLazyVector: 8c5ed8f5f7c7fb2c618e9d8fe0306422afcab617 fmt: 24e7591456deb60b4a77518f83d9a916ac84223f glog: 0b31c25149b9d350b2666c7d459229861a00ec07 hermes-engine: 6685af7f27b851cd7fa2675bdeef4b291383b2fc @@ -2689,74 +2689,74 @@ SPEC CHECKSUMS: OSSLibraryExample: 5105eecb9aa325c0d65c59023fd8dc5f5753e777 RCT-Folly: c803cf33238782d5fd21a5e02d44f64068e0e130 RCTDeprecation: 3808e36294137f9ee5668f4df2e73dc079cd1dcf - RCTRequired: 51921b51508d6ef3be419e67fcdbf771608cbc19 - RCTTypeSafety: 131a0039844d64a74c7216102eff2ad8481bcff0 - React: 17dfab6575595b3e8c05981f3551b9abc1cb4638 - React-callinvoker: a2cf876fa6ff549021c82fab9d8a844ebf3edb26 - React-Core: 6689d6d8c840c346b4fb33bedd3b4ab0998977b9 - React-CoreModules: 6229a45c4541a71ee6d98efc699041f4822d034e - React-cxxreact: dde26d5ff2290d256ba2f54361b6b25d66692b6f - React-debug: 12114c2c85860bd1ae063e8395dfe1acfdbd8e52 - React-defaultsnativemodule: a6f47f4d3a27be6ab8219be9c291e07d88be905c - React-domnativemodule: cabe322920f0924390bb1f773eaff8c78ce00811 - React-Fabric: a58f497cf6e43fdc977e809e344a41fe982a816d - React-FabricComponents: ed64f37c5bbedc7fc6d53bbdfb26bf762133279a - React-FabricImage: 2df53db37380f92a783b1aeebd0b8743346eab37 - React-featureflags: f618e7376b5d60cf50e6ecc54cc8d8f8bea7f533 - React-featureflagsnativemodule: 059ddc2ede24b334027f2c8bf20998b6e831952f - React-graphics: 82f3372e393a5df8ac8c6bc7eb375de56e2fd864 - React-hermes: fa3cfba79ca3ada41ba44164a3ef6c188bf5e4cd - React-idlecallbacksnativemodule: 5745409ad4aa6a532b39402142e7a8cef79d028a - React-ImageManager: 2be9a311a8eaa5a3fe61cae37cae80ae22a054f8 - React-jserrorhandler: 202b40c70dbb27be5cfce7b08ea2622087d2f68b - React-jsi: 02b339fbda34a660011f9f5f2a20a4ef2b7daa34 - React-jsiexecutor: fb7702654f79856cb4f481841862f3d20011416d - React-jsinspector: 1fd9b2f8f6cc1c27e392a29f78a6b68a92ea9f42 - React-jsinspectorcdp: 9a7b13a3c6609800cda10056fa93e4393fc3b996 - React-jsinspectornetwork: e1e25e2b7cc89dabe1510c833e571ab085359303 - React-jsinspectortracing: ffd28c432635828f25731713819d014460b3fa85 - React-jsitooling: ede7b163d214a8a3d2b433d866cf433da1de268d - React-jsitracing: ec3d60a5cb0f4cb56af78ecd34da6f57885fe416 - React-logger: 135e4abf56127b967fffff5bc0b2ef4584de4d7d - React-Mapbuffer: 53dca8beb377fde16e00009969ca2b5fd0f20f60 - React-microtasksnativemodule: 3d6a681dec1d7f7ae998ab8dde7004c549d8354c - React-NativeModulesApple: 6016a2fc496946028b816bec6196ff94ea2e1e79 - React-oscompat: 8ad747df4f44d49b553721acbf823a59f34f29ed - React-perflogger: 3b9810997047cad4744250472679c66f086c6b1c - React-performancetimeline: d743f996c984d740146884e6701b4ffc849c5b1c - React-RCTActionSheet: 517b6b7ef2d331cfe73c50497d3b18e5365e9d76 - React-RCTAnimation: 6290b0750ad9f7725e545ea49c7e37cdec99b2f6 - React-RCTAppDelegate: dbd82637e081e7e992cd117093c40f8531d47e8a - React-RCTBlob: 8319c310008dafaf5bd4a286e1e9a31bbb70a82a - React-RCTFabric: 6a1a3b0e6c8afcb5c6047e6fcc38db2c36019f64 - React-RCTFBReactNativeSpec: ac36c80d54a2cb41f29de51da352f08822204ce2 - React-RCTImage: 2c5cf5aa49b5aa7c2996dc70656e45025e5ed9a9 - React-RCTLinking: b32854bda6832be0f99b4a66135ebb33f8d5e9c0 - React-RCTNetwork: 1f245ae633aaa0a32bc31003384e7319610ae2ed - React-RCTPushNotification: 0421f26b78ede0214cf8d54bdb325d2377d77fd9 - React-RCTRuntime: b7deaa678c5c0fb3aa7d9b85290f2c7c16be791e - React-RCTSettings: 48f3c42e09e8ad94ce8aa65ead8832f74ae37050 - React-RCTTest: 9af0697ac1f84d2ce4a5a3f801757294f87089ce - React-RCTText: 4507043f2dabd4cb7137695d5e1ec935374a28cd - React-RCTUIKit: 0e209d063e5ea1e2932e91290113271e6d7e3b05 - React-RCTVibration: eb64d2a8f7cb554813ccc2d46453e09f8c3346cc - React-rendererconsistency: 5dda1a2c3c3e32aa69025d09de976c7c32641fb4 - React-renderercss: 06b267fdad0b96950c19178bbbdc3c44c74f3483 - React-rendererdebug: 96839422f2e87ba948f14dcd73c9c831e498b629 - React-RuntimeApple: 876fef1ebdc838d23a0e290b254210d6a36d76b3 - React-RuntimeCore: 7d1ec1a8ea0a676c78af8a5c9127b0ff93d6e2cc - React-runtimeexecutor: cf91d5d1ad62c324b73152f41bc92f30483b3192 - React-RuntimeHermes: d41e2636727bbc43a15d993060729d72d21ec344 - React-runtimescheduler: 952cf9e2dfa52bc346778b66e4a0bcb84695bf4c - React-timing: 9ba4a42a794a6c4362f91ee414dddfe8cd0b55fd - React-utils: f4cc581df2d9566393a574c2c123a871145158d1 - ReactAppDependencyProvider: a442a82933c528431a4fbb90a7aa113681fa0020 + RCTRequired: f93971b6cc77a578664f7509f4f6c58b6096a094 + RCTTypeSafety: 0c0a2f4cd381689b83b6933b706524eb76a2a226 + React: 3cc8a9580b6e9f2109c2539ba2190c58be234e80 + React-callinvoker: 774c76d5e58a379bce7394bd952b3b5cfa75ee10 + React-Core: 034463a78376ec032844f8824d9e550b7b1da4fc + React-CoreModules: d426931656374cf383b4df1a7a57cb3d4cf7dfdd + React-cxxreact: d497c307ad56be4249e4e15f06b34f42ed7e5f0b + React-debug: d70d452a59cdc0b9dc0a2db861af2fd8e213b36b + React-defaultsnativemodule: 211889c964131e6ff81862b7f836636ce46871c6 + React-domnativemodule: aad271fa1377d4c761ca229a2c6d5c9de073efc3 + React-Fabric: 65ff37ac5d0eca50df21e9b6ea768474543de319 + React-FabricComponents: 3ef86609a14c103d9d86aa23a61c17a98b933586 + React-FabricImage: 0813ce2e9a7909167f940216158a226f793ef136 + React-featureflags: cacfe0bdb0125de3be61fdc18423338c678f3928 + React-featureflagsnativemodule: 320b731777f63fecf3d8f02f2c88772583655703 + React-graphics: 7939999d67a64da09cb42852b6f15e05596ac43b + React-hermes: c0f7d4b10d52bb3233739208f812baf31918989d + React-idlecallbacksnativemodule: 5d00d2a0457b0f50e093533f3eba0aad53042b2a + React-ImageManager: 0354a97da2ed58b2bb4ffa32463128d99064bfc6 + React-jserrorhandler: ff0e479096c623526cabee9e21a6bbdac9dce131 + React-jsi: a373a9eaf6cda4eb170c7cae87d6d27e494a07f8 + React-jsiexecutor: 363898b2c3a90152febd9ce2eeb8142f74c95875 + React-jsinspector: ce7c3ed5d6f391db1c51fd6233e4579481cbc026 + React-jsinspectorcdp: 95423f556a880ae6d4b2f0b39a20da4e32279ae0 + React-jsinspectornetwork: 61358b75b6e9b849a04fa1a9958dd86bd1f9a702 + React-jsinspectortracing: eebe1f917431c533f473491de69f16f3437828ed + React-jsitooling: 77428d071e954964ed2d7e153b6a640bf3856470 + React-jsitracing: 8ed01231135aaab7b37a3e91718f77c99a56e4c3 + React-logger: fd877088e41c9bc7676c7f368d7532017490bbc6 + React-Mapbuffer: 723a6d94bba97cdbd13a16e9c9ec384fa4da614e + React-microtasksnativemodule: 21fd5ff14e724e1f11830704edf262444281859e + React-NativeModulesApple: f6786138047529478cdae334a6613aa17dbcc4c8 + React-oscompat: d50c6bf2aaa4879b127ddb8907c201116dc29a12 + React-perflogger: 0c27553522a8b4b0a550e6b9e8d3983de7ad438d + React-performancetimeline: 6a34c6c9fcf17cf2fac9656fcae2e49b9a9a2936 + React-RCTActionSheet: 3bb429b7b5f207451d10b13139f6fc1b5418c619 + React-RCTAnimation: 53a2c00048bb93829e9ab871d800700b70e11ede + React-RCTAppDelegate: e2aaf4cf98165d70cd2218ed5f363906c2bff00c + React-RCTBlob: 88f697ff93b3db3302e65957016924c37a544fbd + React-RCTFabric: efff0623f313cfb826b3ba8896a0d86499b2193e + React-RCTFBReactNativeSpec: 7213511e4f969f0bb7593db5011122e795c7740b + React-RCTImage: eb5d29d3f8e84d7a2881b1dd5d12e2922c610938 + React-RCTLinking: e6f0269a647fe4cf71f8f756982e89f1b4bb9c9b + React-RCTNetwork: f7277e742f7a52be134bea954556f3762178912a + React-RCTPushNotification: af51404ab0cc839bd720102bddbd210e7f5eb56d + React-RCTRuntime: 376a60f54d19d0b899200246400288ff8bfc09d1 + React-RCTSettings: 92f173e4fe16b0d972b51b9d4a15df859de41d94 + React-RCTTest: cd3aff303b3c10304b4bbb8673ad3cb1d2c4f35b + React-RCTText: f4f4d0db1c8a303d38e8b85b08611ee4480dec9a + React-RCTUIKit: a8978f14be89f4bc17583dc2c52690e773abfb6b + React-RCTVibration: 92af8da27749e46668a838d9cdb4b97142414943 + React-rendererconsistency: 1e28bd57632297b5231494c0d9a1e32e1d2b66de + React-renderercss: 377edccc6f20f23117d80f80b16f1b6225f872b6 + React-rendererdebug: 9ff20ef76861344ddcb98b3ac41ee9fe4b413219 + React-RuntimeApple: dd2c831382a27e503af9012f109429fe82462490 + React-RuntimeCore: 081cde412a4cd5a4b266c70690ec30a175a998ee + React-runtimeexecutor: 89588e3d01209f86fd0238428716b8e857607944 + React-RuntimeHermes: 544d6070bc18d8587e1256a365265bc7140515c7 + React-runtimescheduler: d5976056b0113fd18010a1833849cf94873d94e4 + React-timing: b1d02199cbb35bf942a83e9d31cd7bd9294e37a5 + React-utils: 1040f15d9700d3992e55538fd36a3acd00b3c7c1 + ReactAppDependencyProvider: 80d7267281c29ed383e27db51468fab09d27d2fd ReactCodegen: 45d2e543e9f1958ea9cf32b87ffa06b550db3683 - ReactCommon: 7803a3e81ce4850dc577b4f1929a1d776b3877ee - ReactCommon-Samples: 7ff26d71ada1a09525d6fc7c466c83aa9e29add2 + ReactCommon: 01209feeb08aa9830c07f39d6ed2f4e33f83a393 + ReactCommon-Samples: bebe8836e5cecae96a2763b68de8c0cffb210e7a ScreenshotManager: 10713952cbe264b56dfd36670e881ddd028daef5 SocketRocket: d4aabe649be1e368d1318fdf28a022d714d65748 - Yoga: fe5ea7afbb80f9d777066a728fa44f77d227ddd5 + Yoga: f92c3c7550706b81e37925f9f035649e0a0312b0 PODFILE CHECKSUM: 86f155f7e9c92081bc7cd14b59aa0c1774a88f73 From dbac66be348cfe49ca089cb9ea8d0963b4863115 Mon Sep 17 00:00:00 2001 From: Saad Najmi Date: Mon, 9 Mar 2026 14:08:00 -0700 Subject: [PATCH 4/6] refactor: rename RCTUI typedefs to RCTPlatform Rename typedef-only aliases from RCTUI* to RCTPlatform* prefix to distinguish them from RCTUI* types that are real subclasses on macOS. - RCTUIColor -> RCTPlatformColor - RCTUIPanGestureRecognizer -> RCTPlatformPanGestureRecognizer - RCTUIApplication -> RCTPlatformApplication Backward-compatible aliases are provided for all three. --- .../RCTSampleNativeComponentComponentView.mm | 4 +- .../RCTSampleNativeComponentViewManager.mm | 4 +- .../Nodes/RCTInterpolationAnimatedNode.mm | 4 +- .../NativeAnimation/RCTAnimationUtils.h | 2 +- .../NativeAnimation/RCTAnimationUtils.mm | 2 +- .../Libraries/Text/RCTTextAttributes.h | 12 +- .../Libraries/Text/RCTTextAttributes.mm | 16 +-- .../Libraries/Text/Text/RCTTextView.mm | 2 +- .../Multiline/RCTMultilineTextInputView.mm | 2 +- .../Text/TextInput/Multiline/RCTUITextView.h | 6 +- .../Text/TextInput/Multiline/RCTUITextView.mm | 16 +-- .../TextInput/Multiline/RCTWrappedTextView.m | 2 +- .../RCTBackedTextInputViewProtocol.h | 2 +- .../Text/TextInput/RCTBaseTextInputView.h | 2 +- .../Text/TextInput/RCTBaseTextInputView.mm | 4 +- .../TextInput/Singleline/RCTUITextField.h | 4 +- .../TextInput/Singleline/RCTUITextField.mm | 14 +- packages/react-native/React/Base/RCTConvert.h | 10 +- .../react-native/React/Base/RCTConvert.mm | 36 ++--- packages/react-native/React/Base/RCTUtils.h | 2 +- packages/react-native/React/Base/RCTUtils.mm | 2 +- .../RCTSurfaceHostingView.mm | 2 +- .../CoreModules/RCTActionSheetManager.mm | 2 +- .../React/CoreModules/RCTDevLoadingView.mm | 20 +-- .../React/CoreModules/RCTFPSGraph.h | 2 +- .../React/CoreModules/RCTFPSGraph.mm | 4 +- .../React/CoreModules/RCTPerfMonitor.mm | 18 +-- .../DevSupport/RCTDevLoadingViewProtocol.h | 2 +- .../RCTPausedInDebuggerOverlayController.mm | 2 +- .../Text/RCTParagraphComponentView.mm | 4 +- .../RCTUnimplementedNativeComponentView.mm | 4 +- .../RCTUnimplementedViewComponentView.mm | 4 +- .../View/RCTViewComponentView.mm | 22 +-- .../React/Fabric/RCTConversions.h | 2 +- .../React/Fabric/Utils/RCTBoxShadow.mm | 2 +- .../React/Fabric/Utils/RCTGradientUtils.mm | 6 +- .../React/RCTUIKit/RCTUIKitCompat.h | 14 +- .../Views/RCTActivityIndicatorViewManager.m | 2 +- .../React/Views/RCTBorderDrawing.h | 10 +- .../React/Views/RCTBorderDrawing.m | 12 +- .../React/Views/RCTDebuggingOverlay.m | 6 +- packages/react-native/React/Views/RCTView.h | 20 +-- packages/react-native/React/Views/RCTView.m | 28 ++-- .../renderer/graphics/HostPlatformColor.mm | 34 ++--- .../renderer/graphics/RCTPlatformColorUtils.h | 4 +- .../graphics/RCTPlatformColorUtils.mm | 24 ++-- .../RCTAttributedTextUtils.mm | 14 +- .../RCTTextPrimitivesConversions.h | 2 +- .../ios/RNTLegacyView.mm | 2 +- .../ios/RNTMyNativeViewCommon.mm | 8 +- .../ios/UIView+ColorOverlays.h | 2 +- packages/rn-tester/Podfile.lock | 132 +++++++++--------- .../RCTTest/FBSnapshotTestCase/UIImage+Diff.m | 2 +- packages/rn-tester/RNTester/AppDelegate.mm | 4 +- .../FlexibleSizeExampleView.mm | 4 +- .../RCTAnimationUtilsTests.m | 8 +- .../RCTConvert_UIColorTests.m | 12 +- 57 files changed, 300 insertions(+), 288 deletions(-) diff --git a/packages/react-native-test-library/ios/RCTSampleNativeComponentComponentView.mm b/packages/react-native-test-library/ios/RCTSampleNativeComponentComponentView.mm index 4edd7c69c59f..68867f0ba906 100644 --- a/packages/react-native-test-library/ios/RCTSampleNativeComponentComponentView.mm +++ b/packages/react-native-test-library/ios/RCTSampleNativeComponentComponentView.mm @@ -18,14 +18,14 @@ using namespace facebook::react; -static RCTUIColor *RCTUIColorFromHexString(const std::string hexString) // [macOS] +static RCTPlatformColor *RCTUIColorFromHexString(const std::string hexString) // [macOS] { unsigned rgbValue = 0; NSString *colorString = [NSString stringWithCString:hexString.c_str() encoding:[NSString defaultCStringEncoding]]; NSScanner *scanner = [NSScanner scannerWithString:colorString]; [scanner setScanLocation:1]; // bypass '#' character [scanner scanHexInt:&rgbValue]; - return [RCTUIColor colorWithRed:((rgbValue & 0xFF0000) >> 16) / 255.0 // [macOS] + return [RCTPlatformColor colorWithRed:((rgbValue & 0xFF0000) >> 16) / 255.0 // [macOS] green:((rgbValue & 0xFF00) >> 8) / 255.0 blue:(rgbValue & 0xFF) / 255.0 alpha:1.0]; diff --git a/packages/react-native-test-library/ios/RCTSampleNativeComponentViewManager.mm b/packages/react-native-test-library/ios/RCTSampleNativeComponentViewManager.mm index 0574b317dbca..5e11f745a428 100644 --- a/packages/react-native-test-library/ios/RCTSampleNativeComponentViewManager.mm +++ b/packages/react-native-test-library/ios/RCTSampleNativeComponentViewManager.mm @@ -11,14 +11,14 @@ #import -static RCTUIColor *UIColorFromHexString(const std::string hexString) // [macOS] +static RCTPlatformColor *UIColorFromHexString(const std::string hexString) // [macOS] { unsigned rgbValue = 0; NSString *colorString = [NSString stringWithCString:hexString.c_str() encoding:[NSString defaultCStringEncoding]]; NSScanner *scanner = [NSScanner scannerWithString:colorString]; [scanner setScanLocation:1]; // bypass '#' character [scanner scanHexInt:&rgbValue]; - return [RCTUIColor colorWithRed:((rgbValue & 0xFF0000) >> 16) / 255.0 // [macOS] + return [RCTPlatformColor colorWithRed:((rgbValue & 0xFF0000) >> 16) / 255.0 // [macOS] green:((rgbValue & 0xFF00) >> 8) / 255.0 blue:(rgbValue & 0xFF) / 255.0 alpha:1.0]; diff --git a/packages/react-native/Libraries/NativeAnimation/Nodes/RCTInterpolationAnimatedNode.mm b/packages/react-native/Libraries/NativeAnimation/Nodes/RCTInterpolationAnimatedNode.mm index db335f1d7d0d..ce5db3bcc5c1 100644 --- a/packages/react-native/Libraries/NativeAnimation/Nodes/RCTInterpolationAnimatedNode.mm +++ b/packages/react-native/Libraries/NativeAnimation/Nodes/RCTInterpolationAnimatedNode.mm @@ -103,8 +103,8 @@ - (instancetype)initWithTag:(NSNumber *)tag config:(NSDictionary for (id value in outputRangeConfig) { switch (_outputType) { case RCTInterpolationOutputColor: { - RCTUIColor *color = [RCTConvert UIColor:value]; // [macOS] - [outputRange addObject:color ? color : [RCTUIColor whiteColor]]; // [macOS] + RCTPlatformColor *color = [RCTConvert UIColor:value]; // [macOS] + [outputRange addObject:color ? color : [RCTPlatformColor whiteColor]]; // [macOS] break; } case RCTInterpolationOutputString: diff --git a/packages/react-native/Libraries/NativeAnimation/RCTAnimationUtils.h b/packages/react-native/Libraries/NativeAnimation/RCTAnimationUtils.h index 3b3ac46c1f59..d23337d07f56 100644 --- a/packages/react-native/Libraries/NativeAnimation/RCTAnimationUtils.h +++ b/packages/react-native/Libraries/NativeAnimation/RCTAnimationUtils.h @@ -34,7 +34,7 @@ RCT_EXTERN CGFloat RCTInterpolateValueInRange( NSString *extrapolateRight); RCT_EXTERN uint32_t -RCTInterpolateColorInRange(CGFloat value, NSArray *inputRange, NSArray *outputRange); // [macOS] +RCTInterpolateColorInRange(CGFloat value, NSArray *inputRange, NSArray *outputRange); // [macOS] // Represents a color as a int32_t. RGB components are assumed to be in [0-255] range and alpha in [0-1] range RCT_EXTERN uint32_t RCTColorFromComponents(CGFloat red, CGFloat green, CGFloat blue, CGFloat alpha); diff --git a/packages/react-native/Libraries/NativeAnimation/RCTAnimationUtils.mm b/packages/react-native/Libraries/NativeAnimation/RCTAnimationUtils.mm index 94662918ded6..44ee6a60cb6e 100644 --- a/packages/react-native/Libraries/NativeAnimation/RCTAnimationUtils.mm +++ b/packages/react-native/Libraries/NativeAnimation/RCTAnimationUtils.mm @@ -84,7 +84,7 @@ CGFloat RCTInterpolateValueInRange( return RCTInterpolateValue(value, inputMin, inputMax, outputMin, outputMax, extrapolateLeft, extrapolateRight); } -uint32_t RCTInterpolateColorInRange(CGFloat value, NSArray *inputRange, NSArray *outputRange) // [macOS] +uint32_t RCTInterpolateColorInRange(CGFloat value, NSArray *inputRange, NSArray *outputRange) // [macOS] { NSUInteger rangeIndex = RCTFindIndexOfNearestValue(value, inputRange); CGFloat inputMin = inputRange[rangeIndex].doubleValue; diff --git a/packages/react-native/Libraries/Text/RCTTextAttributes.h b/packages/react-native/Libraries/Text/RCTTextAttributes.h index 8d39cde1f647..037b3cebc80a 100644 --- a/packages/react-native/Libraries/Text/RCTTextAttributes.h +++ b/packages/react-native/Libraries/Text/RCTTextAttributes.h @@ -25,8 +25,8 @@ extern NSString *const RCTTextAttributesTagAttributeName; @interface RCTTextAttributes : NSObject // Color -@property (nonatomic, strong, nullable) RCTUIColor *foregroundColor; // [macOS] -@property (nonatomic, strong, nullable) RCTUIColor *backgroundColor; // [macOS] +@property (nonatomic, strong, nullable) RCTPlatformColor *foregroundColor; // [macOS] +@property (nonatomic, strong, nullable) RCTPlatformColor *backgroundColor; // [macOS] @property (nonatomic, assign) CGFloat opacity; // Font @property (nonatomic, copy, nullable) NSString *fontFamily; @@ -46,13 +46,13 @@ extern NSString *const RCTTextAttributesTagAttributeName; @property (nonatomic, assign) NSLineBreakStrategy lineBreakStrategy; @property (nonatomic, assign) NSLineBreakMode lineBreakMode; // Decoration -@property (nonatomic, strong, nullable) RCTUIColor *textDecorationColor; // [macOS] +@property (nonatomic, strong, nullable) RCTPlatformColor *textDecorationColor; // [macOS] @property (nonatomic, assign) NSUnderlineStyle textDecorationStyle; @property (nonatomic, assign) RCTTextDecorationLineType textDecorationLine; // Shadow @property (nonatomic, assign) CGSize textShadowOffset; @property (nonatomic, assign) CGFloat textShadowRadius; -@property (nonatomic, strong, nullable) RCTUIColor *textShadowColor; // [macOS] +@property (nonatomic, strong, nullable) RCTPlatformColor *textShadowColor; // [macOS] // Special @property (nonatomic, assign) BOOL isHighlighted; @property (nonatomic, strong, nullable) NSNumber *tag; @@ -92,8 +92,8 @@ extern NSString *const RCTTextAttributesTagAttributeName; /** * Foreground and background colors with opacity and right defaults. */ -- (RCTUIColor *)effectiveForegroundColor; // [macOS] -- (RCTUIColor *)effectiveBackgroundColor; // [macOS] +- (RCTPlatformColor *)effectiveForegroundColor; // [macOS] +- (RCTPlatformColor *)effectiveBackgroundColor; // [macOS] /** * Text transformed per 'none', 'uppercase', 'lowercase', 'capitalize' diff --git a/packages/react-native/Libraries/Text/RCTTextAttributes.mm b/packages/react-native/Libraries/Text/RCTTextAttributes.mm index 9b9622bad08e..e3f9a0af583e 100644 --- a/packages/react-native/Libraries/Text/RCTTextAttributes.mm +++ b/packages/react-native/Libraries/Text/RCTTextAttributes.mm @@ -18,9 +18,9 @@ @implementation RCTTextAttributes // [macOS -+ (RCTUIColor *)defaultForegroundColor ++ (RCTPlatformColor *)defaultForegroundColor { - return [RCTUIColor labelColor]; + return [RCTPlatformColor labelColor]; } // macOS] @@ -175,7 +175,7 @@ - (NSParagraphStyle *)effectiveParagraphStyle } // Colors - RCTUIColor *effectiveForegroundColor = self.effectiveForegroundColor; // [macOS] + RCTPlatformColor *effectiveForegroundColor = self.effectiveForegroundColor; // [macOS] if (_foregroundColor || !isnan(_opacity)) { attributes[NSForegroundColorAttributeName] = effectiveForegroundColor; @@ -275,9 +275,9 @@ - (CGFloat)effectiveFontSizeMultiplier } } -- (RCTUIColor *)effectiveForegroundColor // [macOS] +- (RCTPlatformColor *)effectiveForegroundColor // [macOS] { - RCTUIColor *effectiveForegroundColor = _foregroundColor ?: [RCTUIColor blackColor]; // [macOS] + RCTPlatformColor *effectiveForegroundColor = _foregroundColor ?: [RCTPlatformColor blackColor]; // [macOS] if (!isnan(_opacity)) { effectiveForegroundColor = @@ -287,16 +287,16 @@ - (RCTUIColor *)effectiveForegroundColor // [macOS] return effectiveForegroundColor; } -- (RCTUIColor *)effectiveBackgroundColor // [macOS] +- (RCTPlatformColor *)effectiveBackgroundColor // [macOS] { - RCTUIColor *effectiveBackgroundColor = _backgroundColor; // ?: [[UIColor whiteColor] colorWithAlphaComponent:0]; // [macOS] + RCTPlatformColor *effectiveBackgroundColor = _backgroundColor; // ?: [[UIColor whiteColor] colorWithAlphaComponent:0]; // [macOS] if (effectiveBackgroundColor && !isnan(_opacity)) { effectiveBackgroundColor = [effectiveBackgroundColor colorWithAlphaComponent:CGColorGetAlpha(effectiveBackgroundColor.CGColor) * _opacity]; } - return effectiveBackgroundColor ?: [RCTUIColor clearColor]; // [macOS] + return effectiveBackgroundColor ?: [RCTPlatformColor clearColor]; // [macOS] } static NSString *capitalizeText(NSString *text) diff --git a/packages/react-native/Libraries/Text/Text/RCTTextView.mm b/packages/react-native/Libraries/Text/Text/RCTTextView.mm index abff88e692bd..d121a3ab427d 100644 --- a/packages/react-native/Libraries/Text/Text/RCTTextView.mm +++ b/packages/react-native/Libraries/Text/Text/RCTTextView.mm @@ -271,7 +271,7 @@ - (void)drawRect:(CGRect)rect if (highlightPath) { if (!_highlightLayer) { _highlightLayer = [CAShapeLayer layer]; - _highlightLayer.fillColor = [RCTUIColor colorWithWhite:0 alpha:0.25].CGColor; // [macOS] + _highlightLayer.fillColor = [RCTPlatformColor colorWithWhite:0 alpha:0.25].CGColor; // [macOS] [self.layer addSublayer:_highlightLayer]; } _highlightLayer.position = _contentFrame.origin; diff --git a/packages/react-native/Libraries/Text/TextInput/Multiline/RCTMultilineTextInputView.mm b/packages/react-native/Libraries/Text/TextInput/Multiline/RCTMultilineTextInputView.mm index 9be90e85d168..11f4df900f33 100644 --- a/packages/react-native/Libraries/Text/TextInput/Multiline/RCTMultilineTextInputView.mm +++ b/packages/react-native/Libraries/Text/TextInput/Multiline/RCTMultilineTextInputView.mm @@ -27,7 +27,7 @@ - (instancetype)initWithBridge:(RCTBridge *)bridge #if TARGET_OS_OSX // [macOS self.hideVerticalScrollIndicator = NO; _scrollView = [[RCTUIScrollView alloc] initWithFrame:self.bounds]; - _scrollView.backgroundColor = [RCTUIColor clearColor]; + _scrollView.backgroundColor = [RCTPlatformColor clearColor]; _scrollView.drawsBackground = NO; _scrollView.borderType = NSNoBorder; _scrollView.hasHorizontalRuler = NO; diff --git a/packages/react-native/Libraries/Text/TextInput/Multiline/RCTUITextView.h b/packages/react-native/Libraries/Text/TextInput/Multiline/RCTUITextView.h index 9be114752fa4..1200194463d1 100644 --- a/packages/react-native/Libraries/Text/TextInput/Multiline/RCTUITextView.h +++ b/packages/react-native/Libraries/Text/TextInput/Multiline/RCTUITextView.h @@ -32,7 +32,7 @@ #endif // macOS] @property (nonatomic, assign, readonly) BOOL dictationRecognizing; @property (nonatomic, copy, nullable) NSString *placeholder; - @property (nonatomic, strong, nullable) RCTUIColor *placeholderColor; // [macOS] + @property (nonatomic, strong, nullable) RCTPlatformColor *placeholderColor; // [macOS] @property (nonatomic, assign) CGFloat preferredMaxLayoutWidth; @@ -51,8 +51,8 @@ #if TARGET_OS_OSX // [macOS @property (nonatomic, getter=isScrollEnabled) BOOL scrollEnabled; - @property (nonatomic, strong, nullable) RCTUIColor *selectionColor; - @property (nonatomic, strong, nullable) RCTUIColor *cursorColor; + @property (nonatomic, strong, nullable) RCTPlatformColor *selectionColor; + @property (nonatomic, strong, nullable) RCTPlatformColor *cursorColor; @property (nonatomic, assign) UIEdgeInsets textContainerInsets; @property (nonatomic, copy) NSString *text; @property (nonatomic, assign) NSTextAlignment textAlignment; diff --git a/packages/react-native/Libraries/Text/TextInput/Multiline/RCTUITextView.mm b/packages/react-native/Libraries/Text/TextInput/Multiline/RCTUITextView.mm index 2929b16bbcc5..8c71181b26a8 100644 --- a/packages/react-native/Libraries/Text/TextInput/Multiline/RCTUITextView.mm +++ b/packages/react-native/Libraries/Text/TextInput/Multiline/RCTUITextView.mm @@ -42,10 +42,10 @@ @implementation RCTUITextView { } #endif // macOS] -static RCTUIColor *defaultPlaceholderColor(void) // [macOS] +static RCTPlatformColor *defaultPlaceholderColor(void) // [macOS] { // Default placeholder color from UITextField. - return [RCTUIColor placeholderTextColor]; // [macOS] + return [RCTPlatformColor placeholderTextColor]; // [macOS] } - (instancetype)initWithFrame:(CGRect)frame @@ -68,8 +68,8 @@ - (instancetype)initWithFrame:(CGRect)frame _textInputDelegateAdapter = [[RCTBackedTextViewDelegateAdapter alloc] initWithTextView:self]; - self.backgroundColor = [RCTUIColor clearColor]; // [macOS] - self.textColor = [RCTUIColor blackColor]; // [macOS] + self.backgroundColor = [RCTPlatformColor clearColor]; // [macOS] + self.textColor = [RCTPlatformColor blackColor]; // [macOS] // This line actually removes 5pt (default value) left and right padding in UITextView. #if !TARGET_OS_OSX // [macOS] self.textContainer.lineFragmentPadding = 0; @@ -149,7 +149,7 @@ - (void)setPlaceholder:(NSString *)placeholder [self _updatePlaceholder]; } -- (void)setPlaceholderColor:(RCTUIColor *)placeholderColor // [macOS] +- (void)setPlaceholderColor:(RCTPlatformColor *)placeholderColor // [macOS] { _placeholderColor = placeholderColor; [self _updatePlaceholder]; @@ -174,16 +174,16 @@ - (void)toggleGrammarChecking:(id)sender [_textInputDelegate grammarCheckingDidChange:self.isGrammarCheckingEnabled]; } -- (void)setSelectionColor:(RCTUIColor *)selectionColor +- (void)setSelectionColor:(RCTPlatformColor *)selectionColor { NSMutableDictionary *selectTextAttributes = self.selectedTextAttributes.mutableCopy; selectTextAttributes[NSBackgroundColorAttributeName] = selectionColor ?: [NSColor selectedControlColor]; self.selectedTextAttributes = selectTextAttributes.copy; } -- (RCTUIColor*)selectionColor +- (RCTPlatformColor*)selectionColor { - return (RCTUIColor*)self.selectedTextAttributes[NSBackgroundColorAttributeName]; + return (RCTPlatformColor*)self.selectedTextAttributes[NSBackgroundColorAttributeName]; } - (void)setCursorColor:(NSColor *)cursorColor diff --git a/packages/react-native/Libraries/Text/TextInput/Multiline/RCTWrappedTextView.m b/packages/react-native/Libraries/Text/TextInput/Multiline/RCTWrappedTextView.m index ed8f3444b755..01114a943c70 100644 --- a/packages/react-native/Libraries/Text/TextInput/Multiline/RCTWrappedTextView.m +++ b/packages/react-native/Libraries/Text/TextInput/Multiline/RCTWrappedTextView.m @@ -28,7 +28,7 @@ - (instancetype)initWithFrame:(CGRect)frame self.hideVerticalScrollIndicator = NO; _scrollView = [[RCTUIScrollView alloc] initWithFrame:self.bounds]; - _scrollView.backgroundColor = [RCTUIColor clearColor]; + _scrollView.backgroundColor = [RCTPlatformColor clearColor]; _scrollView.drawsBackground = NO; _scrollView.borderType = NSNoBorder; _scrollView.hasHorizontalRuler = NO; diff --git a/packages/react-native/Libraries/Text/TextInput/RCTBackedTextInputViewProtocol.h b/packages/react-native/Libraries/Text/TextInput/RCTBackedTextInputViewProtocol.h index a04f96a7d871..63a8a57e47c7 100644 --- a/packages/react-native/Libraries/Text/TextInput/RCTBackedTextInputViewProtocol.h +++ b/packages/react-native/Libraries/Text/TextInput/RCTBackedTextInputViewProtocol.h @@ -33,7 +33,7 @@ NS_ASSUME_NONNULL_BEGIN @property (nonatomic, copy, nullable) NSAttributedString *attributedText; @property (nonatomic, copy, nullable) NSString *placeholder; -@property (nonatomic, strong, nullable) RCTUIColor *placeholderColor; // [macOS] +@property (nonatomic, strong, nullable) RCTPlatformColor *placeholderColor; // [macOS] #if !TARGET_OS_OSX // [macOS] @property (nonatomic, assign, readonly) BOOL textWasPasted; #else // [macOS diff --git a/packages/react-native/Libraries/Text/TextInput/RCTBaseTextInputView.h b/packages/react-native/Libraries/Text/TextInput/RCTBaseTextInputView.h index bcaa6add683b..d3d9f50633d1 100644 --- a/packages/react-native/Libraries/Text/TextInput/RCTBaseTextInputView.h +++ b/packages/react-native/Libraries/Text/TextInput/RCTBaseTextInputView.h @@ -49,7 +49,7 @@ NS_ASSUME_NONNULL_BEGIN @property (nonatomic, assign) BOOL clearTextOnSubmit; @property (nonatomic, copy, nullable) RCTDirectEventBlock onSubmitEditing; @property (nonatomic, copy) NSArray *submitKeyEvents; -@property (nonatomic, strong, nullable) RCTUIColor *cursorColor; +@property (nonatomic, strong, nullable) RCTPlatformColor *cursorColor; #endif // macOS] @property (nonatomic, assign) NSInteger mostRecentEventCount; @property (nonatomic, assign, readonly) NSInteger nativeEventCount; diff --git a/packages/react-native/Libraries/Text/TextInput/RCTBaseTextInputView.mm b/packages/react-native/Libraries/Text/TextInput/RCTBaseTextInputView.mm index 207b5d51986d..572bf21ef4a3 100644 --- a/packages/react-native/Libraries/Text/TextInput/RCTBaseTextInputView.mm +++ b/packages/react-native/Libraries/Text/TextInput/RCTBaseTextInputView.mm @@ -127,7 +127,7 @@ - (void)enforceTextAttributesIfNeeded NSDictionary *textAttributes = [[_textAttributes effectiveTextAttributes] mutableCopy]; if ([textAttributes valueForKey:NSForegroundColorAttributeName] == nil) { - [textAttributes setValue:[RCTUIColor blackColor] forKey:NSForegroundColorAttributeName]; // [macOS] + [textAttributes setValue:[RCTPlatformColor blackColor] forKey:NSForegroundColorAttributeName]; // [macOS] } backedTextInputView.defaultTextAttributes = textAttributes; @@ -1071,7 +1071,7 @@ - (void)handleInputAccessoryDoneButton NSMutableDictionary *textAttributes = [backedTextInputView.defaultTextAttributes mutableCopy] ?: [NSMutableDictionary new]; - [textAttributes setValue:backedTextInputView.placeholderColor ?: [RCTUIColor placeholderTextColor] + [textAttributes setValue:backedTextInputView.placeholderColor ?: [RCTPlatformColor placeholderTextColor] forKey:NSForegroundColorAttributeName]; return textAttributes; diff --git a/packages/react-native/Libraries/Text/TextInput/Singleline/RCTUITextField.h b/packages/react-native/Libraries/Text/TextInput/Singleline/RCTUITextField.h index ff30d49d7f7f..1348056cac97 100644 --- a/packages/react-native/Libraries/Text/TextInput/Singleline/RCTUITextField.h +++ b/packages/react-native/Libraries/Text/TextInput/Singleline/RCTUITextField.h @@ -40,7 +40,7 @@ NS_ASSUME_NONNULL_BEGIN @property (nonatomic, assign) BOOL textWasPasted; #endif // macOS] @property (nonatomic, assign, readonly) BOOL dictationRecognizing; -@property (nonatomic, strong, nullable) RCTUIColor *placeholderColor; // [macOS] +@property (nonatomic, strong, nullable) RCTPlatformColor *placeholderColor; // [macOS] @property (nonatomic, assign) UIEdgeInsets textContainerInset; #if !TARGET_OS_OSX // [macOS] @property (nonatomic, assign, getter=isEditable) BOOL editable; @@ -66,7 +66,7 @@ NS_ASSUME_NONNULL_BEGIN @property (nonatomic, getter=isContinuousSpellCheckingEnabled) BOOL continuousSpellCheckingEnabled; @property (nonatomic, getter=isGrammarCheckingEnabled) BOOL grammarCheckingEnabled; @property (nonatomic, assign) BOOL enableFocusRing; -@property (nonatomic, strong, nullable) RCTUIColor *selectionColor; +@property (nonatomic, strong, nullable) RCTPlatformColor *selectionColor; @property (weak, nullable) id delegate; @property (nonatomic, assign) CGFloat pointScaleFactor; diff --git a/packages/react-native/Libraries/Text/TextInput/Singleline/RCTUITextField.mm b/packages/react-native/Libraries/Text/TextInput/Singleline/RCTUITextField.mm index c30fdfea6a27..eb8b559b99f5 100644 --- a/packages/react-native/Libraries/Text/TextInput/Singleline/RCTUITextField.mm +++ b/packages/react-native/Libraries/Text/TextInput/Singleline/RCTUITextField.mm @@ -29,8 +29,8 @@ @interface RCTUITextFieldCell : NSTextFieldCell @property (nonatomic, getter=isAutomaticSpellingCorrectionEnabled) BOOL automaticSpellingCorrectionEnabled; @property (nonatomic, getter=isContinuousSpellCheckingEnabled) BOOL continuousSpellCheckingEnabled; @property (nonatomic, getter=isGrammarCheckingEnabled) BOOL grammarCheckingEnabled; -@property (nonatomic, strong, nullable) RCTUIColor *selectionColor; -@property (nonatomic, strong, nullable) RCTUIColor *insertionPointColor; +@property (nonatomic, strong, nullable) RCTPlatformColor *selectionColor; +@property (nonatomic, strong, nullable) RCTPlatformColor *insertionPointColor; @end @@ -298,12 +298,12 @@ - (BOOL)isGrammarCheckingEnabled return ((RCTUITextFieldCell*)self.cell).isGrammarCheckingEnabled; } -- (void)setSelectionColor:(RCTUIColor *)selectionColor +- (void)setSelectionColor:(RCTPlatformColor *)selectionColor { ((RCTUITextFieldCell*)self.cell).selectionColor = selectionColor; } -- (RCTUIColor*)selectionColor +- (RCTPlatformColor*)selectionColor { return ((RCTUITextFieldCell*)self.cell).selectionColor; } @@ -313,7 +313,7 @@ - (void)setCursorColor:(NSColor *)cursorColor ((RCTUITextFieldCell*)self.cell).insertionPointColor = cursorColor; } -- (RCTUIColor*)cursorColor +- (RCTPlatformColor*)cursorColor { return ((RCTUITextFieldCell*)self.cell).insertionPointColor; } @@ -361,7 +361,7 @@ - (NSString*)placeholder // [macOS #endif } // macOS] -- (void)setPlaceholderColor:(RCTUIColor *)placeholderColor // [macOS] +- (void)setPlaceholderColor:(RCTPlatformColor *)placeholderColor // [macOS] { _placeholderColor = placeholderColor; [self _updatePlaceholder]; @@ -467,7 +467,7 @@ - (void)setDisableKeyboardShortcuts:(BOOL)disableKeyboardShortcuts NSMutableDictionary *textAttributes = [_defaultTextAttributes mutableCopy] ?: [NSMutableDictionary new]; - [textAttributes setValue:self.placeholderColor ?: [RCTUIColor placeholderTextColor] + [textAttributes setValue:self.placeholderColor ?: [RCTPlatformColor placeholderTextColor] forKey:NSForegroundColorAttributeName]; // [macOS] return textAttributes; diff --git a/packages/react-native/React/Base/RCTConvert.h b/packages/react-native/React/Base/RCTConvert.h index d0effa7c0a2e..19b12e92905f 100644 --- a/packages/react-native/React/Base/RCTConvert.h +++ b/packages/react-native/React/Base/RCTConvert.h @@ -109,15 +109,15 @@ typedef NSURL RCTFileURL; + (CGAffineTransform)CGAffineTransform:(id)json; -+ (RCTUIColor *)UIColorWithRed:(CGFloat)red green:(CGFloat)green blue:(CGFloat)blue alpha:(CGFloat)alpha; // [macOS] -+ (RCTUIColor *)UIColorWithRed:(CGFloat)red // [macOS] ++ (RCTPlatformColor *)UIColorWithRed:(CGFloat)red green:(CGFloat)green blue:(CGFloat)blue alpha:(CGFloat)alpha; // [macOS] ++ (RCTPlatformColor *)UIColorWithRed:(CGFloat)red // [macOS] green:(CGFloat)green blue:(CGFloat)blue alpha:(CGFloat)alpha andColorSpace:(RCTColorSpace)colorSpace; + (RCTColorSpace)RCTColorSpaceFromString:(NSString *)colorSpace; -+ (RCTUIColor *)UIColor:(id)json; // [macOS] -+ (RCTUIColor *)NSColor:(id)json; // [macOS] ++ (RCTPlatformColor *)UIColor:(id)json; // [macOS] ++ (RCTPlatformColor *)NSColor:(id)json; // [macOS] + (CGColorRef)CGColor:(id)json CF_RETURNS_NOT_RETAINED; + (YGValue)YGValue:(id)json; @@ -129,7 +129,7 @@ typedef NSURL RCTFileURL; + (NSArray *)NSURLArray:(id)json; + (NSArray *)RCTFileURLArray:(id)json; + (NSArray *)NSNumberArray:(id)json; -+ (NSArray *)UIColorArray:(id)json; // [macOS] ++ (NSArray *)UIColorArray:(id)json; // [macOS] #if TARGET_OS_OSX // [macOS + (NSArray *)NSPasteboardTypeArray:(id)json; #endif // macOS] diff --git a/packages/react-native/React/Base/RCTConvert.mm b/packages/react-native/React/Base/RCTConvert.mm index 09822246f927..c74482f5b131 100644 --- a/packages/react-native/React/Base/RCTConvert.mm +++ b/packages/react-native/React/Base/RCTConvert.mm @@ -976,10 +976,10 @@ + (UIEdgeInsets)UIEdgeInsets:(id)json /** Returns a UIColor based on a semantic color name. * Returns nil if the semantic color name is invalid. */ -static RCTUIColor *RCTColorFromSemanticColorName(NSString *semanticColorName) +static RCTPlatformColor *RCTColorFromSemanticColorName(NSString *semanticColorName) { NSDictionary *colorMap = RCTSemanticColorsMap(); - RCTUIColor *color = nil; + RCTPlatformColor *color = nil; NSDictionary *colorInfo = colorMap[semanticColorName]; if (colorInfo) { NSString *semanticColorSelector = colorInfo[RCTSelector]; @@ -987,7 +987,7 @@ + (UIEdgeInsets)UIEdgeInsets:(id)json semanticColorSelector = semanticColorName; } SEL selector = NSSelectorFromString(semanticColorSelector); - if (![RCTUIColor respondsToSelector:selector]) { + if (![RCTPlatformColor respondsToSelector:selector]) { NSNumber *fallbackRGB = colorInfo[RCTFallbackARGB]; if (fallbackRGB != nil) { RCTAssert([fallbackRGB isKindOfClass:[NSNumber class]], @"fallback ARGB is not a number"); @@ -996,12 +996,12 @@ + (UIEdgeInsets)UIEdgeInsets:(id)json semanticColorSelector = colorInfo[RCTFallback]; selector = NSSelectorFromString(semanticColorSelector); } - RCTAssert ([RCTUIColor respondsToSelector:selector], @"RCTUIColor does not respond to a semantic color selector."); - Class klass = [RCTUIColor class]; + RCTAssert ([RCTPlatformColor respondsToSelector:selector], @"RCTPlatformColor does not respond to a semantic color selector."); + Class klass = [RCTPlatformColor class]; IMP imp = [klass methodForSelector:selector]; id (*getSemanticColorObject)(id, SEL) = (id(*)(id, SEL))imp; id colorObject = getSemanticColorObject(klass, selector); - if ([colorObject isKindOfClass:[RCTUIColor class]]) { + if ([colorObject isKindOfClass:[RCTPlatformColor class]]) { color = colorObject; } else if ([colorObject isKindOfClass:[NSArray class]]) { NSArray *colors = colorObject; @@ -1048,21 +1048,21 @@ void RCTSetDefaultColorSpace(RCTColorSpace colorSpace) _defaultColorSpace = colorSpace; } -+ (RCTUIColor *)UIColorWithRed:(CGFloat)red green:(CGFloat)green blue:(CGFloat)blue alpha:(CGFloat)alpha // [macOS] ++ (RCTPlatformColor *)UIColorWithRed:(CGFloat)red green:(CGFloat)green blue:(CGFloat)blue alpha:(CGFloat)alpha // [macOS] { RCTColorSpace space = RCTGetDefaultColorSpace(); return [self UIColorWithRed:red green:green blue:blue alpha:alpha andColorSpace:space]; } -+ (RCTUIColor *)UIColorWithRed:(CGFloat)red // [macOS] ++ (RCTPlatformColor *)UIColorWithRed:(CGFloat)red // [macOS] green:(CGFloat)green blue:(CGFloat)blue alpha:(CGFloat)alpha andColorSpace:(RCTColorSpace)colorSpace { if (colorSpace == RCTColorSpaceDisplayP3) { - return [RCTUIColor colorWithDisplayP3Red:red green:green blue:blue alpha:alpha]; // [macOS] + return [RCTPlatformColor colorWithDisplayP3Red:red green:green blue:blue alpha:alpha]; // [macOS] } - return [RCTUIColor colorWithRed:red green:green blue:blue alpha:alpha]; // [macOS] + return [RCTPlatformColor colorWithRed:red green:green blue:blue alpha:alpha]; // [macOS] } + (RCTColorSpace)RCTColorSpaceFromString:(NSString *)colorSpace @@ -1102,7 +1102,7 @@ + (NSColor *)NSColor:(id)json #endif // TARGET_OS_OSX // macOS] -+ (RCTUIColor *)UIColor:(id)json // [macOS] ++ (RCTPlatformColor *)UIColor:(id)json // [macOS] { if (!json) { return nil; @@ -1135,7 +1135,7 @@ + (RCTUIColor *)UIColor:(id)json // [macOS] } else if ((value = [dictionary objectForKey:@"semantic"])) { if ([value isKindOfClass:[NSString class]]) { NSString *semanticName = value; - RCTUIColor *color = [RCTUIColor colorNamed:semanticName]; // [macOS] + RCTPlatformColor *color = [RCTPlatformColor colorNamed:semanticName]; // [macOS] if (color != nil) { return color; } @@ -1148,7 +1148,7 @@ + (RCTUIColor *)UIColor:(id)json // [macOS] return color; } else if ([value isKindOfClass:[NSArray class]]) { for (id name in value) { - RCTUIColor *color = [RCTUIColor colorNamed:name]; // [macOS] + RCTPlatformColor *color = [RCTPlatformColor colorNamed:name]; // [macOS] if (color != nil) { return color; } @@ -1169,13 +1169,13 @@ + (RCTUIColor *)UIColor:(id)json // [macOS] } else if ((value = [dictionary objectForKey:@"dynamic"])) { NSDictionary *appearances = value; id light = [appearances objectForKey:@"light"]; - RCTUIColor *lightColor = [RCTConvert UIColor:light]; + RCTPlatformColor *lightColor = [RCTConvert UIColor:light]; id dark = [appearances objectForKey:@"dark"]; - RCTUIColor *darkColor = [RCTConvert UIColor:dark]; // [macOS] + RCTPlatformColor *darkColor = [RCTConvert UIColor:dark]; // [macOS] id highContrastLight = [appearances objectForKey:@"highContrastLight"]; - RCTUIColor *highContrastLightColor = [RCTConvert UIColor:highContrastLight]; // [macOS] + RCTPlatformColor *highContrastLightColor = [RCTConvert UIColor:highContrastLight]; // [macOS] id highContrastDark = [appearances objectForKey:@"highContrastDark"]; - RCTUIColor *highContrastDarkColor = [RCTConvert UIColor:highContrastDark]; // [macOS] + RCTPlatformColor *highContrastDarkColor = [RCTConvert UIColor:highContrastDark]; // [macOS] if (lightColor != nil && darkColor != nil) { #if !TARGET_OS_OSX // [macOS] UIColor *color = [UIColor colorWithDynamicProvider:^UIColor *_Nonnull(UITraitCollection *_Nonnull collection) { @@ -1304,7 +1304,7 @@ + (YGValue)YGValue:(id)json RCT_ARRAY_CONVERTER(NSURL) RCT_ARRAY_CONVERTER(RCTFileURL) -RCT_ARRAY_CONVERTER(RCTUIColor) // [macOS] +RCT_ARRAY_CONVERTER(RCTPlatformColor) // [macOS] /** * This macro is used for creating converter functions for directly diff --git a/packages/react-native/React/Base/RCTUtils.h b/packages/react-native/React/Base/RCTUtils.h index ea38e8917743..3f336aa2f21e 100644 --- a/packages/react-native/React/Base/RCTUtils.h +++ b/packages/react-native/React/Base/RCTUtils.h @@ -92,7 +92,7 @@ RCT_EXTERN BOOL RCTRunningInAppExtension(void); #endif // [macOS] // Returns the shared UIApplication instance, or nil if running in an App Extension -RCT_EXTERN RCTUIApplication *__nullable RCTSharedApplication(void); // [macOS] +RCT_EXTERN RCTPlatformApplication *__nullable RCTSharedApplication(void); // [macOS] // Returns the current main window, useful if you need to access the root view // or view controller diff --git a/packages/react-native/React/Base/RCTUtils.mm b/packages/react-native/React/Base/RCTUtils.mm index 8c49dcd98b8b..d28c8da035f4 100644 --- a/packages/react-native/React/Base/RCTUtils.mm +++ b/packages/react-native/React/Base/RCTUtils.mm @@ -633,7 +633,7 @@ BOOL RCTRunningInAppExtension(void) } #endif // [macOS] -RCTUIApplication *__nullable RCTSharedApplication(void) // [macOS] +RCTPlatformApplication *__nullable RCTSharedApplication(void) // [macOS] { #if !TARGET_OS_OSX // [macOS] if (RCTRunningInAppExtension()) { diff --git a/packages/react-native/React/Base/Surface/SurfaceHostingView/RCTSurfaceHostingView.mm b/packages/react-native/React/Base/Surface/SurfaceHostingView/RCTSurfaceHostingView.mm index b2b984b51baf..89d491a2b9b9 100644 --- a/packages/react-native/React/Base/Surface/SurfaceHostingView/RCTSurfaceHostingView.mm +++ b/packages/react-native/React/Base/Surface/SurfaceHostingView/RCTSurfaceHostingView.mm @@ -48,7 +48,7 @@ - (instancetype)initWithSurface:(id)surface [self _updateViews]; // For backward compatibility with RCTRootView, set a color here instead of transparent (OS default). - self.backgroundColor = [RCTUIColor whiteColor]; // [macOS] + self.backgroundColor = [RCTPlatformColor whiteColor]; // [macOS] } return self; diff --git a/packages/react-native/React/CoreModules/RCTActionSheetManager.mm b/packages/react-native/React/CoreModules/RCTActionSheetManager.mm index 3177b768543e..2d3db7190e0f 100644 --- a/packages/react-native/React/CoreModules/RCTActionSheetManager.mm +++ b/packages/react-native/React/CoreModules/RCTActionSheetManager.mm @@ -339,7 +339,7 @@ - (void)presentSharingServicePicker:(NSSharingServicePicker *)picker }); NSString *userInterfaceStyle = [RCTConvert NSString:options.userInterfaceStyle()]; NSNumber *anchorViewTag = [RCTConvert NSNumber:options.anchor() ? @(*options.anchor()) : nil]; - RCTUIColor *tintColor = [RCTConvert RCTUIColor:options.tintColor() ? @(*options.tintColor()) : nil]; // [macOS] + RCTPlatformColor *tintColor = [RCTConvert RCTPlatformColor:options.tintColor() ? @(*options.tintColor()) : nil]; // [macOS] dispatch_async(dispatch_get_main_queue(), ^{ if (message) { diff --git a/packages/react-native/React/CoreModules/RCTDevLoadingView.mm b/packages/react-native/React/CoreModules/RCTDevLoadingView.mm index ff71221beb16..4eb05b280ccf 100644 --- a/packages/react-native/React/CoreModules/RCTDevLoadingView.mm +++ b/packages/react-native/React/CoreModules/RCTDevLoadingView.mm @@ -96,7 +96,7 @@ - (void)hideBannerAfter:(CGFloat)delay [self performSelector:@selector(hide) withObject:nil afterDelay:delay]; } -- (void)showMessage:(NSString *)message color:(RCTUIColor *)color backgroundColor:(RCTUIColor *)backgroundColor // [macOS] +- (void)showMessage:(NSString *)message color:(RCTPlatformColor *)color backgroundColor:(RCTPlatformColor *)backgroundColor // [macOS] { if (!RCTDevLoadingViewGetEnabled() || _hiding) { return; @@ -271,12 +271,12 @@ - (void)showProgressMessage:(NSString *)message return; } - RCTUIColor *color = [RCTUIColor whiteColor]; // [macOS] - RCTUIColor *backgroundColor = [RCTUIColor colorWithHue:105 saturation:0 brightness:.25 alpha:1]; // [macOS] + RCTPlatformColor *color = [RCTPlatformColor whiteColor]; // [macOS] + RCTPlatformColor *backgroundColor = [RCTPlatformColor colorWithHue:105 saturation:0 brightness:.25 alpha:1]; // [macOS] if ([self isDarkModeEnabled]) { - color = [RCTUIColor colorWithHue:208 saturation:0.03 brightness:.14 alpha:1]; // [macOS] - backgroundColor = [RCTUIColor colorWithHue:0 saturation:0 brightness:0.98 alpha:1]; // [macOS] + color = [RCTPlatformColor colorWithHue:208 saturation:0.03 brightness:.14 alpha:1]; // [macOS] + backgroundColor = [RCTPlatformColor colorWithHue:0 saturation:0 brightness:0.98 alpha:1]; // [macOS] } [self showMessage:message color:color backgroundColor:backgroundColor]; @@ -287,12 +287,12 @@ - (void)showOfflineMessage // [macOS isDarkModeEnabled should only be run on the main thread __weak __typeof(self) weakSelf = self; RCTExecuteOnMainQueue(^{ - RCTUIColor *color = [RCTUIColor whiteColor]; // [macOS] - RCTUIColor *backgroundColor = [RCTUIColor blackColor]; // [macOS] + RCTPlatformColor *color = [RCTPlatformColor whiteColor]; // [macOS] + RCTPlatformColor *backgroundColor = [RCTPlatformColor blackColor]; // [macOS] if ([weakSelf isDarkModeEnabled]) { - color = [RCTUIColor blackColor]; // [macOS] - backgroundColor = [RCTUIColor whiteColor]; // [macOS] + color = [RCTPlatformColor blackColor]; // [macOS] + backgroundColor = [RCTPlatformColor whiteColor]; // [macOS] } NSString *message = [NSString stringWithFormat:@"Connect to %@ to develop JavaScript.", RCT_PACKAGER_NAME]; @@ -357,7 +357,7 @@ + (NSString *)moduleName + (void)setEnabled:(BOOL)enabled { } -- (void)showMessage:(NSString *)message color:(RCTUIColor *)color backgroundColor:(RCTUIColor *)backgroundColor // [macOS] RCTUIColor +- (void)showMessage:(NSString *)message color:(RCTPlatformColor *)color backgroundColor:(RCTPlatformColor *)backgroundColor // [macOS] RCTPlatformColor { } - (void)showMessage:(NSString *)message withColor:(NSNumber *)color withBackgroundColor:(NSNumber *)backgroundColor diff --git a/packages/react-native/React/CoreModules/RCTFPSGraph.h b/packages/react-native/React/CoreModules/RCTFPSGraph.h index 73c141d53b2b..8d37fea7d6c8 100644 --- a/packages/react-native/React/CoreModules/RCTFPSGraph.h +++ b/packages/react-native/React/CoreModules/RCTFPSGraph.h @@ -17,7 +17,7 @@ @property (nonatomic, assign, readonly) NSUInteger maxFPS; @property (nonatomic, assign, readonly) NSUInteger minFPS; -- (instancetype)initWithFrame:(CGRect)frame color:(RCTUIColor *)color NS_DESIGNATED_INITIALIZER; // [macOS] +- (instancetype)initWithFrame:(CGRect)frame color:(RCTPlatformColor *)color NS_DESIGNATED_INITIALIZER; // [macOS] - (void)onTick:(NSTimeInterval)timestamp; diff --git a/packages/react-native/React/CoreModules/RCTFPSGraph.mm b/packages/react-native/React/CoreModules/RCTFPSGraph.mm index b0a4eabafe32..0dc54f4b5c6b 100644 --- a/packages/react-native/React/CoreModules/RCTFPSGraph.mm +++ b/packages/react-native/React/CoreModules/RCTFPSGraph.mm @@ -27,7 +27,7 @@ @implementation RCTFPSGraph { RCTUILabel *_label; // [macOS] CGFloat *_frames; - RCTUIColor *_color; // [macOS] + RCTPlatformColor *_color; // [macOS] NSTimeInterval _prevTime; NSUInteger _frameCount; @@ -39,7 +39,7 @@ @implementation RCTFPSGraph { CGFloat _scale; } -- (instancetype)initWithFrame:(CGRect)frame color:(RCTUIColor *)color // [macOS] +- (instancetype)initWithFrame:(CGRect)frame color:(RCTPlatformColor *)color // [macOS] { if ((self = [super initWithFrame:frame])) { #if TARGET_OS_OSX // [macOS diff --git a/packages/react-native/React/CoreModules/RCTPerfMonitor.mm b/packages/react-native/React/CoreModules/RCTPerfMonitor.mm index 2b8507f057d5..8a78d40792bc 100644 --- a/packages/react-native/React/CoreModules/RCTPerfMonitor.mm +++ b/packages/react-native/React/CoreModules/RCTPerfMonitor.mm @@ -73,7 +73,7 @@ @interface RCTPerfMonitor #if __has_include() @property (nonatomic, strong, readonly) RCTDevMenuItem *devMenuItem; #endif -@property (nonatomic, strong, readonly) RCTUIPanGestureRecognizer *gestureRecognizer; // [macOS] +@property (nonatomic, strong, readonly) RCTPlatformPanGestureRecognizer *gestureRecognizer; // [macOS] @property (nonatomic, strong, readonly) RCTPlatformView *container; // [macOS] #if TARGET_OS_OSX // [macOS @property (nonatomic, strong, readonly) NSWindow *containerWindow; @@ -93,7 +93,7 @@ @implementation RCTPerfMonitor { #if __has_include() RCTDevMenuItem *_devMenuItem; #endif - RCTUIPanGestureRecognizer *_gestureRecognizer; // [macOS] + RCTPlatformPanGestureRecognizer *_gestureRecognizer; // [macOS] RCTPlatformView *_container; // [macOS] #if !TARGET_OS_OSX // [macOS] UITableView *_metrics; @@ -175,10 +175,10 @@ - (RCTDevMenuItem *)devMenuItem } #endif -- (RCTUIPanGestureRecognizer *)gestureRecognizer // [macOS] +- (RCTPlatformPanGestureRecognizer *)gestureRecognizer // [macOS] { if (!_gestureRecognizer) { - _gestureRecognizer = [[RCTUIPanGestureRecognizer alloc] initWithTarget:self action:@selector(gesture:)]; + _gestureRecognizer = [[RCTPlatformPanGestureRecognizer alloc] initWithTarget:self action:@selector(gesture:)]; } return _gestureRecognizer; @@ -239,9 +239,9 @@ - (RCTFPSGraph *)uiGraph { if (!_uiGraph) { #if !TARGET_OS_OSX // [macOS] - _uiGraph = [[RCTFPSGraph alloc] initWithFrame:CGRectMake(134, 14, 40, 30) color:[RCTUIColor lightGrayColor]]; + _uiGraph = [[RCTFPSGraph alloc] initWithFrame:CGRectMake(134, 14, 40, 30) color:[RCTPlatformColor lightGrayColor]]; #else // [macOS - _uiGraph = [[RCTFPSGraph alloc] initWithFrame:CGRectMake(175, 14, 46, 30) color:[RCTUIColor lightGrayColor]]; + _uiGraph = [[RCTFPSGraph alloc] initWithFrame:CGRectMake(175, 14, 46, 30) color:[RCTPlatformColor lightGrayColor]]; _uiGraph.autoresizingMask = NSViewMinYMargin; #endif // macOS] } @@ -252,9 +252,9 @@ - (RCTFPSGraph *)jsGraph { if (!_jsGraph) { #if !TARGET_OS_OSX // [macOS] - _jsGraph = [[RCTFPSGraph alloc] initWithFrame:CGRectMake(178, 14, 40, 30) color:[RCTUIColor lightGrayColor]]; + _jsGraph = [[RCTFPSGraph alloc] initWithFrame:CGRectMake(178, 14, 40, 30) color:[RCTPlatformColor lightGrayColor]]; #else // [macOS - _jsGraph = [[RCTFPSGraph alloc] initWithFrame:CGRectMake(226, 14, 46, 30) color:[RCTUIColor lightGrayColor]]; + _jsGraph = [[RCTFPSGraph alloc] initWithFrame:CGRectMake(226, 14, 46, 30) color:[RCTPlatformColor lightGrayColor]]; _jsGraph.autoresizingMask = NSViewMinYMargin; #endif // macOS] } @@ -674,7 +674,7 @@ - (void)updateStats #endif // macOS] } -- (void)gesture:(RCTUIPanGestureRecognizer *)gestureRecognizer // [macOS] +- (void)gesture:(RCTPlatformPanGestureRecognizer *)gestureRecognizer // [macOS] { #if !TARGET_OS_OSX // [macOS] CGPoint translation = [gestureRecognizer translationInView:self.container.superview]; diff --git a/packages/react-native/React/DevSupport/RCTDevLoadingViewProtocol.h b/packages/react-native/React/DevSupport/RCTDevLoadingViewProtocol.h index 976b7ba421f2..4d3e06f58307 100644 --- a/packages/react-native/React/DevSupport/RCTDevLoadingViewProtocol.h +++ b/packages/react-native/React/DevSupport/RCTDevLoadingViewProtocol.h @@ -11,7 +11,7 @@ @protocol RCTDevLoadingViewProtocol + (void)setEnabled:(BOOL)enabled; -- (void)showMessage:(NSString *)message color:(RCTUIColor *)color backgroundColor:(RCTUIColor *)backgroundColor; // [macOS] +- (void)showMessage:(NSString *)message color:(RCTPlatformColor *)color backgroundColor:(RCTPlatformColor *)backgroundColor; // [macOS] - (void)showWithURL:(NSURL *)URL; - (void)updateProgress:(RCTLoadingProgress *)progress; - (void)hide; diff --git a/packages/react-native/React/DevSupport/RCTPausedInDebuggerOverlayController.mm b/packages/react-native/React/DevSupport/RCTPausedInDebuggerOverlayController.mm index 06181fdc1cf5..a045759a518d 100644 --- a/packages/react-native/React/DevSupport/RCTPausedInDebuggerOverlayController.mm +++ b/packages/react-native/React/DevSupport/RCTPausedInDebuggerOverlayController.mm @@ -46,7 +46,7 @@ - (void)viewDidLoad messageLabel.numberOfLines = 0; #endif // [macOS] messageLabel.font = [UIFont boldSystemFontOfSize:16]; - messageLabel.textColor = [RCTUIColor blackColor]; // [macOS] + messageLabel.textColor = [RCTPlatformColor blackColor]; // [macOS] messageLabel.translatesAutoresizingMaskIntoConstraints = NO; RCTUIView *messageContainer = [[RCTUIView alloc] init]; // [macOS] [messageContainer addSubview:messageLabel]; diff --git a/packages/react-native/React/Fabric/Mounting/ComponentViews/Text/RCTParagraphComponentView.mm b/packages/react-native/React/Fabric/Mounting/ComponentViews/Text/RCTParagraphComponentView.mm index dce3f15a2d07..b1beb6c931fe 100644 --- a/packages/react-native/React/Fabric/Mounting/ComponentViews/Text/RCTParagraphComponentView.mm +++ b/packages/react-native/React/Fabric/Mounting/ComponentViews/Text/RCTParagraphComponentView.mm @@ -70,7 +70,7 @@ - (instancetype)initWithFrame:(CGRect)frame self.opaque = NO; #endif // [macOS] _textView = [RCTParagraphTextView new]; - _textView.backgroundColor = RCTUIColor.clearColor; // [macOS] + _textView.backgroundColor = RCTPlatformColor.clearColor; // [macOS] self.contentView = _textView; } @@ -437,7 +437,7 @@ - (void)drawRect:(CGRect)rect if (highlightPath) { if (!self->_highlightLayer) { self->_highlightLayer = [CAShapeLayer layer]; - self->_highlightLayer.fillColor = [RCTUIColor colorWithWhite:0 alpha:0.25].CGColor; // [macOS] + self->_highlightLayer.fillColor = [RCTPlatformColor colorWithWhite:0 alpha:0.25].CGColor; // [macOS] [self.layer addSublayer:self->_highlightLayer]; } self->_highlightLayer.position = frame.origin; diff --git a/packages/react-native/React/Fabric/Mounting/ComponentViews/UnimplementedComponent/RCTUnimplementedNativeComponentView.mm b/packages/react-native/React/Fabric/Mounting/ComponentViews/UnimplementedComponent/RCTUnimplementedNativeComponentView.mm index c8255b15b7ea..51e3151b3dd9 100644 --- a/packages/react-native/React/Fabric/Mounting/ComponentViews/UnimplementedComponent/RCTUnimplementedNativeComponentView.mm +++ b/packages/react-native/React/Fabric/Mounting/ComponentViews/UnimplementedComponent/RCTUnimplementedNativeComponentView.mm @@ -24,14 +24,14 @@ - (instancetype)initWithFrame:(CGRect)frame CGRect bounds = self.bounds; _label = [[RCTUILabel alloc] initWithFrame:bounds]; // [macOS] - _label.backgroundColor = [RCTUIColor colorWithRed:1.0 green:0.0 blue:0.0 alpha:0.3]; + _label.backgroundColor = [RCTPlatformColor colorWithRed:1.0 green:0.0 blue:0.0 alpha:0.3]; #if !TARGET_OS_OSX // [macOS] _label.layoutMargins = UIEdgeInsetsMake(12, 12, 12, 12); #endif // [macOS] _label.lineBreakMode = NSLineBreakByWordWrapping; _label.numberOfLines = 0; _label.textAlignment = NSTextAlignmentCenter; - _label.textColor = [RCTUIColor whiteColor]; // [macOS] + _label.textColor = [RCTPlatformColor whiteColor]; // [macOS] #if !TARGET_OS_OSX // [macOS] self.contentView = _label; diff --git a/packages/react-native/React/Fabric/Mounting/ComponentViews/UnimplementedView/RCTUnimplementedViewComponentView.mm b/packages/react-native/React/Fabric/Mounting/ComponentViews/UnimplementedView/RCTUnimplementedViewComponentView.mm index 66e189b573f5..e18658f2f8b6 100644 --- a/packages/react-native/React/Fabric/Mounting/ComponentViews/UnimplementedView/RCTUnimplementedViewComponentView.mm +++ b/packages/react-native/React/Fabric/Mounting/ComponentViews/UnimplementedView/RCTUnimplementedViewComponentView.mm @@ -30,11 +30,11 @@ - (instancetype)initWithFrame:(CGRect)frame _props = UnimplementedViewShadowNode::defaultSharedProps(); _label = [[RCTUILabel alloc] initWithFrame:self.bounds]; - _label.backgroundColor = [RCTUIColor colorWithRed:1.0 green:0.0 blue:0.0 alpha:0.3]; + _label.backgroundColor = [RCTPlatformColor colorWithRed:1.0 green:0.0 blue:0.0 alpha:0.3]; _label.lineBreakMode = NSLineBreakByCharWrapping; _label.numberOfLines = 0; _label.textAlignment = NSTextAlignmentCenter; - _label.textColor = [RCTUIColor whiteColor]; + _label.textColor = [RCTPlatformColor whiteColor]; #if !TARGET_OS_OSX // [macOS] _label.allowsDefaultTighteningForTruncation = YES; _label.adjustsFontSizeToFitWidth = YES; diff --git a/packages/react-native/React/Fabric/Mounting/ComponentViews/View/RCTViewComponentView.mm b/packages/react-native/React/Fabric/Mounting/ComponentViews/View/RCTViewComponentView.mm index bb03d890157d..78b616a03a7a 100644 --- a/packages/react-native/React/Fabric/Mounting/ComponentViews/View/RCTViewComponentView.mm +++ b/packages/react-native/React/Fabric/Mounting/ComponentViews/View/RCTViewComponentView.mm @@ -45,7 +45,7 @@ const CGFloat BACKGROUND_COLOR_ZPOSITION = -1024.0f; @implementation RCTViewComponentView { - RCTUIColor *_backgroundColor; // [macOS] + RCTPlatformColor *_backgroundColor; // [macOS] CALayer *_backgroundColorLayer; __weak CALayer *_borderLayer; CALayer *_outlineLayer; @@ -131,12 +131,12 @@ - (BOOL)pointInside:(CGPoint)point withEvent:(UIEvent *)event return CGRectContainsPoint(hitFrame, point); } -- (RCTUIColor *)backgroundColor // [macOS] +- (RCTPlatformColor *)backgroundColor // [macOS] { return _backgroundColor; } -- (void)setBackgroundColor:(RCTUIColor *)backgroundColor // [macOS] +- (void)setBackgroundColor:(RCTPlatformColor *)backgroundColor // [macOS] { _backgroundColor = backgroundColor; } @@ -308,7 +308,7 @@ - (void)updateProps:(const Props::Shared &)props oldProps:(const Props::Shared & // `shadowColor` if (oldViewProps.shadowColor != newViewProps.shadowColor) { - RCTUIColor *shadowColor = RCTUIColorFromSharedColor(newViewProps.shadowColor); // [macOS] + RCTPlatformColor *shadowColor = RCTUIColorFromSharedColor(newViewProps.shadowColor); // [macOS] self.layer.shadowColor = shadowColor.CGColor; needsInvalidateLayer = YES; } @@ -872,7 +872,7 @@ static void RCTAddContourEffectToLayer( const RCTBorderStyle &contourStyle) { RCTUIImage *image = RCTGetBorderImage( // [macOS] - contourStyle, layer.bounds.size, cornerRadii, contourInsets, contourColors, [RCTUIColor clearColor], NO); // [macOS] + contourStyle, layer.bounds.size, cornerRadii, contourInsets, contourColors, [RCTPlatformColor clearColor], NO); // [macOS] if (image == nil) { layer.contents = nil; @@ -1175,9 +1175,9 @@ - (void)invalidateLayer // background color #if !TARGET_OS_OSX // [macOS] - RCTUIColor *backgroundColor = [_backgroundColor resolvedColorWithTraitCollection:self.traitCollection]; + RCTPlatformColor *backgroundColor = [_backgroundColor resolvedColorWithTraitCollection:self.traitCollection]; #else // [macOS - RCTUIColor *backgroundColor = _backgroundColor; + RCTPlatformColor *backgroundColor = _backgroundColor; #endif // macOS] // The reason we sometimes do not set self.layer's backgroundColor is because // we want to support non-uniform border radii, which apple does not natively @@ -1207,7 +1207,7 @@ - (void)invalidateLayer _borderLayer = nil; layer.borderWidth = (CGFloat)borderMetrics.borderWidths.left; - RCTUIColor *borderColor = RCTUIColorFromSharedColor(borderMetrics.borderColors.left); // [macOS] + RCTPlatformColor *borderColor = RCTUIColorFromSharedColor(borderMetrics.borderColors.left); // [macOS] layer.borderColor = borderColor.CGColor; layer.cornerRadius = (CGFloat)borderMetrics.borderRadii.topLeft.horizontal; @@ -1254,11 +1254,11 @@ - (void)invalidateLayer layer.bounds, -_props->outlineOffset - _props->outlineWidth, -_props->outlineOffset - _props->outlineWidth); if (borderMetrics.borderRadii.isUniform() && borderMetrics.borderRadii.topLeft.horizontal == 0) { - RCTUIColor *outlineColor = RCTUIColorFromSharedColor(_props->outlineColor); // [macOS] + RCTPlatformColor *outlineColor = RCTUIColorFromSharedColor(_props->outlineColor); // [macOS] _outlineLayer.borderWidth = _props->outlineWidth; _outlineLayer.borderColor = outlineColor.CGColor; } else { - RCTUIColor *outlineColor = RCTUIColorFromSharedColor(_props->outlineColor); // [macOS] + RCTPlatformColor *outlineColor = RCTUIColorFromSharedColor(_props->outlineColor); // [macOS] RCTAddContourEffectToLayer( _outlineLayer, @@ -1289,7 +1289,7 @@ - (void)invalidateLayer _filterLayer = [CALayer layer]; [self shapeLayerToMatchView:_filterLayer borderMetrics:borderMetrics]; _filterLayer.compositingFilter = @"multiplyBlendMode"; - _filterLayer.backgroundColor = [RCTUIColor colorWithRed:multiplicativeBrightness // [macOS] + _filterLayer.backgroundColor = [RCTPlatformColor colorWithRed:multiplicativeBrightness // [macOS] green:multiplicativeBrightness blue:multiplicativeBrightness alpha:self.layer.opacity] diff --git a/packages/react-native/React/Fabric/RCTConversions.h b/packages/react-native/React/Fabric/RCTConversions.h index 06fd8acdd2f7..22dbdc14e3d0 100644 --- a/packages/react-native/React/Fabric/RCTConversions.h +++ b/packages/react-native/React/Fabric/RCTConversions.h @@ -39,7 +39,7 @@ inline std::string RCTStringFromNSString(NSString *string) return std::string{string.UTF8String ?: ""}; } -inline RCTUIColor *_Nullable RCTUIColorFromSharedColor(const facebook::react::SharedColor &sharedColor) // [macOS] +inline RCTPlatformColor *_Nullable RCTUIColorFromSharedColor(const facebook::react::SharedColor &sharedColor) // [macOS] { return RCTPlatformColorFromColor(*sharedColor); } diff --git a/packages/react-native/React/Fabric/Utils/RCTBoxShadow.mm b/packages/react-native/React/Fabric/Utils/RCTBoxShadow.mm index 2b531dd906f3..1f338df64828 100644 --- a/packages/react-native/React/Fabric/Utils/RCTBoxShadow.mm +++ b/packages/react-native/React/Fabric/Utils/RCTBoxShadow.mm @@ -51,7 +51,7 @@ static CGRect insetRect(CGRect rect, CGFloat left, CGFloat top, CGFloat right, C static CGColorRef colorRefFromSharedColor(const SharedColor &color) { CGColorRef colorRef = RCTUIColorFromSharedColor(color).CGColor; - return colorRef ? colorRef : [RCTUIColor blackColor].CGColor; // [macOS] + return colorRef ? colorRef : [RCTPlatformColor blackColor].CGColor; // [macOS] } static CALayer *initBoxShadowLayer(const BoxShadow &shadow, CGSize layerSize) diff --git a/packages/react-native/React/Fabric/Utils/RCTGradientUtils.mm b/packages/react-native/React/Fabric/Utils/RCTGradientUtils.mm index 19c0fc38a3f6..bad94dcf0fc6 100644 --- a/packages/react-native/React/Fabric/Utils/RCTGradientUtils.mm +++ b/packages/react-native/React/Fabric/Utils/RCTGradientUtils.mm @@ -233,7 +233,7 @@ CGSize calculateMultipliers(CGSize bounds) auto leftColor = RCTUIColorFromSharedColor(leftSharedColor); auto rightColor = RCTUIColorFromSharedColor(rightSharedColor); NSArray *inputRange = @[ @0.0, @1.0 ]; - NSArray *outputRange = @[ leftColor, rightColor ]; // [macOS] + NSArray *outputRange = @[ leftColor, rightColor ]; // [macOS] for (auto &newStop : newStops) { auto pointRelativeOffset = (newStop.position.value() - offsetLeft) / totalDist; @@ -384,9 +384,9 @@ + (void)getColors:(NSMutableArray *)colors // To fix this, we detect when a color stop is transparent black and replace it with // a transparent version of the *previous* color stop. This creates a smooth fade-out effect // by only interpolating the alpha channel, matching web and Android behavior. - RCTUIColor *lastColor = nil; // [macOS] + RCTPlatformColor *lastColor = nil; // [macOS] for (const auto &colorStop : colorStops) { - RCTUIColor *currentColor = RCTUIColorFromSharedColor(colorStop.color); // [macOS] + RCTPlatformColor *currentColor = RCTUIColorFromSharedColor(colorStop.color); // [macOS] CGFloat red = 0.0; CGFloat green = 0.0; diff --git a/packages/react-native/React/RCTUIKit/RCTUIKitCompat.h b/packages/react-native/React/RCTUIKit/RCTUIKitCompat.h index b60aa0a818e0..8d056cff0ccd 100644 --- a/packages/react-native/React/RCTUIKit/RCTUIKitCompat.h +++ b/packages/react-native/React/RCTUIKit/RCTUIKitCompat.h @@ -86,7 +86,19 @@ NS_ASSUME_NONNULL_BEGIN // MARK: - Font type compatibility -#if TARGET_OS_OSX +#if !TARGET_OS_OSX + +UIKIT_STATIC_INLINE UIFont *UIFontWithSize(UIFont *font, CGFloat pointSize) +{ + return [font fontWithSize:pointSize]; +} + +UIKIT_STATIC_INLINE CGFloat UIFontLineHeight(UIFont *font) +{ + return font.lineHeight; +} + +#else // TARGET_OS_OSX // Both NSFont and UIFont are toll-free bridged to CTFontRef @compatibility_alias UIFont NSFont; diff --git a/packages/react-native/React/Views/RCTActivityIndicatorViewManager.m b/packages/react-native/React/Views/RCTActivityIndicatorViewManager.m index 7f33139f21a2..09d5e99f92af 100644 --- a/packages/react-native/React/Views/RCTActivityIndicatorViewManager.m +++ b/packages/react-native/React/Views/RCTActivityIndicatorViewManager.m @@ -40,7 +40,7 @@ - (RCTPlatformView *)view // [macOS] Setting activityIndicatorViewStyle overrides the color, so restore the original color after setting the indicator style. */ - RCTUIColor *oldColor = view.color; // [macOS] + RCTPlatformColor *oldColor = view.color; // [macOS] view.activityIndicatorViewStyle = json ? [RCTConvert UIActivityIndicatorViewStyle:json] : defaultView.activityIndicatorViewStyle; view.color = oldColor; diff --git a/packages/react-native/React/Views/RCTBorderDrawing.h b/packages/react-native/React/Views/RCTBorderDrawing.h index 5db1600403a7..277d0961e276 100644 --- a/packages/react-native/React/Views/RCTBorderDrawing.h +++ b/packages/react-native/React/Views/RCTBorderDrawing.h @@ -29,10 +29,10 @@ typedef struct { } RCTCornerInsets; typedef struct { - RCTUIColor *top; // [macOS] - RCTUIColor *left; // [macOS] - RCTUIColor *bottom; // [macOS] - RCTUIColor *right; // [macOS] + RCTPlatformColor *top; // [macOS] + RCTPlatformColor *left; // [macOS] + RCTPlatformColor *bottom; // [macOS] + RCTPlatformColor *right; // [macOS] } RCTBorderColors; /** @@ -76,5 +76,5 @@ RCT_EXTERN RCTUIImage *RCTGetBorderImage( // [macOS] RCTCornerRadii cornerRadii, UIEdgeInsets borderInsets, RCTBorderColors borderColors, - RCTUIColor *backgroundColor, // [macOS] + RCTPlatformColor *backgroundColor, // [macOS] BOOL drawToEdge); diff --git a/packages/react-native/React/Views/RCTBorderDrawing.m b/packages/react-native/React/Views/RCTBorderDrawing.m index b9ebea2bf78c..387aa55921cc 100644 --- a/packages/react-native/React/Views/RCTBorderDrawing.m +++ b/packages/react-native/React/Views/RCTBorderDrawing.m @@ -201,7 +201,7 @@ static CGPathRef RCTPathCreateOuterOutline(BOOL drawToEdge, CGRect rect, RCTCorn } static RCTUIGraphicsImageRenderer * // [macOS] -RCTMakeUIGraphicsImageRenderer(CGSize size, RCTUIColor *backgroundColor, BOOL hasCornerRadii, BOOL drawToEdge) // [macOS] +RCTMakeUIGraphicsImageRenderer(CGSize size, RCTPlatformColor *backgroundColor, BOOL hasCornerRadii, BOOL drawToEdge) // [macOS] { const CGFloat alpha = CGColorGetAlpha(backgroundColor.CGColor); const BOOL opaque = (drawToEdge || !hasCornerRadii) && alpha == 1.0; @@ -216,7 +216,7 @@ static CGPathRef RCTPathCreateOuterOutline(BOOL drawToEdge, CGRect rect, RCTCorn CGSize viewSize, UIEdgeInsets borderInsets, RCTBorderColors borderColors, - RCTUIColor *backgroundColor, // [macOS] + RCTPlatformColor *backgroundColor, // [macOS] BOOL drawToEdge) { const BOOL hasCornerRadii = RCTCornerRadiiAreAboveThreshold(cornerRadii); @@ -338,7 +338,7 @@ static CGPathRef RCTPathCreateOuterOutline(BOOL drawToEdge, CGRect rect, RCTCorn } } - RCTUIColor *currentColor = nil; // [macOS] + RCTPlatformColor *currentColor = nil; // [macOS] // RIGHT if (borderInsets.right > 0) { @@ -488,7 +488,7 @@ static CGPathRef RCTPathCreateOuterOutline(BOOL drawToEdge, CGRect rect, RCTCorn CGSize viewSize, UIEdgeInsets borderInsets, RCTBorderColors borderColors, - RCTUIColor *backgroundColor, // [macOS] + RCTPlatformColor *backgroundColor, // [macOS] BOOL drawToEdge) { NSCParameterAssert(borderStyle == RCTBorderStyleDashed || borderStyle == RCTBorderStyleDotted); @@ -565,7 +565,7 @@ static CGPathRef RCTPathCreateOuterOutline(BOOL drawToEdge, CGRect rect, RCTCorn CGContextSetLineWidth(context, lineWidth); CGContextSetLineDash(context, 0, dashLengths, sizeof(dashLengths) / sizeof(*dashLengths)); - CGContextSetStrokeColorWithColor(context, [RCTUIColor yellowColor].CGColor); // [macOS] + CGContextSetStrokeColorWithColor(context, [RCTPlatformColor yellowColor].CGColor); // [macOS] CGContextAddPath(context, path); CGContextSetStrokeColorWithColor(context, borderColors.top.CGColor); @@ -581,7 +581,7 @@ static CGPathRef RCTPathCreateOuterOutline(BOOL drawToEdge, CGRect rect, RCTCorn RCTCornerRadii cornerRadii, UIEdgeInsets borderInsets, RCTBorderColors borderColors, - RCTUIColor *backgroundColor, // [macOS] + RCTPlatformColor *backgroundColor, // [macOS] BOOL drawToEdge) { switch (borderStyle) { diff --git a/packages/react-native/React/Views/RCTDebuggingOverlay.m b/packages/react-native/React/Views/RCTDebuggingOverlay.m index 1bd2157de055..de8e183369c3 100644 --- a/packages/react-native/React/Views/RCTDebuggingOverlay.m +++ b/packages/react-native/React/Views/RCTDebuggingOverlay.m @@ -44,7 +44,7 @@ - (void)highlightTraceUpdates:(NSArray *)updates for (NSDictionary *update in updates) { NSNumber *identifier = [RCTConvert NSNumber:update[@"id"]]; NSDictionary *nodeRectangle = update[@"rectangle"]; - RCTUIColor *nodeColor = [RCTConvert RCTUIColor:update[@"color"]]; // [macOS] + RCTPlatformColor *nodeColor = [RCTConvert RCTPlatformColor:update[@"color"]]; // [macOS] CGRect rect = [RCTConvert CGRect:nodeRectangle]; @@ -72,7 +72,7 @@ - (void)highlightTraceUpdates:(NSArray *)updates } RCTUIView *box = [[RCTUIView alloc] initWithFrame:rect]; - box.backgroundColor = [RCTUIColor clearColor]; // [macOS] + box.backgroundColor = [RCTPlatformColor clearColor]; // [macOS] box.layer.borderWidth = 2.0f; box.layer.borderColor = nodeColor.CGColor; @@ -101,7 +101,7 @@ - (void)highlightElements:(NSArray *)rectangles for (NSDictionary *rectangle in rectangles) { RCTUIView *view = [[RCTUIView alloc] initWithFrame:[RCTConvert CGRect:rectangle]]; // [macOS] - view.backgroundColor = [RCTUIColor colorWithRed:200 / 255.0 green:230 / 255.0 blue:255 / 255.0 alpha:0.8]; // [macOS] + view.backgroundColor = [RCTPlatformColor colorWithRed:200 / 255.0 green:230 / 255.0 blue:255 / 255.0 alpha:0.8]; // [macOS] [self addSubview:view]; [_highlightedElements addObject:view]; } diff --git a/packages/react-native/React/Views/RCTView.h b/packages/react-native/React/Views/RCTView.h index fab2ec1f449d..257c13b9b3bc 100644 --- a/packages/react-native/React/Views/RCTView.h +++ b/packages/react-native/React/Views/RCTView.h @@ -99,16 +99,16 @@ extern const UIAccessibilityTraits SwitchAccessibilityTrait; /** * Border colors (actually retained). */ -@property (nonatomic, strong) RCTUIColor *borderTopColor; -@property (nonatomic, strong) RCTUIColor *borderRightColor; -@property (nonatomic, strong) RCTUIColor *borderBottomColor; -@property (nonatomic, strong) RCTUIColor *borderLeftColor; -@property (nonatomic, strong) RCTUIColor *borderStartColor; -@property (nonatomic, strong) RCTUIColor *borderEndColor; -@property (nonatomic, strong) RCTUIColor *borderColor; -@property (nonatomic, strong) RCTUIColor *borderBlockColor; -@property (nonatomic, strong) RCTUIColor *borderBlockEndColor; -@property (nonatomic, strong) RCTUIColor *borderBlockStartColor; +@property (nonatomic, strong) RCTPlatformColor *borderTopColor; +@property (nonatomic, strong) RCTPlatformColor *borderRightColor; +@property (nonatomic, strong) RCTPlatformColor *borderBottomColor; +@property (nonatomic, strong) RCTPlatformColor *borderLeftColor; +@property (nonatomic, strong) RCTPlatformColor *borderStartColor; +@property (nonatomic, strong) RCTPlatformColor *borderEndColor; +@property (nonatomic, strong) RCTPlatformColor *borderColor; +@property (nonatomic, strong) RCTPlatformColor *borderBlockColor; +@property (nonatomic, strong) RCTPlatformColor *borderBlockEndColor; +@property (nonatomic, strong) RCTPlatformColor *borderBlockStartColor; /** * Border widths. diff --git a/packages/react-native/React/Views/RCTView.m b/packages/react-native/React/Views/RCTView.m index a61582797d10..5562d9b4e20b 100644 --- a/packages/react-native/React/Views/RCTView.m +++ b/packages/react-native/React/Views/RCTView.m @@ -137,7 +137,7 @@ - (RCTPlatformView *)react_findClipView // [macOS] } @implementation RCTView { - RCTUIColor *_backgroundColor; // [macOS] + RCTPlatformColor *_backgroundColor; // [macOS] id _eventDispatcher; // [macOS] #if TARGET_OS_OSX // [macOS NSTrackingArea *_trackingArea; @@ -1020,12 +1020,12 @@ - (void)traitCollectionDidChange:(UITraitCollection *)previousTraitCollection #pragma mark - Borders -- (RCTUIColor *)backgroundColor // [macOS] RCTUIColor +- (RCTPlatformColor *)backgroundColor // [macOS] RCTPlatformColor { return _backgroundColor; } -- (void)setBackgroundColor:(RCTUIColor *)backgroundColor // macOS RCTUIColor +- (void)setBackgroundColor:(RCTPlatformColor *)backgroundColor // macOS RCTPlatformColor { if ([_backgroundColor isEqual:backgroundColor]) { return; @@ -1145,12 +1145,12 @@ - (RCTBorderColors)borderColors { const BOOL isRTL = _reactLayoutDirection == UIUserInterfaceLayoutDirectionRightToLeft; - RCTUIColor *directionAwareBorderLeftColor = nil; - RCTUIColor *directionAwareBorderRightColor = nil; + RCTPlatformColor *directionAwareBorderLeftColor = nil; + RCTPlatformColor *directionAwareBorderRightColor = nil; if ([[RCTI18nUtil sharedInstance] doLeftAndRightSwapInRTL]) { - RCTUIColor *borderStartColor = _borderStartColor ?: _borderLeftColor; // macOS RCTUIColor - RCTUIColor *borderEndColor = _borderEndColor ?: _borderRightColor; // macOS RCTUIColor + RCTPlatformColor *borderStartColor = _borderStartColor ?: _borderLeftColor; // macOS RCTPlatformColor + RCTPlatformColor *borderEndColor = _borderEndColor ?: _borderRightColor; // macOS RCTPlatformColor directionAwareBorderLeftColor = isRTL ? borderEndColor : borderStartColor; directionAwareBorderRightColor = isRTL ? borderStartColor : borderEndColor; @@ -1159,9 +1159,9 @@ - (RCTBorderColors)borderColors directionAwareBorderRightColor = (isRTL ? _borderStartColor : _borderEndColor) ?: _borderRightColor; } - RCTUIColor *borderColor = _borderColor; - RCTUIColor *borderTopColor = _borderTopColor; - RCTUIColor *borderBottomColor = _borderBottomColor; + RCTPlatformColor *borderColor = _borderColor; + RCTPlatformColor *borderTopColor = _borderTopColor; + RCTPlatformColor *borderBottomColor = _borderBottomColor; if (_borderBlockColor) { borderTopColor = _borderBlockColor; @@ -1244,9 +1244,9 @@ - (void)displayLayer:(CALayer *)layer // correctly clip the subviews. #if !TARGET_OS_OSX // [macOS] - RCTUIColor *backgroundColor = [_backgroundColor resolvedColorWithTraitCollection:self.traitCollection]; + RCTPlatformColor *backgroundColor = [_backgroundColor resolvedColorWithTraitCollection:self.traitCollection]; #else // [macOS - RCTUIColor *backgroundColor = _backgroundColor; + RCTPlatformColor *backgroundColor = _backgroundColor; #endif // macOS] #if TARGET_OS_OSX // [macOS @@ -1396,9 +1396,9 @@ - (void)updateClippingForLayer:(CALayer *)layer #pragma mark Border Color -// macOS RCTUIColor +// macOS RCTPlatformColor #define setBorderColor(side) \ - -(void)setBorder##side##Color : (RCTUIColor *)color \ + -(void)setBorder##side##Color : (RCTPlatformColor *)color \ { \ if ([_border##side##Color isEqual:color]) { \ return; \ diff --git a/packages/react-native/ReactCommon/react/renderer/graphics/platform/ios/react/renderer/graphics/HostPlatformColor.mm b/packages/react-native/ReactCommon/react/renderer/graphics/platform/ios/react/renderer/graphics/HostPlatformColor.mm index 0d6eaa9bb391..632e1c7e0db5 100644 --- a/packages/react-native/ReactCommon/react/renderer/graphics/platform/ios/react/renderer/graphics/HostPlatformColor.mm +++ b/packages/react-native/ReactCommon/react/renderer/graphics/platform/ios/react/renderer/graphics/HostPlatformColor.mm @@ -24,7 +24,7 @@ bool UIColorIsP3ColorSpace(const std::shared_ptr &uiColor) { - RCTUIColor *color = unwrapManagedObject(uiColor); // [macOS] + RCTPlatformColor *color = unwrapManagedObject(uiColor); // [macOS] CGColorSpaceRef colorSpace = CGColorGetColorSpace(color.CGColor); if (CGColorSpaceGetModel(colorSpace) == kCGColorSpaceModelRGB) { @@ -36,28 +36,28 @@ bool UIColorIsP3ColorSpace(const std::shared_ptr &uiColor) return false; } -RCTUIColor *_Nullable UIColorFromInt32(int32_t intColor) // [macOS] +RCTPlatformColor *_Nullable UIColorFromInt32(int32_t intColor) // [macOS] { CGFloat a = CGFloat((intColor >> 24) & 0xFF) / 255.0; CGFloat r = CGFloat((intColor >> 16) & 0xFF) / 255.0; CGFloat g = CGFloat((intColor >> 8) & 0xFF) / 255.0; CGFloat b = CGFloat(intColor & 0xFF) / 255.0; - RCTUIColor *color = [RCTUIColor colorWithRed:r green:g blue:b alpha:a]; // [macOS] + RCTPlatformColor *color = [RCTPlatformColor colorWithRed:r green:g blue:b alpha:a]; // [macOS] return color; } -RCTUIColor *_Nullable UIColorFromDynamicColor(const facebook::react::DynamicColor &dynamicColor) // [macOS] +RCTPlatformColor *_Nullable UIColorFromDynamicColor(const facebook::react::DynamicColor &dynamicColor) // [macOS] { int32_t light = dynamicColor.lightColor; int32_t dark = dynamicColor.darkColor; int32_t highContrastLight = dynamicColor.highContrastLightColor; int32_t highContrastDark = dynamicColor.highContrastDarkColor; - RCTUIColor *lightColor = UIColorFromInt32(light); // [macOS] - RCTUIColor *darkColor = UIColorFromInt32(dark); // [macOS] - RCTUIColor *highContrastLightColor = UIColorFromInt32(highContrastLight); // [macOS] - RCTUIColor *highContrastDarkColor = UIColorFromInt32(highContrastDark); // [macOS] + RCTPlatformColor *lightColor = UIColorFromInt32(light); // [macOS] + RCTPlatformColor *darkColor = UIColorFromInt32(dark); // [macOS] + RCTPlatformColor *highContrastLightColor = UIColorFromInt32(highContrastLight); // [macOS] + RCTPlatformColor *highContrastDarkColor = UIColorFromInt32(highContrastDark); // [macOS] if (lightColor != nil && darkColor != nil) { #if !TARGET_OS_OSX // [macOS] @@ -117,7 +117,7 @@ int32_t ColorFromColorComponents(const facebook::react::ColorComponents &compone return color; } -int32_t ColorFromUIColor(RCTUIColor *color) // [macOS] +int32_t ColorFromUIColor(RCTPlatformColor *color) // [macOS] { CGFloat rgba[4]; [color getRed:&rgba[0] green:&rgba[1] blue:&rgba[2] alpha:&rgba[3]]; @@ -129,7 +129,7 @@ int32_t ColorFromUIColorForSpecificTraitCollection( const std::shared_ptr &uiColor, UITraitCollection *traitCollection) { - RCTUIColor *color = (RCTUIColor *)unwrapManagedObject(uiColor); // [macOS] + RCTPlatformColor *color = (RCTPlatformColor *)unwrapManagedObject(uiColor); // [macOS] if (color) { color = [color resolvedColorWithTraitCollection:traitCollection]; return ColorFromUIColor(color); @@ -144,21 +144,21 @@ int32_t ColorFromUIColor(const std::shared_ptr &uiColor) #if !TARGET_OS_OSX // [macOS] return ColorFromUIColorForSpecificTraitCollection(uiColor, [UITraitCollection currentTraitCollection]); #else // [macOS - RCTUIColor *color = (RCTUIColor *)unwrapManagedObject(uiColor); + RCTPlatformColor *color = (RCTPlatformColor *)unwrapManagedObject(uiColor); return ColorFromUIColor(color); #endif // macOS] } -RCTUIColor *_Nullable UIColorFromComponentsColor(const facebook::react::ColorComponents &components) // [macOS] +RCTPlatformColor *_Nullable UIColorFromComponentsColor(const facebook::react::ColorComponents &components) // [macOS] { - RCTUIColor *uiColor = nil; // [macOS] + RCTPlatformColor *uiColor = nil; // [macOS] if (components.colorSpace == ColorSpace::DisplayP3) { - uiColor = [RCTUIColor colorWithDisplayP3Red:components.red // [macOS] + uiColor = [RCTPlatformColor colorWithDisplayP3Red:components.red // [macOS] green:components.green blue:components.blue alpha:components.alpha]; } else { - uiColor = [RCTUIColor colorWithRed:components.red green:components.green blue:components.blue alpha:components.alpha]; // [macOS] + uiColor = [RCTPlatformColor colorWithRed:components.red green:components.green blue:components.blue alpha:components.alpha]; // [macOS] } return uiColor; @@ -233,7 +233,7 @@ int32_t ColorFromUIColor(const std::shared_ptr &uiColor) Color::Color(std::shared_ptr uiColor) { - RCTUIColor *color = ((RCTUIColor *)unwrapManagedObject(uiColor)); // [macOS] + RCTPlatformColor *color = ((RCTPlatformColor *)unwrapManagedObject(uiColor)); // [macOS] if (color) { auto colorHash = hashFromUIColor(uiColor); uiColorHashValue_ = colorHash; @@ -260,7 +260,7 @@ int32_t ColorFromUIColor(const std::shared_ptr &uiColor) float Color::getChannel(int channelId) const { CGFloat rgba[4]; - RCTUIColor *color = (__bridge RCTUIColor *)getUIColor().get(); // [macOS] + RCTPlatformColor *color = (__bridge RCTPlatformColor *)getUIColor().get(); // [macOS] [color getRed:&rgba[0] green:&rgba[1] blue:&rgba[2] alpha:&rgba[3]]; return static_cast(rgba[channelId]); } diff --git a/packages/react-native/ReactCommon/react/renderer/graphics/platform/ios/react/renderer/graphics/RCTPlatformColorUtils.h b/packages/react-native/ReactCommon/react/renderer/graphics/platform/ios/react/renderer/graphics/RCTPlatformColorUtils.h index 77af7db36bd0..b9144e45e942 100644 --- a/packages/react-native/ReactCommon/react/renderer/graphics/platform/ios/react/renderer/graphics/RCTPlatformColorUtils.h +++ b/packages/react-native/ReactCommon/react/renderer/graphics/platform/ios/react/renderer/graphics/RCTPlatformColorUtils.h @@ -17,6 +17,6 @@ struct Color; facebook::react::ColorComponents RCTPlatformColorComponentsFromSemanticItems( std::vector& semanticItems); -RCTUIColor* RCTPlatformColorFromSemanticItems( // [macOS] +RCTPlatformColor* RCTPlatformColorFromSemanticItems( // [macOS] std::vector& semanticItems); -RCTUIColor* RCTPlatformColorFromColor(const facebook::react::Color& color); // [macOS] +RCTPlatformColor* RCTPlatformColorFromColor(const facebook::react::Color& color); // [macOS] diff --git a/packages/react-native/ReactCommon/react/renderer/graphics/platform/ios/react/renderer/graphics/RCTPlatformColorUtils.mm b/packages/react-native/ReactCommon/react/renderer/graphics/platform/ios/react/renderer/graphics/RCTPlatformColorUtils.mm index 403fa049ce75..7eaac5801fd1 100644 --- a/packages/react-native/ReactCommon/react/renderer/graphics/platform/ios/react/renderer/graphics/RCTPlatformColorUtils.mm +++ b/packages/react-native/ReactCommon/react/renderer/graphics/platform/ios/react/renderer/graphics/RCTPlatformColorUtils.mm @@ -134,7 +134,7 @@ return dict; } -static RCTUIColor *_UIColorFromHexValue(NSNumber *hexValue) // [macOS] +static RCTPlatformColor *_UIColorFromHexValue(NSNumber *hexValue) // [macOS] { NSUInteger hexIntValue = [hexValue unsignedIntegerValue]; @@ -143,10 +143,10 @@ CGFloat blue = ((CGFloat)((hexIntValue & 0xFF00) >> 8)) / 255.0; CGFloat alpha = ((CGFloat)(hexIntValue & 0xFF)) / 255.0; - return [RCTUIColor colorWithRed:red green:green blue:blue alpha:alpha]; // [macOS] + return [RCTPlatformColor colorWithRed:red green:green blue:blue alpha:alpha]; // [macOS] } -static RCTUIColor *_Nullable _UIColorFromSemanticString(NSString *semanticString) // [macOS] +static RCTPlatformColor *_Nullable _UIColorFromSemanticString(NSString *semanticString) // [macOS] { NSString *platformColorString = [semanticString hasSuffix:kColorSuffix] ? [semanticString substringToIndex:[semanticString length] - [kColorSuffix length]] @@ -155,17 +155,17 @@ NSDictionary *colorInfo = platformColorSelectorsDict[platformColorString]; if (colorInfo) { SEL objcColorSelector = NSSelectorFromString([platformColorString stringByAppendingString:kColorSuffix]); - if (![RCTUIColor respondsToSelector:objcColorSelector]) { // [macOS] + if (![RCTPlatformColor respondsToSelector:objcColorSelector]) { // [macOS] NSNumber *fallbackRGB = colorInfo[kFallbackARGBKey]; if (fallbackRGB) { return _UIColorFromHexValue(fallbackRGB); } } else { - Class uiColorClass = [RCTUIColor class]; // [macOS] + Class uiColorClass = [RCTPlatformColor class]; // [macOS] IMP imp = [uiColorClass methodForSelector:objcColorSelector]; id (*getUIColor)(id, SEL) = ((id(*)(id, SEL))imp); id colorObject = getUIColor(uiColorClass, objcColorSelector); - if ([colorObject isKindOfClass:[RCTUIColor class]]) { // [macOS] + if ([colorObject isKindOfClass:[RCTPlatformColor class]]) { // [macOS] return colorObject; } } @@ -180,7 +180,7 @@ return [NSString stringWithCString:string.c_str() encoding:encoding]; } -static inline facebook::react::ColorComponents _ColorComponentsFromUIColor(RCTUIColor *color) // [macOS] +static inline facebook::react::ColorComponents _ColorComponentsFromUIColor(RCTPlatformColor *color) // [macOS] { CGFloat rgba[4]; #if TARGET_OS_OSX // [macOS @@ -195,11 +195,11 @@ return _ColorComponentsFromUIColor(RCTPlatformColorFromSemanticItems(semanticItems)); } -RCTUIColor *RCTPlatformColorFromSemanticItems(std::vector &semanticItems) // [macOS] +RCTPlatformColor *RCTPlatformColorFromSemanticItems(std::vector &semanticItems) // [macOS] { for (const auto &semanticCString : semanticItems) { NSString *semanticNSString = _NSStringFromCString(semanticCString); - RCTUIColor *uiColor = [RCTUIColor colorNamed:semanticNSString]; // [macOS] + RCTPlatformColor *uiColor = [RCTPlatformColor colorNamed:semanticNSString]; // [macOS] if (uiColor != nil) { return uiColor; } @@ -209,12 +209,12 @@ } } - return RCTUIColor.clearColor; // [macOS] + return RCTPlatformColor.clearColor; // [macOS] } -RCTUIColor *RCTPlatformColorFromColor(const facebook::react::Color &color) // [macOS] +RCTPlatformColor *RCTPlatformColorFromColor(const facebook::react::Color &color) // [macOS] { - return (RCTUIColor *)facebook::react::unwrapManagedObject(color.getUIColor()); // [macOS] + return (RCTPlatformColor *)facebook::react::unwrapManagedObject(color.getUIColor()); // [macOS] } NS_ASSUME_NONNULL_END diff --git a/packages/react-native/ReactCommon/react/renderer/textlayoutmanager/platform/ios/react/renderer/textlayoutmanager/RCTAttributedTextUtils.mm b/packages/react-native/ReactCommon/react/renderer/textlayoutmanager/platform/ios/react/renderer/textlayoutmanager/RCTAttributedTextUtils.mm index 4ce0166e34ce..5ff1c376da8b 100644 --- a/packages/react-native/ReactCommon/react/renderer/textlayoutmanager/platform/ios/react/renderer/textlayoutmanager/RCTAttributedTextUtils.mm +++ b/packages/react-native/ReactCommon/react/renderer/textlayoutmanager/platform/ios/react/renderer/textlayoutmanager/RCTAttributedTextUtils.mm @@ -142,9 +142,9 @@ inline static CGFloat RCTEffectiveFontSizeMultiplierFromTextAttributes(const Tex return RCTFontWithFontProperties(fontProperties); } -inline static RCTUIColor *RCTEffectiveForegroundColorFromTextAttributes(const TextAttributes &textAttributes) // [macOS] +inline static RCTPlatformColor *RCTEffectiveForegroundColorFromTextAttributes(const TextAttributes &textAttributes) // [macOS] { - RCTUIColor *effectiveForegroundColor = RCTUIColorFromSharedColor(textAttributes.foregroundColor) ? RCTUIColorFromSharedColor(textAttributes.foregroundColor) : [RCTUIColor blackColor]; // [macOS] + RCTPlatformColor *effectiveForegroundColor = RCTUIColorFromSharedColor(textAttributes.foregroundColor) ? RCTUIColorFromSharedColor(textAttributes.foregroundColor) : [RCTPlatformColor blackColor]; // [macOS] if (!isnan(textAttributes.opacity)) { effectiveForegroundColor = [effectiveForegroundColor @@ -154,16 +154,16 @@ inline static CGFloat RCTEffectiveFontSizeMultiplierFromTextAttributes(const Tex return effectiveForegroundColor; } -inline static RCTUIColor *RCTEffectiveBackgroundColorFromTextAttributes(const TextAttributes &textAttributes) // [macOS] +inline static RCTPlatformColor *RCTEffectiveBackgroundColorFromTextAttributes(const TextAttributes &textAttributes) // [macOS] { - RCTUIColor *effectiveBackgroundColor = RCTUIColorFromSharedColor(textAttributes.backgroundColor); // [macOS] + RCTPlatformColor *effectiveBackgroundColor = RCTUIColorFromSharedColor(textAttributes.backgroundColor); // [macOS] if (effectiveBackgroundColor && !isnan(textAttributes.opacity)) { effectiveBackgroundColor = [effectiveBackgroundColor colorWithAlphaComponent:CGColorGetAlpha(effectiveBackgroundColor.CGColor) * textAttributes.opacity]; } - return effectiveBackgroundColor ? effectiveBackgroundColor : [RCTUIColor clearColor]; // [macOS] + return effectiveBackgroundColor ? effectiveBackgroundColor : [RCTPlatformColor clearColor]; // [macOS] } NSMutableDictionary *RCTNSTextAttributesFromTextAttributes( @@ -178,7 +178,7 @@ inline static CGFloat RCTEffectiveFontSizeMultiplierFromTextAttributes(const Tex } // Colors - RCTUIColor *effectiveForegroundColor = RCTEffectiveForegroundColorFromTextAttributes(textAttributes); // [macOS] + RCTPlatformColor *effectiveForegroundColor = RCTEffectiveForegroundColorFromTextAttributes(textAttributes); // [macOS] if (textAttributes.foregroundColor || !isnan(textAttributes.opacity)) { attributes[NSForegroundColorAttributeName] = effectiveForegroundColor; @@ -245,7 +245,7 @@ inline static CGFloat RCTEffectiveFontSizeMultiplierFromTextAttributes(const Tex NSUnderlineStyle style = RCTNSUnderlineStyleFromTextDecorationStyle( textAttributes.textDecorationStyle.value_or(TextDecorationStyle::Solid)); - RCTUIColor *textDecorationColor = RCTUIColorFromSharedColor(textAttributes.textDecorationColor); // [macOS] + RCTPlatformColor *textDecorationColor = RCTUIColorFromSharedColor(textAttributes.textDecorationColor); // [macOS] // Underline if (textDecorationLineType == TextDecorationLineType::Underline || diff --git a/packages/react-native/ReactCommon/react/renderer/textlayoutmanager/platform/ios/react/renderer/textlayoutmanager/RCTTextPrimitivesConversions.h b/packages/react-native/ReactCommon/react/renderer/textlayoutmanager/platform/ios/react/renderer/textlayoutmanager/RCTTextPrimitivesConversions.h index 14379fbd8b2a..1082488967ed 100644 --- a/packages/react-native/ReactCommon/react/renderer/textlayoutmanager/platform/ios/react/renderer/textlayoutmanager/RCTTextPrimitivesConversions.h +++ b/packages/react-native/ReactCommon/react/renderer/textlayoutmanager/platform/ios/react/renderer/textlayoutmanager/RCTTextPrimitivesConversions.h @@ -114,7 +114,7 @@ inline static NSUnderlineStyle RCTNSUnderlineStyleFromTextDecorationStyle( } // TODO: this file has some duplicates method, we can remove it -inline static RCTUIColor *_Nullable RCTUIColorFromSharedColor(const facebook::react::SharedColor &sharedColor) // [macOS] +inline static RCTPlatformColor *_Nullable RCTUIColorFromSharedColor(const facebook::react::SharedColor &sharedColor) // [macOS] { return RCTPlatformColorFromColor(*sharedColor); } diff --git a/packages/rn-tester/NativeComponentExample/ios/RNTLegacyView.mm b/packages/rn-tester/NativeComponentExample/ios/RNTLegacyView.mm index e728caa7a424..c0ad80692f3a 100644 --- a/packages/rn-tester/NativeComponentExample/ios/RNTLegacyView.mm +++ b/packages/rn-tester/NativeComponentExample/ios/RNTLegacyView.mm @@ -9,7 +9,7 @@ @implementation RNTLegacyView -- (void)setBackgroundColor:(RCTUIColor *)backgroundColor // [macOS] +- (void)setBackgroundColor:(RCTPlatformColor *)backgroundColor // [macOS] { super.backgroundColor = backgroundColor; [self emitEvent]; diff --git a/packages/rn-tester/NativeComponentExample/ios/RNTMyNativeViewCommon.mm b/packages/rn-tester/NativeComponentExample/ios/RNTMyNativeViewCommon.mm index 7e37a19f7c3e..f851f612c110 100644 --- a/packages/rn-tester/NativeComponentExample/ios/RNTMyNativeViewCommon.mm +++ b/packages/rn-tester/NativeComponentExample/ios/RNTMyNativeViewCommon.mm @@ -11,7 +11,7 @@ @implementation RCTPlatformView (ColorOverlays) // [macOS] - (void)setBackgroundColorWithColorString:(NSString *)colorString { - RCTUIColor *color = [RCTPlatformView RCTUIColorFromHexString:std::string([colorString UTF8String])]; // [macOS] + RCTPlatformColor *color = [RCTPlatformView RCTUIColorFromHexString:std::string([colorString UTF8String])]; // [macOS] #if !TARGET_OS_OSX // [macOS] self.backgroundColor = color; #else // [macOS @@ -28,7 +28,7 @@ - (void)addColorOverlays:(const NSArray *)overlayColors id colorString = [overlayColors objectAtIndex:i]; CGRect rect = CGRectMake(viewBounds.origin.x + width * i, viewBounds.origin.y, width, viewBounds.size.height); RCTUIView *overlayView = [[RCTUIView alloc] initWithFrame:rect]; // [macOS] - RCTUIColor *color = [RCTPlatformView RCTUIColorFromHexString:std::string([colorString UTF8String])]; // [macOS] + RCTPlatformColor *color = [RCTPlatformView RCTUIColorFromHexString:std::string([colorString UTF8String])]; // [macOS] overlayView.backgroundColor = color; [self addSubview:overlayView]; } @@ -42,14 +42,14 @@ - (void)removeOverlays } } -+ (RCTUIColor *)RCTUIColorFromHexString:(const std::string)hexString // [macOS] ++ (RCTPlatformColor *)RCTUIColorFromHexString:(const std::string)hexString // [macOS] { unsigned rgbValue = 0; NSString *colorString = [NSString stringWithCString:hexString.c_str() encoding:[NSString defaultCStringEncoding]]; NSScanner *scanner = [NSScanner scannerWithString:colorString]; [scanner setScanLocation:1]; // bypass '#' character [scanner scanHexInt:&rgbValue]; - return [RCTUIColor colorWithRed:((rgbValue & 0xFF0000) >> 16) / 255.0 // [macOS] + return [RCTPlatformColor colorWithRed:((rgbValue & 0xFF0000) >> 16) / 255.0 // [macOS] green:((rgbValue & 0xFF00) >> 8) / 255.0 blue:(rgbValue & 0xFF) / 255.0 alpha:1.0]; diff --git a/packages/rn-tester/NativeComponentExample/ios/UIView+ColorOverlays.h b/packages/rn-tester/NativeComponentExample/ios/UIView+ColorOverlays.h index 07cb6e5c8dcd..2d4c7e5992ff 100644 --- a/packages/rn-tester/NativeComponentExample/ios/UIView+ColorOverlays.h +++ b/packages/rn-tester/NativeComponentExample/ios/UIView+ColorOverlays.h @@ -16,7 +16,7 @@ NS_ASSUME_NONNULL_BEGIN - (void)setBackgroundColorWithColorString:(NSString *)colorString; - (void)addColorOverlays:(const NSArray *)overlayColors; - (void)removeOverlays; -+ (RCTUIColor *)RCTUIColorFromHexString:(const std::string)hexString; // [macOS] ++ (RCTPlatformColor *)RCTUIColorFromHexString:(const std::string)hexString; // [macOS] @end diff --git a/packages/rn-tester/Podfile.lock b/packages/rn-tester/Podfile.lock index 2505737d86a1..531bb9933da7 100644 --- a/packages/rn-tester/Podfile.lock +++ b/packages/rn-tester/Podfile.lock @@ -2679,7 +2679,7 @@ SPEC CHECKSUMS: boost: cea1d4f90a3a59537f3deb03ff5656489d7133dd DoubleConversion: d31b1eb37f6d6f456530c4fd9124b857d6889cab fast_float: 20817c22759af6ac8d4d67e6e059b8b499953656 - FBLazyVector: 8c5ed8f5f7c7fb2c618e9d8fe0306422afcab617 + FBLazyVector: 914c9db4fc55ebdf6ca840799db116f673245cff fmt: 24e7591456deb60b4a77518f83d9a916ac84223f glog: 0b31c25149b9d350b2666c7d459229861a00ec07 hermes-engine: 6685af7f27b851cd7fa2675bdeef4b291383b2fc @@ -2689,74 +2689,74 @@ SPEC CHECKSUMS: OSSLibraryExample: 5105eecb9aa325c0d65c59023fd8dc5f5753e777 RCT-Folly: c803cf33238782d5fd21a5e02d44f64068e0e130 RCTDeprecation: 3808e36294137f9ee5668f4df2e73dc079cd1dcf - RCTRequired: f93971b6cc77a578664f7509f4f6c58b6096a094 - RCTTypeSafety: 0c0a2f4cd381689b83b6933b706524eb76a2a226 - React: 3cc8a9580b6e9f2109c2539ba2190c58be234e80 - React-callinvoker: 774c76d5e58a379bce7394bd952b3b5cfa75ee10 - React-Core: 034463a78376ec032844f8824d9e550b7b1da4fc - React-CoreModules: d426931656374cf383b4df1a7a57cb3d4cf7dfdd - React-cxxreact: d497c307ad56be4249e4e15f06b34f42ed7e5f0b - React-debug: d70d452a59cdc0b9dc0a2db861af2fd8e213b36b - React-defaultsnativemodule: 211889c964131e6ff81862b7f836636ce46871c6 - React-domnativemodule: aad271fa1377d4c761ca229a2c6d5c9de073efc3 - React-Fabric: 65ff37ac5d0eca50df21e9b6ea768474543de319 - React-FabricComponents: 3ef86609a14c103d9d86aa23a61c17a98b933586 - React-FabricImage: 0813ce2e9a7909167f940216158a226f793ef136 - React-featureflags: cacfe0bdb0125de3be61fdc18423338c678f3928 - React-featureflagsnativemodule: 320b731777f63fecf3d8f02f2c88772583655703 - React-graphics: 7939999d67a64da09cb42852b6f15e05596ac43b - React-hermes: c0f7d4b10d52bb3233739208f812baf31918989d - React-idlecallbacksnativemodule: 5d00d2a0457b0f50e093533f3eba0aad53042b2a - React-ImageManager: 0354a97da2ed58b2bb4ffa32463128d99064bfc6 - React-jserrorhandler: ff0e479096c623526cabee9e21a6bbdac9dce131 - React-jsi: a373a9eaf6cda4eb170c7cae87d6d27e494a07f8 - React-jsiexecutor: 363898b2c3a90152febd9ce2eeb8142f74c95875 - React-jsinspector: ce7c3ed5d6f391db1c51fd6233e4579481cbc026 - React-jsinspectorcdp: 95423f556a880ae6d4b2f0b39a20da4e32279ae0 - React-jsinspectornetwork: 61358b75b6e9b849a04fa1a9958dd86bd1f9a702 - React-jsinspectortracing: eebe1f917431c533f473491de69f16f3437828ed - React-jsitooling: 77428d071e954964ed2d7e153b6a640bf3856470 - React-jsitracing: 8ed01231135aaab7b37a3e91718f77c99a56e4c3 - React-logger: fd877088e41c9bc7676c7f368d7532017490bbc6 - React-Mapbuffer: 723a6d94bba97cdbd13a16e9c9ec384fa4da614e - React-microtasksnativemodule: 21fd5ff14e724e1f11830704edf262444281859e - React-NativeModulesApple: f6786138047529478cdae334a6613aa17dbcc4c8 - React-oscompat: d50c6bf2aaa4879b127ddb8907c201116dc29a12 - React-perflogger: 0c27553522a8b4b0a550e6b9e8d3983de7ad438d - React-performancetimeline: 6a34c6c9fcf17cf2fac9656fcae2e49b9a9a2936 - React-RCTActionSheet: 3bb429b7b5f207451d10b13139f6fc1b5418c619 - React-RCTAnimation: 53a2c00048bb93829e9ab871d800700b70e11ede - React-RCTAppDelegate: e2aaf4cf98165d70cd2218ed5f363906c2bff00c - React-RCTBlob: 88f697ff93b3db3302e65957016924c37a544fbd - React-RCTFabric: efff0623f313cfb826b3ba8896a0d86499b2193e - React-RCTFBReactNativeSpec: 7213511e4f969f0bb7593db5011122e795c7740b - React-RCTImage: eb5d29d3f8e84d7a2881b1dd5d12e2922c610938 - React-RCTLinking: e6f0269a647fe4cf71f8f756982e89f1b4bb9c9b - React-RCTNetwork: f7277e742f7a52be134bea954556f3762178912a - React-RCTPushNotification: af51404ab0cc839bd720102bddbd210e7f5eb56d - React-RCTRuntime: 376a60f54d19d0b899200246400288ff8bfc09d1 - React-RCTSettings: 92f173e4fe16b0d972b51b9d4a15df859de41d94 - React-RCTTest: cd3aff303b3c10304b4bbb8673ad3cb1d2c4f35b - React-RCTText: f4f4d0db1c8a303d38e8b85b08611ee4480dec9a - React-RCTUIKit: a8978f14be89f4bc17583dc2c52690e773abfb6b - React-RCTVibration: 92af8da27749e46668a838d9cdb4b97142414943 - React-rendererconsistency: 1e28bd57632297b5231494c0d9a1e32e1d2b66de - React-renderercss: 377edccc6f20f23117d80f80b16f1b6225f872b6 - React-rendererdebug: 9ff20ef76861344ddcb98b3ac41ee9fe4b413219 - React-RuntimeApple: dd2c831382a27e503af9012f109429fe82462490 - React-RuntimeCore: 081cde412a4cd5a4b266c70690ec30a175a998ee - React-runtimeexecutor: 89588e3d01209f86fd0238428716b8e857607944 - React-RuntimeHermes: 544d6070bc18d8587e1256a365265bc7140515c7 - React-runtimescheduler: d5976056b0113fd18010a1833849cf94873d94e4 - React-timing: b1d02199cbb35bf942a83e9d31cd7bd9294e37a5 - React-utils: 1040f15d9700d3992e55538fd36a3acd00b3c7c1 - ReactAppDependencyProvider: 80d7267281c29ed383e27db51468fab09d27d2fd + RCTRequired: ea0ce8633d6bd7e3c6474d3671affae3341e4dc7 + RCTTypeSafety: 0629ffb01f0edb1007b32aaa6e313993562a6893 + React: 4468dbd5a20641f627fcb4da098a2959ed1bd9cb + React-callinvoker: eac6d4cbf1d95e509a9e8bd6bbf0d70608d97063 + React-Core: f9261760c6b89e90fbe496cfb05cd29cf756b347 + React-CoreModules: 573b5285aba4bf0f5ba4ed90c3154e60f212082c + React-cxxreact: 13a0435382a9dfa1af8f94ad8a994fc2c83e171f + React-debug: 1ead1100ad889e248091bd145cb650150e11eb40 + React-defaultsnativemodule: edfefda227f602dc0a907adbdcecd47507608803 + React-domnativemodule: 77cc8d1816fc4b20bf1f549bc0e0ae4cf6f781ec + React-Fabric: d340d3f80aad30de49568d1b7f28590b28f452ea + React-FabricComponents: dd98f05f41fd1200729aa4de15cda458be376251 + React-FabricImage: 981810518c96bae9c3f90c6dd06d5a9eb373aa20 + React-featureflags: e32ef5e8070fa566c75e161852b964956c4b12b0 + React-featureflagsnativemodule: 86cce3aa2b9435740cdf3a04a7cb91e4a1e3a82a + React-graphics: 95e8652a498eb47f1b5fc4defe85318c1ed7166b + React-hermes: 79a9a00278feaa6b20a21db5dfb84cd7e78d27e8 + React-idlecallbacksnativemodule: 800e3b67e01ec1b43f111d5a9a9667e2090c2009 + React-ImageManager: 4dc5dc21f06e8710dcb6b05086dc8ed4614d8fec + React-jserrorhandler: bc9e99354ecbd68695f1e2726d90d96c0129b99d + React-jsi: fed2a9198215b45687f5d0a582f16e345a675e68 + React-jsiexecutor: be0080da7cbcfd6b86b1d2b4444b23e4a50ace5e + React-jsinspector: 4c53022eea40f9a4546bdc69f978437c99d4f222 + React-jsinspectorcdp: 9c132f2ee0c42f279608e286c94be2ddd1e9cc3a + React-jsinspectornetwork: 67d88573d883db05960c41a929840289ba65dd11 + React-jsinspectortracing: d3d25aecb27a3858799cc4293ed631cef802ce99 + React-jsitooling: 164900ed1e98d6ce52e8096e267f1d242c4e23bc + React-jsitracing: a8e16db73af228f47c86afb79dea9be7a735876a + React-logger: 931720c7b8b8786e126ec069b098fe16742cb824 + React-Mapbuffer: 735b43b67aa6d0eea1f39182e23bc33dcc548699 + React-microtasksnativemodule: 3dc63757e5b21ac287de37d92eea35f683b7145c + React-NativeModulesApple: 7bae477d44227bda902a6ac05590844e7455115d + React-oscompat: 80e872d2625f973eacee8adc88f491454a5e1900 + React-perflogger: 4351d522c557181c56369a181f3d208fd2c78cad + React-performancetimeline: cd9556701b88f31ed18af19492d277522d4772dd + React-RCTActionSheet: 0f0d76589db7da427b44e4973e22956aadffa434 + React-RCTAnimation: 45a6cf9bf67118f08f5481ae1888c915be37d540 + React-RCTAppDelegate: bf80710894c7f7e17585d65d047cd0e6e77558c8 + React-RCTBlob: 93d024ab4466a70be207b7a20e2afc0da78bf3e3 + React-RCTFabric: bdbef4bc03e2171188e976a768d8fafa7d33630f + React-RCTFBReactNativeSpec: 7d23d9f871516227aa3fccd780bed6e3e4a0d77d + React-RCTImage: f6b28dd4189630bce8a039f6167e78c3e67b7c59 + React-RCTLinking: c3be6008e3d2a0a84d7661c1a0d7b0d7bb813c6a + React-RCTNetwork: b15ef021022e354019f16dc78ec510767cb6db53 + React-RCTPushNotification: 504a766c965ce3459b4d78ce5de7bc711bf24dba + React-RCTRuntime: 961130a0bc41666c5c0cbce53beb7a3384b6d400 + React-RCTSettings: 19975f8ba67e0bac7f3b5f69e7e0dc9acd7af8c3 + React-RCTTest: cdf3aa18823b16d0e4572b799f09c746d39504c6 + React-RCTText: 2fa09c9e8f7f8605fd2113a38ab68214a5491adf + React-RCTUIKit: b045d0d9f2696c4dc09ca10a005c4221b6d0090f + React-RCTVibration: cdf2714eec9a893b9805a3696f3e429f431104a8 + React-rendererconsistency: b8f70a4602de18127856ffa77ed6866332af18ec + React-renderercss: d68d39cc443fc4f7d5d8d93f0c3b72f9664d26a4 + React-rendererdebug: f2968ab1db44e216f748e7ea4f1e5923cfa2f305 + React-RuntimeApple: 8631c3424e7117cc4d16d1e593af92e507386b66 + React-RuntimeCore: b04d857177c31e10c70459d6517925391e56c026 + React-runtimeexecutor: 6e5d997f70de6c234d6690c0dfbee22e7dccf10a + React-RuntimeHermes: 23787b2235c01f955ad5000fa8fb39d468c35f40 + React-runtimescheduler: b92fad7442990dd8c631daf0fe167acd39114bdb + React-timing: ac4b31e7bf70419da58b8a785a9897315d8e1174 + React-utils: 61d631177cd2fd99b9a9a0542581637c68e7d293 + ReactAppDependencyProvider: 3c17f982e7f11d565b8f74e6087f681c7c1136b6 ReactCodegen: 45d2e543e9f1958ea9cf32b87ffa06b550db3683 - ReactCommon: 01209feeb08aa9830c07f39d6ed2f4e33f83a393 - ReactCommon-Samples: bebe8836e5cecae96a2763b68de8c0cffb210e7a + ReactCommon: ab506150f9eed0c6c25f026a08af7f111b0b1b97 + ReactCommon-Samples: 7b6f99c4187348cd1d5d14dbe0c1035d6dd8c252 ScreenshotManager: 10713952cbe264b56dfd36670e881ddd028daef5 SocketRocket: d4aabe649be1e368d1318fdf28a022d714d65748 - Yoga: f92c3c7550706b81e37925f9f035649e0a0312b0 + Yoga: 8e66b322d82c0b90948545deba6b4b29f3f4a587 PODFILE CHECKSUM: 86f155f7e9c92081bc7cd14b59aa0c1774a88f73 diff --git a/packages/rn-tester/RCTTest/FBSnapshotTestCase/UIImage+Diff.m b/packages/rn-tester/RCTTest/FBSnapshotTestCase/UIImage+Diff.m index 20592a2f6b06..49524dca2df9 100644 --- a/packages/rn-tester/RCTTest/FBSnapshotTestCase/UIImage+Diff.m +++ b/packages/rn-tester/RCTTest/FBSnapshotTestCase/UIImage+Diff.m @@ -28,7 +28,7 @@ - (RCTPlatformImage *)diffWithImage:(RCTPlatformImage *)image CGContextBeginTransparencyLayer(context, NULL); [image drawInRect:CGRectMake(0, 0, image.size.width, image.size.height)]; CGContextSetBlendMode(context, kCGBlendModeDifference); - CGContextSetFillColorWithColor(context, [RCTUIColor whiteColor].CGColor); + CGContextSetFillColorWithColor(context, [RCTPlatformColor whiteColor].CGColor); CGContextFillRect(context, CGRectMake(0, 0, self.size.width, self.size.height)); CGContextEndTransparencyLayer(context); }]; diff --git a/packages/rn-tester/RNTester/AppDelegate.mm b/packages/rn-tester/RNTester/AppDelegate.mm index 2af869ad7eb5..3bd5852584e5 100644 --- a/packages/rn-tester/RNTester/AppDelegate.mm +++ b/packages/rn-tester/RNTester/AppDelegate.mm @@ -120,14 +120,14 @@ - (BOOL)application:(UIApplication *)app } // Required for the remoteNotificationsRegistered event. -- (void)application:(__unused RCTUIApplication *)application +- (void)application:(__unused RCTPlatformApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken { [RCTPushNotificationManager didRegisterForRemoteNotificationsWithDeviceToken:deviceToken]; } // Required for the remoteNotificationRegistrationError event. -- (void)application:(__unused RCTUIApplication *)application +- (void)application:(__unused RCTPlatformApplication *)application didFailToRegisterForRemoteNotificationsWithError:(NSError *)error { [RCTPushNotificationManager didFailToRegisterForRemoteNotificationsWithError:error]; diff --git a/packages/rn-tester/RNTester/NativeExampleViews/FlexibleSizeExampleView.mm b/packages/rn-tester/RNTester/NativeExampleViews/FlexibleSizeExampleView.mm index 4d26ad68a21f..aa42148512d2 100644 --- a/packages/rn-tester/RNTester/NativeExampleViews/FlexibleSizeExampleView.mm +++ b/packages/rn-tester/RNTester/NativeExampleViews/FlexibleSizeExampleView.mm @@ -66,8 +66,8 @@ - (instancetype)initWithFrame:(CGRect)frame #else _currentSizeTextView.string = currentSizeTextViewString; #endif // macOS] - _currentSizeTextView.textColor = [RCTUIColor blackColor]; // [macOS] - _currentSizeTextView.backgroundColor = [RCTUIColor whiteColor]; // [macOS] + _currentSizeTextView.textColor = [RCTPlatformColor blackColor]; // [macOS] + _currentSizeTextView.backgroundColor = [RCTPlatformColor whiteColor]; // [macOS] _currentSizeTextView.font = [UIFont boldSystemFontOfSize:10]; _resizableRootView.delegate = self; diff --git a/packages/rn-tester/RNTesterUnitTests/RCTAnimationUtilsTests.m b/packages/rn-tester/RNTesterUnitTests/RCTAnimationUtilsTests.m index f2934bdb00ac..2b90b80ada63 100644 --- a/packages/rn-tester/RNTesterUnitTests/RCTAnimationUtilsTests.m +++ b/packages/rn-tester/RNTesterUnitTests/RCTAnimationUtilsTests.m @@ -98,15 +98,15 @@ - (void)testIdentityExtrapolate - (void)testColorInterpolation { NSArray *input = @[ @0, @1 ]; - NSArray *output = @[ [RCTUIColor redColor], [RCTUIColor blueColor] ]; // [macOS] + NSArray *output = @[ [RCTPlatformColor redColor], [RCTPlatformColor blueColor] ]; // [macOS] uint32_t value; value = RCTInterpolateColorInRange(0, input, output); - XCTAssertEqualObjects([RCTConvert UIColor:@(value)], [RCTUIColor redColor]); // [macOS] + XCTAssertEqualObjects([RCTConvert UIColor:@(value)], [RCTPlatformColor redColor]); // [macOS] value = RCTInterpolateColorInRange(0.5, input, output); XCTAssertEqualObjects( - [RCTConvert UIColor:@(value)], [RCTUIColor colorWithRed:128. / 255 green:0 blue:128. / 255 alpha:1]); // [macOS] + [RCTConvert UIColor:@(value)], [RCTPlatformColor colorWithRed:128. / 255 green:0 blue:128. / 255 alpha:1]); // [macOS] value = RCTInterpolateColorInRange(1, input, output); - XCTAssertEqualObjects([RCTConvert UIColor:@(value)], [RCTUIColor blueColor]); // [macOS] + XCTAssertEqualObjects([RCTConvert UIColor:@(value)], [RCTPlatformColor blueColor]); // [macOS] } - (void)testStringInterpolation diff --git a/packages/rn-tester/RNTesterUnitTests/RCTConvert_UIColorTests.m b/packages/rn-tester/RNTesterUnitTests/RCTConvert_UIColorTests.m index 47529c5f11a4..76aa91b0ccf7 100644 --- a/packages/rn-tester/RNTesterUnitTests/RCTConvert_UIColorTests.m +++ b/packages/rn-tester/RNTesterUnitTests/RCTConvert_UIColorTests.m @@ -57,7 +57,7 @@ - (void)testColorFailure errorMessage = message; }); - RCTUIColor *value = [RCTConvert UIColor:json]; // [macOS] + RCTPlatformColor *value = [RCTConvert UIColor:json]; // [macOS] RCTSetLogFunction(defaultLogFunction); @@ -69,8 +69,8 @@ - (void)testColorFailure - (void)testFallbackColor { id json = RCTJSONParse(@"{ \"semantic\": \"unitTestFallbackColorIOS\" }", nil); - RCTUIColor *value = [RCTConvert UIColor:json]; // [macOS] - XCTAssertTrue(CGColorsAreEqual([value CGColor], [[RCTUIColor blueColor] CGColor])); // [macOS] + RCTPlatformColor *value = [RCTConvert UIColor:json]; // [macOS] + XCTAssertTrue(CGColorsAreEqual([value CGColor], [[RCTPlatformColor blueColor] CGColor])); // [macOS] } #if !TARGET_OS_OSX // [macOS] @@ -79,7 +79,7 @@ - (void)testDynamicColor // 0 == 0x00000000 == black // 16777215 == 0x00FFFFFF == white id json = RCTJSONParse(@"{ \"dynamic\": { \"light\":0, \"dark\":16777215 } }", nil); - RCTUIColor *value = [RCTConvert RCTUIColor:json]; // [macOS] + RCTPlatformColor *value = [RCTConvert RCTPlatformColor:json]; // [macOS] XCTAssertNotNil(value); id savedTraitCollection = [UITraitCollection currentTraitCollection]; @@ -109,7 +109,7 @@ - (void)testCompositeDynamicColor id json = RCTJSONParse( @"{ \"dynamic\": { \"light\": { \"semantic\": \"systemRedColor\" }, \"dark\":{ \"semantic\": \"systemBlueColor\" } } }", nil); - RCTUIColor *value = [RCTConvert UIColor:json]; // [macOS] + RCTPlatformColor *value = [RCTConvert UIColor:json]; // [macOS] XCTAssertNotNil(value); id savedTraitCollection = [UITraitCollection currentTraitCollection]; @@ -178,7 +178,7 @@ - (void)testGenerateFallbacks for (NSString *semanticColor in semanticColors) { id json = RCTJSONParse([NSString stringWithFormat:@"{ \"semantic\": \"%@\" }", semanticColor], nil); - RCTUIColor *value = [RCTConvert UIColor:json]; // [macOS] + RCTPlatformColor *value = [RCTConvert UIColor:json]; // [macOS] XCTAssertNotNil(value); NSNumber *fallback = [semanticColors objectForKey:semanticColor]; From 81277708c5743da6efb61cae74f4d5c87dd6326f Mon Sep 17 00:00:00 2001 From: Saad Najmi Date: Tue, 10 Mar 2026 16:46:27 -0700 Subject: [PATCH 5/6] update copyright notice --- packages/react-native/React-Core.podspec | 4 ++-- packages/react-native/React-RCTUIKit.podspec | 6 ++---- .../react-native/React/RCTUIKit/RCTPlatformDisplayLink.h | 4 ++-- .../react-native/React/RCTUIKit/RCTPlatformDisplayLink.m | 2 +- .../react-native/React/RCTUIKit/RCTUIAccessibilityTraits.h | 2 +- .../React/RCTUIKit/RCTUIActivityIndicatorView.h | 2 +- .../React/RCTUIKit/RCTUIActivityIndicatorView.m | 2 +- packages/react-native/React/RCTUIKit/RCTUIGeometry.h | 2 +- packages/react-native/React/RCTUIKit/RCTUIGraphics.h | 2 +- packages/react-native/React/RCTUIKit/RCTUIGraphics.m | 2 +- .../React/RCTUIKit/RCTUIGraphicsImageRenderer.h | 2 +- .../React/RCTUIKit/RCTUIGraphicsImageRenderer.m | 2 +- packages/react-native/React/RCTUIKit/RCTUIImage.h | 2 +- packages/react-native/React/RCTUIKit/RCTUIImage.m | 2 +- packages/react-native/React/RCTUIKit/RCTUIImageView.h | 2 +- packages/react-native/React/RCTUIKit/RCTUIImageView.m | 2 +- packages/react-native/React/RCTUIKit/RCTUIKit.h | 2 +- packages/react-native/React/RCTUIKit/RCTUIKitCompat.h | 2 +- packages/react-native/React/RCTUIKit/RCTUILabel.h | 2 +- packages/react-native/React/RCTUIKit/RCTUILabel.m | 2 +- packages/react-native/React/RCTUIKit/RCTUIScrollView.h | 2 +- packages/react-native/React/RCTUIKit/RCTUIScrollView.m | 2 +- packages/react-native/React/RCTUIKit/RCTUISlider.h | 2 +- packages/react-native/React/RCTUIKit/RCTUISlider.m | 2 +- packages/react-native/React/RCTUIKit/RCTUISwitch.h | 2 +- packages/react-native/React/RCTUIKit/RCTUISwitch.m | 2 +- packages/react-native/React/RCTUIKit/RCTUITouch.h | 2 +- packages/react-native/React/RCTUIKit/RCTUIView.h | 2 +- packages/react-native/React/RCTUIKit/RCTUIView.m | 2 +- 29 files changed, 32 insertions(+), 34 deletions(-) diff --git a/packages/react-native/React-Core.podspec b/packages/react-native/React-Core.podspec index 35d03c3ec67b..a6c86283454a 100644 --- a/packages/react-native/React-Core.podspec +++ b/packages/react-native/React-Core.podspec @@ -75,7 +75,7 @@ Pod::Spec.new do |s| "React/Tests/**/*", "React/Inspector/**/*", "React/Runtime/**/*", - "React/RCTUIKit/**/*", + "React/RCTUIKit/**/*", # [macOS] ] # The default is use hermes, we don't have jsc installed @@ -115,7 +115,7 @@ Pod::Spec.new do |s| end end - s.dependency "React-RCTUIKit" + s.dependency "React-RCTUIKit" # [macOS] s.dependency "React-cxxreact" s.dependency "React-perflogger" s.dependency "React-jsi" diff --git a/packages/react-native/React-RCTUIKit.podspec b/packages/react-native/React-RCTUIKit.podspec index 88be7d10bc2f..1bae5cf333f3 100644 --- a/packages/react-native/React-RCTUIKit.podspec +++ b/packages/react-native/React-RCTUIKit.podspec @@ -1,4 +1,4 @@ -# Copyright (c) Meta Platforms, Inc. and affiliates. +# Copyright (c) Microsoft Corporation. # # This source code is licensed under the MIT license found in the # LICENSE file in the root directory of this source tree. @@ -22,7 +22,7 @@ Pod::Spec.new do |s| s.summary = "UIKit/AppKit compatibility layer for React Native macOS." s.homepage = "https://reactnative.dev/" s.license = package["license"] - s.author = "Meta Platforms, Inc. and its affiliates" + s.author = "Microsoft Corporation" s.platforms = min_supported_versions s.source = source s.source_files = podspec_sources( @@ -35,9 +35,7 @@ Pod::Spec.new do |s| "DEFINES_MODULE" => "YES", "CLANG_CXX_LANGUAGE_STANDARD" => rct_cxx_language_standard(), } - # [macOS Restrict UIKit to iOS and visionOS s.ios.framework = "UIKit" s.visionos.framework = "UIKit" s.osx.framework = "AppKit" - # macOS] end diff --git a/packages/react-native/React/RCTUIKit/RCTPlatformDisplayLink.h b/packages/react-native/React/RCTUIKit/RCTPlatformDisplayLink.h index 91a51ec6b23c..796def463758 100644 --- a/packages/react-native/React/RCTUIKit/RCTPlatformDisplayLink.h +++ b/packages/react-native/React/RCTUIKit/RCTPlatformDisplayLink.h @@ -1,5 +1,5 @@ -/** - * Copyright (c) 2015-present, Facebook, Inc. +/* + * Copyright (c) Microsoft Corporation. * * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. diff --git a/packages/react-native/React/RCTUIKit/RCTPlatformDisplayLink.m b/packages/react-native/React/RCTUIKit/RCTPlatformDisplayLink.m index 6082d4959904..c264c8512afe 100644 --- a/packages/react-native/React/RCTUIKit/RCTPlatformDisplayLink.m +++ b/packages/react-native/React/RCTUIKit/RCTPlatformDisplayLink.m @@ -1,5 +1,5 @@ /** - * Copyright (c) 2015-present, Facebook, Inc. + * Copyright (c) Microsoft Corporation. * * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. diff --git a/packages/react-native/React/RCTUIKit/RCTUIAccessibilityTraits.h b/packages/react-native/React/RCTUIKit/RCTUIAccessibilityTraits.h index 630b41112629..a1ffbbda1424 100644 --- a/packages/react-native/React/RCTUIKit/RCTUIAccessibilityTraits.h +++ b/packages/react-native/React/RCTUIKit/RCTUIAccessibilityTraits.h @@ -1,5 +1,5 @@ /* - * Copyright (c) Meta Platforms, Inc. and affiliates. + * Copyright (c) Microsoft Corporation. * * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. diff --git a/packages/react-native/React/RCTUIKit/RCTUIActivityIndicatorView.h b/packages/react-native/React/RCTUIKit/RCTUIActivityIndicatorView.h index 054cf5ef11e0..31099f011089 100644 --- a/packages/react-native/React/RCTUIKit/RCTUIActivityIndicatorView.h +++ b/packages/react-native/React/RCTUIKit/RCTUIActivityIndicatorView.h @@ -1,5 +1,5 @@ /* - * Copyright (c) Meta Platforms, Inc. and affiliates. + * Copyright (c) Microsoft Corporation. * * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. diff --git a/packages/react-native/React/RCTUIKit/RCTUIActivityIndicatorView.m b/packages/react-native/React/RCTUIKit/RCTUIActivityIndicatorView.m index b608e5703794..f7963452d2fd 100644 --- a/packages/react-native/React/RCTUIKit/RCTUIActivityIndicatorView.m +++ b/packages/react-native/React/RCTUIKit/RCTUIActivityIndicatorView.m @@ -1,5 +1,5 @@ /** - * Copyright (c) 2015-present, Facebook, Inc. + * Copyright (c) Microsoft Corporation. * * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. diff --git a/packages/react-native/React/RCTUIKit/RCTUIGeometry.h b/packages/react-native/React/RCTUIKit/RCTUIGeometry.h index 65dcdfe5c9cc..3cc0db87169a 100644 --- a/packages/react-native/React/RCTUIKit/RCTUIGeometry.h +++ b/packages/react-native/React/RCTUIKit/RCTUIGeometry.h @@ -1,5 +1,5 @@ /* - * Copyright (c) Meta Platforms, Inc. and affiliates. + * Copyright (c) Microsoft Corporation. * * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. diff --git a/packages/react-native/React/RCTUIKit/RCTUIGraphics.h b/packages/react-native/React/RCTUIKit/RCTUIGraphics.h index 2161acb66df0..cbce11b00ea0 100644 --- a/packages/react-native/React/RCTUIKit/RCTUIGraphics.h +++ b/packages/react-native/React/RCTUIKit/RCTUIGraphics.h @@ -1,5 +1,5 @@ /* - * Copyright (c) Meta Platforms, Inc. and affiliates. + * Copyright (c) Microsoft Corporation. * * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. diff --git a/packages/react-native/React/RCTUIKit/RCTUIGraphics.m b/packages/react-native/React/RCTUIKit/RCTUIGraphics.m index 1dbd2ff10814..d38f951f79bc 100644 --- a/packages/react-native/React/RCTUIKit/RCTUIGraphics.m +++ b/packages/react-native/React/RCTUIKit/RCTUIGraphics.m @@ -1,5 +1,5 @@ /** - * Copyright (c) 2015-present, Facebook, Inc. + * Copyright (c) Microsoft Corporation. * * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. diff --git a/packages/react-native/React/RCTUIKit/RCTUIGraphicsImageRenderer.h b/packages/react-native/React/RCTUIKit/RCTUIGraphicsImageRenderer.h index 2ad1761c2d86..0fa256c6004f 100644 --- a/packages/react-native/React/RCTUIKit/RCTUIGraphicsImageRenderer.h +++ b/packages/react-native/React/RCTUIKit/RCTUIGraphicsImageRenderer.h @@ -1,5 +1,5 @@ /* - * Copyright (c) Meta Platforms, Inc. and affiliates. + * Copyright (c) Microsoft Corporation. * * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. diff --git a/packages/react-native/React/RCTUIKit/RCTUIGraphicsImageRenderer.m b/packages/react-native/React/RCTUIKit/RCTUIGraphicsImageRenderer.m index 58cd8cdd09fe..95c420b3b30b 100644 --- a/packages/react-native/React/RCTUIKit/RCTUIGraphicsImageRenderer.m +++ b/packages/react-native/React/RCTUIKit/RCTUIGraphicsImageRenderer.m @@ -1,5 +1,5 @@ /** - * Copyright (c) 2015-present, Facebook, Inc. + * Copyright (c) Microsoft Corporation. * * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. diff --git a/packages/react-native/React/RCTUIKit/RCTUIImage.h b/packages/react-native/React/RCTUIKit/RCTUIImage.h index e5483c81ca22..f8289c0b648d 100644 --- a/packages/react-native/React/RCTUIKit/RCTUIImage.h +++ b/packages/react-native/React/RCTUIKit/RCTUIImage.h @@ -1,5 +1,5 @@ /* - * Copyright (c) Meta Platforms, Inc. and affiliates. + * Copyright (c) Microsoft Corporation. * * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. diff --git a/packages/react-native/React/RCTUIKit/RCTUIImage.m b/packages/react-native/React/RCTUIKit/RCTUIImage.m index 3995667e21ca..b851a4198c41 100644 --- a/packages/react-native/React/RCTUIKit/RCTUIImage.m +++ b/packages/react-native/React/RCTUIKit/RCTUIImage.m @@ -1,5 +1,5 @@ /** - * Copyright (c) 2015-present, Facebook, Inc. + * Copyright (c) Microsoft Corporation. * * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. diff --git a/packages/react-native/React/RCTUIKit/RCTUIImageView.h b/packages/react-native/React/RCTUIKit/RCTUIImageView.h index e4bd90440e26..70d435ed5568 100644 --- a/packages/react-native/React/RCTUIKit/RCTUIImageView.h +++ b/packages/react-native/React/RCTUIKit/RCTUIImageView.h @@ -1,5 +1,5 @@ /* - * Copyright (c) Meta Platforms, Inc. and affiliates. + * Copyright (c) Microsoft Corporation. * * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. diff --git a/packages/react-native/React/RCTUIKit/RCTUIImageView.m b/packages/react-native/React/RCTUIKit/RCTUIImageView.m index 4e064a581082..d2c4a4d892ab 100644 --- a/packages/react-native/React/RCTUIKit/RCTUIImageView.m +++ b/packages/react-native/React/RCTUIKit/RCTUIImageView.m @@ -1,5 +1,5 @@ /** - * Copyright (c) 2015-present, Facebook, Inc. + * Copyright (c) Microsoft Corporation. * * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. diff --git a/packages/react-native/React/RCTUIKit/RCTUIKit.h b/packages/react-native/React/RCTUIKit/RCTUIKit.h index 2933ca068fdd..3a9c635ffc69 100644 --- a/packages/react-native/React/RCTUIKit/RCTUIKit.h +++ b/packages/react-native/React/RCTUIKit/RCTUIKit.h @@ -1,5 +1,5 @@ /* - * Copyright (c) Meta Platforms, Inc. and affiliates. + * Copyright (c) Microsoft Corporation. * * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. diff --git a/packages/react-native/React/RCTUIKit/RCTUIKitCompat.h b/packages/react-native/React/RCTUIKit/RCTUIKitCompat.h index 8d056cff0ccd..11248cfe22e5 100644 --- a/packages/react-native/React/RCTUIKit/RCTUIKitCompat.h +++ b/packages/react-native/React/RCTUIKit/RCTUIKitCompat.h @@ -1,5 +1,5 @@ /* - * Copyright (c) Meta Platforms, Inc. and affiliates. + * Copyright (c) Microsoft Corporation. * * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. diff --git a/packages/react-native/React/RCTUIKit/RCTUILabel.h b/packages/react-native/React/RCTUIKit/RCTUILabel.h index 4dce1302ce66..71d993a4167f 100644 --- a/packages/react-native/React/RCTUIKit/RCTUILabel.h +++ b/packages/react-native/React/RCTUIKit/RCTUILabel.h @@ -1,5 +1,5 @@ /* - * Copyright (c) Meta Platforms, Inc. and affiliates. + * Copyright (c) Microsoft Corporation. * * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. diff --git a/packages/react-native/React/RCTUIKit/RCTUILabel.m b/packages/react-native/React/RCTUIKit/RCTUILabel.m index 6f95938c5a35..b0b6da79f8d6 100644 --- a/packages/react-native/React/RCTUIKit/RCTUILabel.m +++ b/packages/react-native/React/RCTUIKit/RCTUILabel.m @@ -1,5 +1,5 @@ /** - * Copyright (c) 2015-present, Facebook, Inc. + * Copyright (c) Microsoft Corporation. * * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. diff --git a/packages/react-native/React/RCTUIKit/RCTUIScrollView.h b/packages/react-native/React/RCTUIKit/RCTUIScrollView.h index 31bce195e46c..3cba8e590093 100644 --- a/packages/react-native/React/RCTUIKit/RCTUIScrollView.h +++ b/packages/react-native/React/RCTUIKit/RCTUIScrollView.h @@ -1,5 +1,5 @@ /* - * Copyright (c) Meta Platforms, Inc. and affiliates. + * Copyright (c) Microsoft Corporation. * * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. diff --git a/packages/react-native/React/RCTUIKit/RCTUIScrollView.m b/packages/react-native/React/RCTUIKit/RCTUIScrollView.m index c08e827a81fb..bdbc0c32610d 100644 --- a/packages/react-native/React/RCTUIKit/RCTUIScrollView.m +++ b/packages/react-native/React/RCTUIKit/RCTUIScrollView.m @@ -1,5 +1,5 @@ /** - * Copyright (c) 2015-present, Facebook, Inc. + * Copyright (c) Microsoft Corporation. * * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. diff --git a/packages/react-native/React/RCTUIKit/RCTUISlider.h b/packages/react-native/React/RCTUIKit/RCTUISlider.h index 833ef04ce77c..6290137497a5 100644 --- a/packages/react-native/React/RCTUIKit/RCTUISlider.h +++ b/packages/react-native/React/RCTUIKit/RCTUISlider.h @@ -1,5 +1,5 @@ /* - * Copyright (c) Meta Platforms, Inc. and affiliates. + * Copyright (c) Microsoft Corporation. * * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. diff --git a/packages/react-native/React/RCTUIKit/RCTUISlider.m b/packages/react-native/React/RCTUIKit/RCTUISlider.m index bfe8ad9276da..36e78475becb 100644 --- a/packages/react-native/React/RCTUIKit/RCTUISlider.m +++ b/packages/react-native/React/RCTUIKit/RCTUISlider.m @@ -1,5 +1,5 @@ /** - * Copyright (c) 2015-present, Facebook, Inc. + * Copyright (c) Microsoft Corporation. * * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. diff --git a/packages/react-native/React/RCTUIKit/RCTUISwitch.h b/packages/react-native/React/RCTUIKit/RCTUISwitch.h index 8657d00c39ce..5e27ef223350 100644 --- a/packages/react-native/React/RCTUIKit/RCTUISwitch.h +++ b/packages/react-native/React/RCTUIKit/RCTUISwitch.h @@ -1,5 +1,5 @@ /* - * Copyright (c) Meta Platforms, Inc. and affiliates. + * Copyright (c) Microsoft Corporation. * * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. diff --git a/packages/react-native/React/RCTUIKit/RCTUISwitch.m b/packages/react-native/React/RCTUIKit/RCTUISwitch.m index 7533180f22a0..04d6918cf00c 100644 --- a/packages/react-native/React/RCTUIKit/RCTUISwitch.m +++ b/packages/react-native/React/RCTUIKit/RCTUISwitch.m @@ -1,5 +1,5 @@ /** - * Copyright (c) 2015-present, Facebook, Inc. + * Copyright (c) Microsoft Corporation. * * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. diff --git a/packages/react-native/React/RCTUIKit/RCTUITouch.h b/packages/react-native/React/RCTUIKit/RCTUITouch.h index 45f2518efd5c..eb811a1345d5 100644 --- a/packages/react-native/React/RCTUIKit/RCTUITouch.h +++ b/packages/react-native/React/RCTUIKit/RCTUITouch.h @@ -1,5 +1,5 @@ /* - * Copyright (c) Meta Platforms, Inc. and affiliates. + * Copyright (c) Microsoft Corporation. * * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. diff --git a/packages/react-native/React/RCTUIKit/RCTUIView.h b/packages/react-native/React/RCTUIKit/RCTUIView.h index 7579666ceaac..4ecb82a3d164 100644 --- a/packages/react-native/React/RCTUIKit/RCTUIView.h +++ b/packages/react-native/React/RCTUIKit/RCTUIView.h @@ -1,5 +1,5 @@ /* - * Copyright (c) Meta Platforms, Inc. and affiliates. + * Copyright (c) Microsoft Corporation. * * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. diff --git a/packages/react-native/React/RCTUIKit/RCTUIView.m b/packages/react-native/React/RCTUIKit/RCTUIView.m index d57949c7ff03..152f7b31c007 100644 --- a/packages/react-native/React/RCTUIKit/RCTUIView.m +++ b/packages/react-native/React/RCTUIKit/RCTUIView.m @@ -1,5 +1,5 @@ /** - * Copyright (c) 2015-present, Facebook, Inc. + * Copyright (c) Microsoft Corporation. * * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. From 5f7494542ec2b2c609cb9f9b4ad426a183db16bc Mon Sep 17 00:00:00 2001 From: Saad Najmi Date: Tue, 10 Mar 2026 17:40:55 -0700 Subject: [PATCH 6/6] Switch to compatibility_alias for Swift compat --- .../CoreModules/RCTActionSheetManager.mm | 2 +- .../React/RCTUIKit/RCTPlatformDisplayLink.h | 2 +- .../RCTUIKit/RCTUIActivityIndicatorView.h | 2 +- .../react-native/React/RCTUIKit/RCTUIImage.h | 6 +-- .../React/RCTUIKit/RCTUIImageView.h | 2 +- .../React/RCTUIKit/RCTUIKitCompat.h | 37 +++++++++---------- .../react-native/React/RCTUIKit/RCTUILabel.h | 2 +- .../React/RCTUIKit/RCTUIScrollView.h | 2 +- .../react-native/React/RCTUIKit/RCTUISlider.h | 2 +- .../react-native/React/RCTUIKit/RCTUISwitch.h | 2 +- .../react-native/React/RCTUIKit/RCTUITouch.h | 2 +- .../react-native/React/RCTUIKit/RCTUIView.h | 6 +-- .../React/Views/RCTDebuggingOverlay.m | 2 +- 13 files changed, 33 insertions(+), 36 deletions(-) diff --git a/packages/react-native/React/CoreModules/RCTActionSheetManager.mm b/packages/react-native/React/CoreModules/RCTActionSheetManager.mm index 2d3db7190e0f..11ba8210badf 100644 --- a/packages/react-native/React/CoreModules/RCTActionSheetManager.mm +++ b/packages/react-native/React/CoreModules/RCTActionSheetManager.mm @@ -339,7 +339,7 @@ - (void)presentSharingServicePicker:(NSSharingServicePicker *)picker }); NSString *userInterfaceStyle = [RCTConvert NSString:options.userInterfaceStyle()]; NSNumber *anchorViewTag = [RCTConvert NSNumber:options.anchor() ? @(*options.anchor()) : nil]; - RCTPlatformColor *tintColor = [RCTConvert RCTPlatformColor:options.tintColor() ? @(*options.tintColor()) : nil]; // [macOS] + RCTPlatformColor *tintColor = [RCTConvert UIColor:options.tintColor() ? @(*options.tintColor()) : nil]; // [macOS] dispatch_async(dispatch_get_main_queue(), ^{ if (message) { diff --git a/packages/react-native/React/RCTUIKit/RCTPlatformDisplayLink.h b/packages/react-native/React/RCTUIKit/RCTPlatformDisplayLink.h index 796def463758..dd28d9eeeca2 100644 --- a/packages/react-native/React/RCTUIKit/RCTPlatformDisplayLink.h +++ b/packages/react-native/React/RCTUIKit/RCTPlatformDisplayLink.h @@ -11,7 +11,7 @@ #if !TARGET_OS_OSX #import -#define RCTPlatformDisplayLink CADisplayLink +@compatibility_alias RCTPlatformDisplayLink CADisplayLink; #else #import diff --git a/packages/react-native/React/RCTUIKit/RCTUIActivityIndicatorView.h b/packages/react-native/React/RCTUIKit/RCTUIActivityIndicatorView.h index 31099f011089..d5700b0604d5 100644 --- a/packages/react-native/React/RCTUIKit/RCTUIActivityIndicatorView.h +++ b/packages/react-native/React/RCTUIKit/RCTUIActivityIndicatorView.h @@ -14,7 +14,7 @@ #import #if !TARGET_OS_OSX -typedef UIActivityIndicatorView RCTUIActivityIndicatorView; +@compatibility_alias RCTUIActivityIndicatorView UIActivityIndicatorView; #else @interface RCTUIActivityIndicatorView : NSProgressIndicator NS_ASSUME_NONNULL_BEGIN diff --git a/packages/react-native/React/RCTUIKit/RCTUIImage.h b/packages/react-native/React/RCTUIKit/RCTUIImage.h index f8289c0b648d..b09122f94481 100644 --- a/packages/react-native/React/RCTUIKit/RCTUIImage.h +++ b/packages/react-native/React/RCTUIKit/RCTUIImage.h @@ -15,11 +15,11 @@ #if !TARGET_OS_OSX #import -#define RCTPlatformImage UIImage -#define RCTUIImage UIImage +@compatibility_alias RCTPlatformImage UIImage; +@compatibility_alias RCTUIImage UIImage; #else #import -#define RCTPlatformImage NSImage +@compatibility_alias RCTPlatformImage NSImage; #endif NS_ASSUME_NONNULL_BEGIN diff --git a/packages/react-native/React/RCTUIKit/RCTUIImageView.h b/packages/react-native/React/RCTUIKit/RCTUIImageView.h index 70d435ed5568..4e011aa2b9e9 100644 --- a/packages/react-native/React/RCTUIKit/RCTUIImageView.h +++ b/packages/react-native/React/RCTUIKit/RCTUIImageView.h @@ -15,7 +15,7 @@ #import #if !TARGET_OS_OSX -typedef UIImageView RCTUIImageView; +@compatibility_alias RCTUIImageView UIImageView; #else @interface RCTUIImageView : NSImageView NS_ASSUME_NONNULL_BEGIN diff --git a/packages/react-native/React/RCTUIKit/RCTUIKitCompat.h b/packages/react-native/React/RCTUIKit/RCTUIKitCompat.h index 11248cfe22e5..a195d66bae54 100644 --- a/packages/react-native/React/RCTUIKit/RCTUIKitCompat.h +++ b/packages/react-native/React/RCTUIKit/RCTUIKitCompat.h @@ -22,14 +22,13 @@ NS_ASSUME_NONNULL_BEGIN // MARK: - Color #if !TARGET_OS_OSX -#define RCTPlatformColor UIColor +@compatibility_alias RCTPlatformColor UIColor; +@compatibility_alias RCTUIColor UIColor; #else -#define RCTPlatformColor NSColor +@compatibility_alias RCTPlatformColor NSColor; +@compatibility_alias RCTUIColor NSColor; #endif -// Backward compatibility -#define RCTUIColor RCTPlatformColor - // MARK: - Event types #if TARGET_OS_OSX @@ -209,30 +208,28 @@ typedef NS_ENUM(NSInteger, UIActivityIndicatorViewStyle) { // MARK: - Gesture recognizer #if !TARGET_OS_OSX -#define RCTPlatformPanGestureRecognizer UIPanGestureRecognizer +@compatibility_alias RCTPlatformPanGestureRecognizer UIPanGestureRecognizer; +@compatibility_alias RCTUIPanGestureRecognizer UIPanGestureRecognizer; #else #define UIGestureRecognizer NSGestureRecognizer #define UIGestureRecognizerDelegate NSGestureRecognizerDelegate -#define RCTPlatformPanGestureRecognizer NSPanGestureRecognizer -#define UIApplication NSApplication +@compatibility_alias RCTPlatformPanGestureRecognizer NSPanGestureRecognizer; +@compatibility_alias RCTUIPanGestureRecognizer NSPanGestureRecognizer; +@compatibility_alias UIApplication NSApplication; #endif -// Backward compatibility -#define RCTUIPanGestureRecognizer RCTPlatformPanGestureRecognizer - // MARK: - Cross-platform typedefs #if !TARGET_OS_OSX -typedef UIApplication RCTPlatformApplication; -typedef UIWindow RCTPlatformWindow; -typedef UIViewController RCTPlatformViewController; +@compatibility_alias RCTPlatformApplication UIApplication; +@compatibility_alias RCTPlatformWindow UIWindow; +@compatibility_alias RCTPlatformViewController UIViewController; +@compatibility_alias RCTUIApplication UIApplication; #else -typedef NSApplication RCTPlatformApplication; -typedef NSWindow RCTPlatformWindow; -typedef NSViewController RCTPlatformViewController; +@compatibility_alias RCTPlatformApplication NSApplication; +@compatibility_alias RCTPlatformWindow NSWindow; +@compatibility_alias RCTPlatformViewController NSViewController; +@compatibility_alias RCTUIApplication NSApplication; #endif -// Backward compatibility -#define RCTUIApplication RCTPlatformApplication - NS_ASSUME_NONNULL_END diff --git a/packages/react-native/React/RCTUIKit/RCTUILabel.h b/packages/react-native/React/RCTUIKit/RCTUILabel.h index 71d993a4167f..7781effc3b6f 100644 --- a/packages/react-native/React/RCTUIKit/RCTUILabel.h +++ b/packages/react-native/React/RCTUIKit/RCTUILabel.h @@ -14,7 +14,7 @@ #import #if !TARGET_OS_OSX -typedef UILabel RCTUILabel; +@compatibility_alias RCTUILabel UILabel; #else @interface RCTUILabel : NSTextField NS_ASSUME_NONNULL_BEGIN diff --git a/packages/react-native/React/RCTUIKit/RCTUIScrollView.h b/packages/react-native/React/RCTUIKit/RCTUIScrollView.h index 3cba8e590093..3b8cb22f2605 100644 --- a/packages/react-native/React/RCTUIKit/RCTUIScrollView.h +++ b/packages/react-native/React/RCTUIKit/RCTUIScrollView.h @@ -17,7 +17,7 @@ #import -#define RCTUIScrollView UIScrollView +@compatibility_alias RCTUIScrollView UIScrollView; #define RCTUIScrollViewDelegate UIScrollViewDelegate #else // TARGET_OS_OSX [ diff --git a/packages/react-native/React/RCTUIKit/RCTUISlider.h b/packages/react-native/React/RCTUIKit/RCTUISlider.h index 6290137497a5..76f4cc243d40 100644 --- a/packages/react-native/React/RCTUIKit/RCTUISlider.h +++ b/packages/react-native/React/RCTUIKit/RCTUISlider.h @@ -14,7 +14,7 @@ #import #if !TARGET_OS_OSX -typedef UISlider RCTUISlider; +@compatibility_alias RCTUISlider UISlider; #else @protocol RCTUISliderDelegate; diff --git a/packages/react-native/React/RCTUIKit/RCTUISwitch.h b/packages/react-native/React/RCTUIKit/RCTUISwitch.h index 5e27ef223350..ef262220bcf4 100644 --- a/packages/react-native/React/RCTUIKit/RCTUISwitch.h +++ b/packages/react-native/React/RCTUIKit/RCTUISwitch.h @@ -14,7 +14,7 @@ #import #if !TARGET_OS_OSX -typedef UISwitch RCTUISwitch; +@compatibility_alias RCTUISwitch UISwitch; #else @interface RCTUISwitch : NSSwitch NS_ASSUME_NONNULL_BEGIN diff --git a/packages/react-native/React/RCTUIKit/RCTUITouch.h b/packages/react-native/React/RCTUIKit/RCTUITouch.h index eb811a1345d5..f3fe30ea0f5e 100644 --- a/packages/react-native/React/RCTUIKit/RCTUITouch.h +++ b/packages/react-native/React/RCTUIKit/RCTUITouch.h @@ -13,7 +13,7 @@ #if !TARGET_OS_OSX #import -typedef UITouch RCTUITouch; +@compatibility_alias RCTUITouch UITouch; #else #import @interface RCTUITouch : NSEvent diff --git a/packages/react-native/React/RCTUIKit/RCTUIView.h b/packages/react-native/React/RCTUIKit/RCTUIView.h index 4ecb82a3d164..991018bc4fb9 100644 --- a/packages/react-native/React/RCTUIKit/RCTUIView.h +++ b/packages/react-native/React/RCTUIKit/RCTUIView.h @@ -25,12 +25,12 @@ NS_ASSUME_NONNULL_BEGIN #if !TARGET_OS_OSX -#define RCTPlatformView UIView -#define RCTUIView UIView +@compatibility_alias RCTPlatformView UIView; +@compatibility_alias RCTUIView UIView; #else // TARGET_OS_OSX -#define RCTPlatformView NSView +@compatibility_alias RCTPlatformView NSView; @interface RCTUIView : RCTPlatformView diff --git a/packages/react-native/React/Views/RCTDebuggingOverlay.m b/packages/react-native/React/Views/RCTDebuggingOverlay.m index de8e183369c3..05408f179f98 100644 --- a/packages/react-native/React/Views/RCTDebuggingOverlay.m +++ b/packages/react-native/React/Views/RCTDebuggingOverlay.m @@ -44,7 +44,7 @@ - (void)highlightTraceUpdates:(NSArray *)updates for (NSDictionary *update in updates) { NSNumber *identifier = [RCTConvert NSNumber:update[@"id"]]; NSDictionary *nodeRectangle = update[@"rectangle"]; - RCTPlatformColor *nodeColor = [RCTConvert RCTPlatformColor:update[@"color"]]; // [macOS] + RCTPlatformColor *nodeColor = [RCTConvert UIColor:update[@"color"]]; // [macOS] CGRect rect = [RCTConvert CGRect:nodeRectangle];