Skip to content

Commit cbbca9e

Browse files
shwantonShawn Dempsey
authored andcommitted
[Fabric] Shim RCTUILabel (microsoft#1576)
* Shim RCTUILabel * Conditionally ignore UIKit apis for UILabel * Shim the RCTLabel to render correctly * Re-add removed code Co-authored-by: Shawn Dempsey <shawndempsey@fb.com> # Conflicts: # React/Base/macOS/RCTUIKit.m # Conflicts: # React/Base/macOS/RCTUIKit.m
1 parent 72d2a49 commit cbbca9e

File tree

4 files changed

+42
-8
lines changed

4 files changed

+42
-8
lines changed

React/Base/RCTUIKit.h

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -486,18 +486,20 @@ NS_INLINE CGRect CGRectValue(NSValue *value)
486486
// fabric component types
487487
//
488488

489+
// RCTUISlider
490+
489491
#if !TARGET_OS_OSX // [TODO(macOS GH#774)
490492
#define RCTUISlider UISlider
491493
#else
492494
@interface RCTUISlider : NSSlider
493495
@end
494496
#endif // ]TODO(macOS GH#774)
495497

496-
// RCTUISwitch
498+
// RCTUILabel
497499

498500
#if !TARGET_OS_OSX // [TODO(macOS GH#774)
499-
#define RCTUISwitch UISwitch
501+
#define RCTUILabel UILabel
500502
#else
501-
@interface RCTUISwitch : NSSwitch
503+
@interface RCTUILabel : NSTextField
502504
@end
503505
#endif // ]TODO(macOS GH#774)

React/Base/macOS/RCTUIKit.m

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -589,3 +589,23 @@ - (NSRect)constrainBoundsRect:(NSRect)proposedBounds
589589
}
590590

591591
@end
592+
593+
// RCTUILabel
594+
595+
@implementation RCTUILabel {} // [TODO(macOS GH#774)
596+
597+
- (instancetype)initWithFrame:(NSRect)frameRect
598+
{
599+
if (self = [super initWithFrame:frameRect]) {
600+
[self setBezeled:NO];
601+
[self setDrawsBackground:NO];
602+
[self setEditable:NO];
603+
[self setSelectable:NO];
604+
[self setWantsLayer:YES];
605+
}
606+
607+
return self;
608+
}
609+
610+
@end // ]TODO(macOS GH#774)
611+

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

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
using namespace facebook::react;
1515

1616
@implementation RCTUnimplementedNativeComponentView {
17-
UILabel *_label;
17+
RCTUILabel *_label; // TODO(macOS GH#774)
1818
}
1919

2020
- (instancetype)initWithFrame:(CGRect)frame
@@ -24,9 +24,11 @@ - (instancetype)initWithFrame:(CGRect)frame
2424
_props = defaultProps;
2525

2626
CGRect bounds = self.bounds;
27-
_label = [[UILabel alloc] initWithFrame:bounds];
28-
_label.backgroundColor = [RCTUIColor colorWithRed:1.0 green:0.0 blue:0.0 alpha:0.3]; // TODO(macOS GH#774)
27+
_label = [[RCTUILabel alloc] initWithFrame:bounds]; // TODO(macOS GH#774)
28+
_label.backgroundColor = [RCTUIColor colorWithRed:1.0 green:0.0 blue:0.0 alpha:0.3];
29+
#if !TARGET_OS_OSX // [TODO(macOS GH#774)
2930
_label.layoutMargins = UIEdgeInsetsMake(12, 12, 12, 12);
31+
#endif // ]TODO(macOS GH#774)
3032
_label.lineBreakMode = NSLineBreakByWordWrapping;
3133
_label.numberOfLines = 0;
3234
_label.textAlignment = NSTextAlignmentCenter;

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

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
using namespace facebook::react;
2222

2323
@implementation RCTUnimplementedViewComponentView {
24-
UILabel *_label;
24+
RCTUILabel *_label; // TODO(macOS GH#774)
2525
}
2626

2727
- (instancetype)initWithFrame:(CGRect)frame
@@ -30,16 +30,26 @@ - (instancetype)initWithFrame:(CGRect)frame
3030
static auto const defaultProps = std::make_shared<UnimplementedViewProps const>();
3131
_props = defaultProps;
3232

33-
_label = [[UILabel alloc] initWithFrame:self.bounds];
33+
_label = [[RCTUILabel alloc] initWithFrame:self.bounds]; // TODO(macOS GH#774)
3434
_label.backgroundColor = [RCTUIColor colorWithRed:1.0 green:0.0 blue:0.0 alpha:0.3]; // TODO(macOS GH#774)
3535
_label.lineBreakMode = NSLineBreakByCharWrapping;
36+
#if !TARGET_OS_OSX // [TODO(macOS GH#774)
3637
_label.numberOfLines = 0;
3738
_label.textAlignment = NSTextAlignmentCenter;
39+
#else
40+
_label.alignment = NSTextAlignmentCenter;
41+
#endif // ]TODO(macOS GH#774)
3842
_label.textColor = [RCTUIColor whiteColor]; // TODO(macOS GH#774)
3943
_label.allowsDefaultTighteningForTruncation = YES;
44+
#if !TARGET_OS_OSX // [TODO(macOS GH#774)
4045
_label.adjustsFontSizeToFitWidth = YES;
46+
#endif // ]TODO(macOS GH#774)
4147

48+
#if !TARGET_OS_OSX // [TODO(macOS GH#774)
4249
self.contentView = _label;
50+
#else
51+
[self.contentView addSubview:_label];
52+
#endif // ]TODO(macOS GH#774)
4353
}
4454

4555
return self;

0 commit comments

Comments
 (0)