Skip to content

Commit 5d2ee78

Browse files
SaadnajmiCopilot
andcommitted
feat(macos): port RedBox 2.0 to AppKit on RCTUIKit primitives
Import the final RedBox 2.0 controller and ANSI parser bytes from PR #3054 tree be27899. The parser adaptation originates in c616 and the final consumer layer is represented by adapted commits b1c27df and 7976bf1. The controller uses the shared RCTUIKit table, label, and button primitives. RCTRedBox.mm remains exclusively reconciled by the preceding 0.83 restoration and V1 AppKit commits. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent c8d2532 commit 5d2ee78

4 files changed

Lines changed: 230 additions & 131 deletions

File tree

‎packages/react-native/React/CoreModules/RCTRedBox2AnsiParser+Internal.h‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
* LICENSE file in the root directory of this source tree.
66
*/
77

8-
#import <UIKit/UIKit.h>
8+
#import <React/RCTUIKit.h> // [macOS]
99

1010
/**
1111
* Parses ANSI escape sequences in text and produces an NSAttributedString
@@ -15,8 +15,14 @@
1515
*/
1616
@interface RCTRedBox2AnsiParser : NSObject
1717

18+
#if !TARGET_OS_OSX // [macOS]
1819
+ (NSAttributedString *)attributedStringFromAnsiText:(NSString *)text
1920
baseFont:(UIFont *)font
2021
baseColor:(UIColor *)color;
22+
#else // [macOS
23+
+ (NSAttributedString *)attributedStringFromAnsiText:(NSString *)text
24+
baseFont:(UIFont *)font
25+
baseColor:(RCTPlatformColor *)color;
26+
#endif // macOS]
2127

2228
@end

‎packages/react-native/React/CoreModules/RCTRedBox2AnsiParser.mm‎

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,21 +15,34 @@
1515
using facebook::react::unstable_redbox::AnsiColor;
1616
using facebook::react::unstable_redbox::parseAnsi;
1717

18+
#if !TARGET_OS_OSX // [macOS]
1819
static UIColor *RCTUIColorFromAnsiColor(const AnsiColor &c)
1920
{
2021
return [UIColor colorWithRed:c.r / 255.0 green:c.g / 255.0 blue:c.b / 255.0 alpha:1.0];
2122
}
23+
#else // [macOS
24+
static RCTPlatformColor *RCTUIColorFromAnsiColor(const AnsiColor &c)
25+
{
26+
return [RCTPlatformColor colorWithRed:c.r / 255.0 green:c.g / 255.0 blue:c.b / 255.0 alpha:1.0];
27+
}
28+
#endif // macOS]
2229

2330
@implementation RCTRedBox2AnsiParser
2431

32+
#if !TARGET_OS_OSX // [macOS]
2533
+ (NSAttributedString *)attributedStringFromAnsiText:(NSString *)text baseFont:(UIFont *)font baseColor:(UIColor *)color
34+
#else // [macOS
35+
+ (NSAttributedString *)attributedStringFromAnsiText:(NSString *)text
36+
baseFont:(UIFont *)font
37+
baseColor:(RCTPlatformColor *)color
38+
#endif // macOS]
2639
{
2740
if (text == nil) {
2841
return [[NSAttributedString alloc] init];
2942
}
3043

3144
auto spans = parseAnsi(text.UTF8String);
32-
NSMutableAttributedString *result =[NSMutableAttributedString new];
45+
NSMutableAttributedString *result = [NSMutableAttributedString new];
3346
NSDictionary *baseAttributes = @{NSFontAttributeName : font, NSForegroundColorAttributeName : color};
3447

3548
for (const auto &span : spans) {

‎packages/react-native/React/CoreModules/RCTRedBox2Controller+Internal.h‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,16 @@
66
*/
77

88
#import <React/RCTDefines.h>
9+
#import <React/RCTUIKit.h> // [macOS]
910

1011
#import "RCTRedBox+Internal.h"
1112

1213
#if RCT_DEV_MENU
1314

1415
typedef void (^RCTRedBox2ButtonPressHandler)(void);
1516

16-
@interface RCTRedBox2Controller : UIViewController <RCTRedBox2Controlling, UITableViewDelegate, UITableViewDataSource>
17+
@interface RCTRedBox2Controller
18+
: RCTPlatformViewController <RCTRedBox2Controlling, RCTUITableViewDelegate, RCTUITableViewDataSource> // [macOS]
1719

1820
@property (nonatomic, weak) id<RCTRedBoxControllerActionDelegate> actionDelegate;
1921

0 commit comments

Comments
 (0)