Skip to content

Commit e3d15a8

Browse files
shwantonShawn Dempsey
andauthored
[Fabric] Remaining fixes for Fabric building on macOS target (#1685)
* [Fabric] Fix UIKit Shim * [Fabric] Fix RCTUILabel shim * [Fabric] Fix RCTSliderComponent shim * [Fabric] Disable UIApplicationWillTerminateNotification on macOS * [Fabric] Don't check alpha for NSView * [Fabric] Remove duplicate RCTUITouch def * [Fabric] Fix whitespace Co-authored-by: Shawn Dempsey <shawndempsey@fb.com>
1 parent 3467d0d commit e3d15a8

File tree

7 files changed

+140
-15
lines changed

7 files changed

+140
-15
lines changed

React/Base/RCTUIKit.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -508,6 +508,11 @@ NS_ASSUME_NONNULL_END
508508
typedef UILabel RCTUILabel;
509509
#else
510510
@interface RCTUILabel : NSTextField
511+
NS_ASSUME_NONNULL_BEGIN
512+
@property(nonatomic, copy) NSString* _Nullable text;
513+
@property(nonatomic, assign) NSInteger numberOfLines;
514+
@property(nonatomic, assign) NSTextAlignment textAlignment;
515+
NS_ASSUME_NONNULL_END
511516
@end
512517
#endif
513518

React/Base/macOS/RCTUIKit.m

Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@
1313

1414
#import <objc/runtime.h>
1515

16+
#import <CoreImage/CIFilter.h>
17+
#import <CoreImage/CIVector.h>
18+
1619
static char RCTGraphicsContextSizeKey;
1720

1821
//
@@ -631,5 +634,114 @@ - (void)setOn:(BOOL)on animated:(BOOL)animated {
631634
self.state = on ? NSControlStateValueOn : NSControlStateValueOff;
632635
}
633636

637+
@end
638+
639+
// RCTUIActivityIndicatorView
640+
641+
@interface RCTUIActivityIndicatorView ()
642+
@property (nonatomic, readwrite, getter=isAnimating) BOOL animating;
643+
@end
644+
645+
@implementation RCTUIActivityIndicatorView {}
646+
647+
- (instancetype)initWithFrame:(CGRect)frame
648+
{
649+
if ((self = [super initWithFrame:frame])) {
650+
self.displayedWhenStopped = NO;
651+
self.style = NSProgressIndicatorStyleSpinning;
652+
}
653+
return self;
654+
}
655+
656+
- (void)startAnimating
657+
{
658+
// `wantsLayer` gets reset after the animation is stopped. We have to
659+
// reset it in order for CALayer filters to take effect.
660+
[self setWantsLayer:YES];
661+
[self startAnimation:self];
662+
}
663+
664+
- (void)stopAnimating
665+
{
666+
[self stopAnimation:self];
667+
}
668+
669+
- (void)startAnimation:(id)sender
670+
{
671+
[super startAnimation:sender];
672+
self.animating = YES;
673+
}
674+
675+
- (void)stopAnimation:(id)sender
676+
{
677+
[super stopAnimation:sender];
678+
self.animating = NO;
679+
}
680+
681+
- (void)setActivityIndicatorViewStyle:(UIActivityIndicatorViewStyle)activityIndicatorViewStyle
682+
{
683+
_activityIndicatorViewStyle = activityIndicatorViewStyle;
684+
685+
switch (activityIndicatorViewStyle) {
686+
case UIActivityIndicatorViewStyleWhiteLarge:
687+
self.controlSize = NSControlSizeRegular;
688+
break;
689+
case UIActivityIndicatorViewStyleWhite:
690+
self.controlSize = NSControlSizeSmall;
691+
break;
692+
default:
693+
break;
694+
}
695+
}
696+
697+
- (void)setColor:(RCTUIColor*)color
698+
{
699+
if (_color != color) {
700+
_color = color;
701+
[self setNeedsDisplay:YES];
702+
}
703+
}
704+
705+
- (void)updateLayer
706+
{
707+
[super updateLayer];
708+
if (_color != nil) {
709+
CGFloat r, g, b, a;
710+
[[_color colorUsingColorSpace:[NSColorSpace genericRGBColorSpace]] getRed:&r green:&g blue:&b alpha:&a];
711+
712+
CIFilter *colorPoly = [CIFilter filterWithName:@"CIColorPolynomial"];
713+
[colorPoly setDefaults];
714+
715+
CIVector *redVector = [CIVector vectorWithX:r Y:0 Z:0 W:0];
716+
CIVector *greenVector = [CIVector vectorWithX:g Y:0 Z:0 W:0];
717+
CIVector *blueVector = [CIVector vectorWithX:b Y:0 Z:0 W:0];
718+
[colorPoly setValue:redVector forKey:@"inputRedCoefficients"];
719+
[colorPoly setValue:greenVector forKey:@"inputGreenCoefficients"];
720+
[colorPoly setValue:blueVector forKey:@"inputBlueCoefficients"];
721+
722+
[[self layer] setFilters:@[colorPoly]];
723+
} else {
724+
[[self layer] setFilters:nil];
725+
}
726+
}
727+
728+
- (void)setHidesWhenStopped:(BOOL)hidesWhenStopped
729+
{
730+
self.displayedWhenStopped = !hidesWhenStopped;
731+
}
732+
733+
- (BOOL)hidesWhenStopped
734+
{
735+
return !self.displayedWhenStopped;
736+
}
737+
738+
- (void)setHidden:(BOOL)hidden
739+
{
740+
if ([self hidesWhenStopped] && ![self isAnimating]) {
741+
[super setHidden:YES];
742+
} else {
743+
[super setHidden:hidden];
744+
}
745+
}
634746

635747
@end

React/Fabric/Mounting/ComponentViews/Slider/RCTSliderComponentView.mm

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,12 @@ - (instancetype)initWithFrame:(CGRect)frame
6464
_maximumTrackImageResponseObserverProxy = RCTImageResponseObserverProxy(self);
6565
_thumbImageResponseObserverProxy = RCTImageResponseObserverProxy(self);
6666

67+
#if !TARGET_OS_OSX // [macOS]
6768
self.contentView = _sliderView;
69+
#else // [macOS
70+
self.contentView = [RCTUIView new];
71+
[self.contentView addSubview:_sliderView];
72+
#endif // macOS]
6873
}
6974

