Skip to content

Commit

Permalink
Followup fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Saadnajmi committed Oct 21, 2024
1 parent 013b681 commit 5a06df8
Show file tree
Hide file tree
Showing 32 changed files with 2,426 additions and 1,928 deletions.
4 changes: 4 additions & 0 deletions .yarnrc.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
compressionLevel: mixed

enableGlobalCache: false

nodeLinker: node-modules

yarnPath: .yarn/releases/yarn-4.5.1.cjs
2 changes: 2 additions & 0 deletions packages/react-native/Libraries/Image/RCTResizeMode.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ static inline RCTResizeMode RCTResizeModeFromUIViewContentMode(UIViewContentMode
case UIViewContentModeCenter:
return RCTResizeModeCenter;
break;
#if !TARGET_OS_OSX // [macOS]
case UIViewContentModeRedraw:
case UIViewContentModeTop:
case UIViewContentModeBottom:
Expand All @@ -47,6 +48,7 @@ static inline RCTResizeMode RCTResizeModeFromUIViewContentMode(UIViewContentMode
case UIViewContentModeBottomLeft:
case UIViewContentModeBottomRight:
return RCTResizeModeRepeat;
#endif // [macOS]
}
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,10 @@ Pod::Spec.new do |s|
"CLANG_CXX_LANGUAGE_STANDARD" => rct_cxx_language_standard(),
"HEADER_SEARCH_PATHS" => header_search_paths.join(' ')
}
s.framework = "UIKit"
# [macOS Restrict UIKit to iOS and visionOS
s.ios.framework = "UIKit"
s.visionos.framework = "UIKit"
# macOS]

s.dependency "React-Core/RCTLinkingHeaders", version
s.dependency "ReactCommon/turbomodule/core", version
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,11 @@ Pod::Spec.new do |s|
"CLANG_CXX_LANGUAGE_STANDARD" => rct_cxx_language_standard(),
"HEADER_SEARCH_PATHS" => header_search_paths.join(" ")
}
s.framework = ["UIKit", "QuartzCore"]
# [macOS Restrict UIKit to iOS and visionOS
s.ios.framework = ["UIKit", "QuartzCore"]
s.visionos.framework = ["UIKit", "QuartzCore"]
s.osx.framework = ["Appkit", "QuartzCore"]
# macOS]

s.dependency "RCT-Folly", folly_version
s.dependency "RCTTypeSafety"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,11 @@ Pod::Spec.new do |s|
"CLANG_CXX_LANGUAGE_STANDARD" => rct_cxx_language_standard(),
"HEADER_SEARCH_PATHS" => header_search_paths.join(' ')
}
s.framework = ["UIKit", "UserNotifications"]
# [macOS Restrict UIKit to iOS and visionOS
s.ios.framework = ["UIKit", "UserNotifications"]
s.visionos.framework = ["UIKit", "UserNotifications"]
s.osx.framework = ["Appkit", "UserNotifications"]
# macOS]

s.dependency "RCTTypeSafety"
s.dependency "React-Core/RCTPushNotificationHeaders"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -344,8 +344,13 @@ - (BOOL)textView:(__unused UITextView *)textView shouldChangeTextInRange:(NSRang
return NO;
}

