Skip to content

[Fabric] Remaining fixes for Fabric building on macOS target #1685

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 9 commits into from
Jan 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions React/Base/RCTUIKit.h
Original file line number Diff line number Diff line change
Expand Up @@ -508,6 +508,11 @@ NS_ASSUME_NONNULL_END
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

Expand Down
112 changes: 112 additions & 0 deletions React/Base/macOS/RCTUIKit.m
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@

#import <objc/runtime.h>

#import <CoreImage/CIFilter.h>
#import <CoreImage/CIVector.h>

static char RCTGraphicsContextSizeKey;

//
Expand Down Expand Up @@ -631,5 +634,114 @@ - (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 UIActivityIndicatorViewStyleWhiteLarge:
self.controlSize = NSControlSizeRegular;
break;
case UIActivityIndicatorViewStyleWhite:
self.controlSize = NSControlSizeSmall;
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
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,12 @@ - (instancetype)initWithFrame:(CGRect)frame
_maximumTrackImageResponseObserverProxy = RCTImageResponseObserverProxy(self);
_thumbImageResponseObserverProxy = RCTImageResponseObserverProxy(self);

#if !TARGET_OS_OSX // [macOS]
self.contentView = _sliderView;
#else // [macOS
self.contentView = [RCTUIView new];
[self.contentView addSubview:_sliderView];
#endif // macOS]
}

return self;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,11 @@ - (instancetype)initWithFrame:(CGRect)frame
_label.textAlignment = NSTextAlignmentCenter;
_label.textColor = [RCTUIColor whiteColor]; // [macOS]

#if !TARGET_OS_OSX // [macOS]
self.contentView = _label;
#else // [macOS
[self.contentView addSubview:_label];
#endif // macOS]
}

return self;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,18 +30,14 @@ - (instancetype)initWithFrame:(CGRect)frame
static auto const defaultProps = std::make_shared<UnimplementedViewProps const>();
_props = defaultProps;

_label = [[RCTUILabel alloc] initWithFrame:self.bounds]; // [macOS]
_label.backgroundColor = [RCTUIColor colorWithRed:1.0 green:0.0 blue:0.0 alpha:0.3]; // [macOS]
_label = [[RCTUILabel alloc] initWithFrame:self.bounds];
_label.backgroundColor = [RCTUIColor colorWithRed:1.0 green:0.0 blue:0.0 alpha:0.3];
_label.lineBreakMode = NSLineBreakByCharWrapping;
#if !TARGET_OS_OSX // [macOS]
_label.numberOfLines = 0;
_label.textAlignment = NSTextAlignmentCenter;
#else // [macOS
_label.alignment = NSTextAlignmentCenter;
#endif // macOS]
_label.textColor = [RCTUIColor whiteColor]; // [macOS]
_label.allowsDefaultTighteningForTruncation = YES;
_label.textColor = [RCTUIColor whiteColor];
#if !TARGET_OS_OSX // [macOS]
_label.allowsDefaultTighteningForTruncation = YES;
_label.adjustsFontSizeToFitWidth = YES;
#endif // [macOS]

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -454,7 +454,11 @@ - (RCTUIView *)betterHitTest:(CGPoint)point withEvent:(UIEvent *)event // [macOS
// * Taking `layer.zIndex` field into an account is not required because
// lists of `ShadowView`s are already sorted based on `zIndex` prop.

#if !TARGET_OS_OSX // [macOS]
if (!self.userInteractionEnabled || self.hidden || self.alpha < 0.01) {
#else // [macOS
if (!self.userInteractionEnabled || self.hidden) {
#endif // macOS]
return nil;
}

Expand Down
13 changes: 6 additions & 7 deletions React/Fabric/RCTSurfacePresenter.mm
Original file line number Diff line number Diff line change
Expand Up @@ -98,13 +98,12 @@ - (instancetype)initWithContextContainer:(ContextContainer::Shared)contextContai

_scheduler = [self _createScheduler];

auto reactNativeConfig = _contextContainer->at<std::shared_ptr<ReactNativeConfig const>>("ReactNativeConfig");
if (reactNativeConfig->getBool("react_native_new_architecture:suspend_before_app_termination")) {
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(_applicationWillTerminate)
name:UIApplicationWillTerminateNotification
object:nil];
}
#if !TARGET_OS_OSX // [macOS]
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(_applicationWillTerminate)
name:UIApplicationWillTerminateNotification
object:nil];
#endif // [macOS]
}

return self;
Expand Down