7075
return self;

React/Fabric/Mounting/ComponentViews/UnimplementedComponent/RCTUnimplementedNativeComponentView.mm

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,11 @@ - (instancetype)initWithFrame:(CGRect)frame
3434
_label.textAlignment = NSTextAlignmentCenter;
3535
_label.textColor = [RCTUIColor whiteColor]; // [macOS]
3636

37+
#if !TARGET_OS_OSX // [macOS]
3738
self.contentView = _label;
39+
#else // [macOS
40+
[self.contentView addSubview:_label];
41+
#endif // macOS]
3842
}
3943

4044
return self;

React/Fabric/Mounting/ComponentViews/UnimplementedView/RCTUnimplementedViewComponentView.mm

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -30,18 +30,14 @@ - (instancetype)initWithFrame:(CGRect)frame
3030
static auto const defaultProps = std::make_shared<UnimplementedViewProps const>();
3131
_props = defaultProps;
3232

33-
_label = [[RCTUILabel alloc] initWithFrame:self.bounds]; // [macOS]
34-
_label.backgroundColor = [RCTUIColor colorWithRed:1.0 green:0.0 blue:0.0 alpha:0.3]; // [macOS]
33+
_label = [[RCTUILabel alloc] initWithFrame:self.bounds];
34+
_label.backgroundColor = [RCTUIColor colorWithRed:1.0 green:0.0 blue:0.0 alpha:0.3];
3535
_label.lineBreakMode = NSLineBreakByCharWrapping;
36-
#if !TARGET_OS_OSX // [macOS]
3736
_label.numberOfLines = 0;
3837
_label.textAlignment = NSTextAlignmentCenter;
39-
#else // [macOS
40-
_label.alignment = NSTextAlignmentCenter;
41-
#endif // macOS]
42-
_label.textColor = [RCTUIColor whiteColor]; // [macOS]
43-
_label.allowsDefaultTighteningForTruncation = YES;
38+
_label.textColor = [RCTUIColor whiteColor];
4439
#if !TARGET_OS_OSX // [macOS]
40+
_label.allowsDefaultTighteningForTruncation = YES;
4541
_label.adjustsFontSizeToFitWidth = YES;
4642
#endif // [macOS]
4743

React/Fabric/Mounting/ComponentViews/View/RCTViewComponentView.mm

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -455,7 +455,11 @@ - (RCTUIView *)betterHitTest:(CGPoint)point withEvent:(UIEvent *)event // [macOS
455455
// * Taking `layer.zIndex` field into an account is not required because
456456
// lists of `ShadowView`s are already sorted based on `zIndex` prop.
457457

458+
#if !TARGET_OS_OSX // [macOS]
458459
if (!self.userInteractionEnabled || self.hidden || self.alpha < 0.01) {
460+
#else // [macOS
461+
if (!self.userInteractionEnabled || self.hidden) {
462+
#endif // macOS]
459463
return nil;
460464
}
461465

React/Fabric/RCTSurfacePresenter.mm

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -98,13 +98,12 @@ - (instancetype)initWithContextContainer:(ContextContainer::Shared)contextContai
9898

9999
_scheduler = [self _createScheduler];
100100

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

110109
return self;

0 commit comments

Comments
 (0)