#if !TARGET_OS_OSX // [macOS]
if (range.location + range.length > _backedTextInputView.text.length) {
range = NSMakeRange(range.location, _backedTextInputView.text.length - range.location);
#else // [macOS
if (range.location + range.length > _backedTextInputView.string.length) {
range = NSMakeRange(range.location, _backedTextInputView.string.length - range.location);
#endif // macOS]
} else if ([newText isEqualToString:text]) {
_textDidChangeIsComing = YES;
return YES;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,11 @@ Pod::Spec.new do |s|
"CLANG_CXX_LANGUAGE_STANDARD" => rct_cxx_language_standard(),
"HEADER_SEARCH_PATHS" => header_search_paths.join(" ")
}
s.ios.framework = "UIKit" # [macOS] Restrict to iOS
# [macOS Restrict UIKit to iOS and visionOS
s.ios.framework = "UIKit"
s.visionos.framework = "UIKit"
s.osx.framework = "Appkit"
# macOS]
s.dependency "DoubleConversion"
s.dependency "fmt", "9.1.0"
s.dependency "RCT-Folly", folly_version
Expand Down
5 changes: 3 additions & 2 deletions packages/react-native/React/DevSupport/RCTInspectorUtils.mm
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

#import <React/RCTConstants.h>
#import <React/RCTVersion.h>
#import <UIKit/UIKit.h>
#import <React/RCTUIKit.h>

@implementation CommonHostMetadata
@end
Expand All @@ -25,7 +25,8 @@ + (CommonHostMetadata *)getHostMetadata
// macOS does not support UIDevice. Use System Configuration. This API
// returns a nullable value, but is non-blocking (compared with
// `[NSHost currentHost]`) and is ideal since deviceName is optional.
NSString *deviceName = (__bridge NSString *)SCDynamicStoreCopyComputerName(nil, nil);
// NSString *deviceName = (__bridge NSString *)SCDynamicStoreCopyComputerName(nil, nil);
NSString *deviceName = @"";
#endif // TARGET_OS_IPHONE

auto version = RCTGetReactNativeVersion();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,6 @@ - (void)unmountChildComponentView:(RCTUIView<RCTComponentViewProtocol> *)childCo
{
[childComponentView removeFromSuperview];
}
#endif // [macOS]

#pragma mark - Private

Expand All @@ -300,6 +299,7 @@ - (UIViewController *)_topMostViewControllerFrom:(UIViewController *)rootViewCon
return topController;
}

#endif // [macOS]
@end

#ifdef __cplusplus
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ NS_ASSUME_NONNULL_BEGIN

@end

@interface UIView (RCTScrollViewComponentView)
@interface RCTPlatformView (RCTScrollViewComponentView)

- (void)reactUpdateResponderOffsetForScrollView:(RCTScrollViewComponentView *)scrollView;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,10 @@

#import "RCTFabricComponentsPlugins.h"

#if !TARGET_OS_OSX // [macOS]
/** Native iOS text field bottom keyboard offset amount */
static const CGFloat kSingleLineKeyboardBottomOffset = 15.0;
#endif // [macOS]

using namespace facebook::react;

Expand Down Expand Up @@ -112,6 +114,7 @@ - (void)didMoveToWindow

- (void)reactUpdateResponderOffsetForScrollView:(RCTScrollViewComponentView *)scrollView
{
#if !TARGET_OS_OSX // [macOS]
if (![self isDescendantOfView:scrollView.scrollView] || !_backedTextInputView.isFirstResponder) {
// View is outside scroll view or it's not a first responder.
return;
Expand All @@ -132,6 +135,7 @@ - (void)reactUpdateResponderOffsetForScrollView:(RCTScrollViewComponentView *)sc
}
}
scrollView.firstResponderFocus = [self convertRect:focusRect toView:nil];
#endif // [macOS]
}

#pragma mark - RCTViewComponentView overrides
Expand Down Expand Up @@ -236,11 +240,11 @@ - (void)updateProps:(const Props::Shared &)props oldProps:(const Props::Shared &
_backedTextInputView.smartInsertDeleteType =
RCTUITextSmartInsertDeleteTypeFromOptionalBool(newTextInputProps.traits.smartInsertDelete);
}
#endif // [macOS]

if (newTextInputProps.traits.showSoftInputOnFocus != oldTextInputProps.traits.showSoftInputOnFocus) {
[self _setShowSoftInputOnFocus:newTextInputProps.traits.showSoftInputOnFocus];
}
#endif // [macOS]

// Traits `blurOnSubmit`, `clearTextOnFocus`, and `selectTextOnFocus` were omitted intentionally here
// because they are being checked on-demand.
Expand Down Expand Up @@ -782,6 +786,7 @@ - (void)_setMultiline:(BOOL)multiline
[self addSubview:_backedTextInputView];
}

#if !TARGET_OS_OSX // [macOS]
- (void)_setShowSoftInputOnFocus:(BOOL)showSoftInputOnFocus
{
if (showSoftInputOnFocus) {
Expand All @@ -798,6 +803,7 @@ - (void)_setShowSoftInputOnFocus:(BOOL)showSoftInputOnFocus
_backedTextInputView.inputView = [UIView new];
}
}
#endif // macOS]

- (BOOL)_textOf:(NSAttributedString *)newText equals:(NSAttributedString *)oldText
{
Expand Down
2 changes: 1 addition & 1 deletion packages/react-native/React/Fabric/Utils/RCTBoxShadow.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

#import <React/RCTBorderDrawing.h>
#import <React/RCTDefines.h>
#import <UIKit/UIKit.h>
#import <React/RCTUIKit.h>
#import <react/renderer/graphics/BoxShadow.h>

RCT_EXTERN UIImage *RCTGetBoxShadowImage(
Expand Down
23 changes: 16 additions & 7 deletions packages/react-native/React/Fabric/Utils/RCTBoxShadow.mm
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,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 : [UIColor blackColor].CGColor;
return colorRef ? colorRef : [RCTUIColor blackColor].CGColor; // [macOS]
}

// Core graphics has support for shadows that looks similar to web and are very
Expand Down Expand Up @@ -123,6 +123,12 @@ static void renderOutsetShadows(
CGFloat blurRadius = it->blurRadius;
CGFloat spreadDistance = it->spreadDistance;
CGColorRef color = colorRefFromSharedColor(it->color);

#if TARGET_OS_OSX // [macOS
// For some reason, unflipping the context gets outset shadows to (mostly) appear correctly on macOS
CGAffineTransform flippedTransform = CGAffineTransformMake(1, 0, 0, -1, 0, boundingRect.size.height);
CGContextConcatCTM(context, flippedTransform);
#endif // macOS]

// First, define the shadow rect. This is the rect that will be filled
// and _cast_ the shadow. As a result, the size does not incorporate
Expand Down Expand Up @@ -155,7 +161,7 @@ static void renderOutsetShadows(
// Color here does not matter, we just need something that has 1 for
// alpha so that the shadow is visible. The rect is purposely rendered
// outside of the context so it should not be visible.
CGContextSetFillColorWithColor(context, [UIColor blackColor].CGColor);
CGContextSetFillColorWithColor(context, [RCTUIColor blackColor].CGColor); // [macOS]
CGContextFillPath(context);

CGPathRelease(shadowRectPath);
Expand Down Expand Up @@ -266,7 +272,7 @@ static void renderInsetShadows(
// intersection between our two rects will be clear. The disjoint parts of
// the rect will be colored, but because of the clipping area, we only see
// the shadow projected from the shadow rect, not the clear region rect.
CGContextSetFillColorWithColor(context, [UIColor blackColor].CGColor);
CGContextSetFillColorWithColor(context, [RCTUIColor blackColor].CGColor); // [macOS]
CGContextEOFillPath(context);

CGContextRestoreGState(context);
Expand All @@ -282,11 +288,14 @@ static void renderInsetShadows(
CALayer *layer)
{
CGRect boundingRect = RCTGetBoundingRect(shadows, layer.bounds.size);
UIGraphicsImageRendererFormat *const rendererFormat = [UIGraphicsImageRendererFormat defaultFormat];
UIGraphicsImageRenderer *const renderer = [[UIGraphicsImageRenderer alloc] initWithSize:boundingRect.size
format:rendererFormat];
// [macOS Use RCTUIGraphicsImageRenderer shim
RCTUIGraphicsImageRendererFormat *const rendererFormat = [RCTUIGraphicsImageRendererFormat defaultFormat];
RCTUIGraphicsImageRenderer *const renderer = [[RCTUIGraphicsImageRenderer alloc] initWithSize:boundingRect.size
format:rendererFormat];
// macOS]

UIImage *const boxShadowImage =
[renderer imageWithActions:^(UIGraphicsImageRendererContext *_Nonnull rendererContext) {
[renderer imageWithActions:^(RCTUIGraphicsImageRendererContext *_Nonnull rendererContext) { // [macOS]
auto [outsetShadows, insetShadows] = splitBoxShadowsByInset(shadows);
const CGContextRef context = rendererContext.CGContext;
// Outset shadows should be before inset shadows since outset needs to
Expand Down
2 changes: 2 additions & 0 deletions packages/react-native/React/Views/RCTViewManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -392,6 +392,7 @@ - (void) updateAccessibilityRole:(RCTView *)view withDefaultView:(RCTView *)defa
}
}

#if !TARGET_OS_OSX // [macOS]
RCT_CUSTOM_VIEW_PROPERTY(accessibilityShowsLargeContentViewer, BOOL, RCTView)
{
if (@available(iOS 13.0, *)) {
Expand All @@ -413,6 +414,7 @@ - (void) updateAccessibilityRole:(RCTView *)view withDefaultView:(RCTView *)defa
view.largeContentTitle = json ? [RCTConvert NSString:json] : defaultView.largeContentTitle;
}
}
#endif // [macOS]

RCT_CUSTOM_VIEW_PROPERTY(nativeID, NSString *, RCTView)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,11 @@ Pod::Spec.new do |s|
"USE_HEADERMAP" => "YES",
"CLANG_CXX_LANGUAGE_STANDARD" => rct_cxx_language_standard(),
"GCC_WARN_PEDANTIC" => "YES" }
s.framework = "UIKit"
# [macOS Restrict UIKit to iOS and visionOS
s.ios.framework = "UIKit"
s.visionos.framework = "UIKit"
s.osx.framework = "Appkit"
# macOS]

if ENV['USE_FRAMEWORKS']
s.header_mappings_dir = './'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,11 @@ Pod::Spec.new do |s|
"platform/cxx",
"platform/windows",
s.header_dir = "react/renderer/graphics"
s.framework = "UIKit"
# [macOS Restrict UIKit to iOS and visionOS
s.ios.framework = "UIKit"
s.visionos.framework = "UIKit"
s.osx.framework = "Appkit"
# macOS]

if ENV['USE_FRAMEWORKS']
s.module_name = "React_graphics"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ int32_t ColorFromUIColor(const std::shared_ptr<void> &uiColor)
float Color::getChannel(int channelId) const
{
CGFloat rgba[4];
UIColor *color = (__bridge UIColor *)getUIColor().get();
RCTUIColor *color = (__bridge RCTUIColor *)getUIColor().get(); // [macOS]
[color getRed:&rgba[0] green:&rgba[1] blue:&rgba[2] alpha:&rgba[3]];
return static_cast<float>(rgba[channelId]);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

# [visionOS] Local copy of SocketRocket.podspec with visionOS added as a platform

socket_rocket_version = '0.7.0'
socket_rocket_version = '0.7.1'

Pod::Spec.new do |s|
s.name = 'SocketRocket'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,11 @@ Pod::Spec.new do |s|

s.source_files = "**/*.{h,m,mm,swift}"
s.requires_arc = true
s.framework = ["UIKit", "CoreGraphics"]
# [macOS Restrict UIKit to iOS and visionOS
s.ios.framework = ["UIKit", "CoreGraphics"]
s.visionos.framework = ["UIKit", "CoreGraphics"]
s.osx.framework = ["Appkit", "CoreGraphics"]
# macOS]

install_modules_dependencies(s)
end
Loading

0 comments on commit 5a06df8

Please sign in to comment.